Mercurial > hgsubversion
comparison hgsubversion/svnmeta.py @ 517:ef288fb7f2fe
svnmeta: is_path_tag() is really get_path_tag()
Enforce that returned tags are non-empty.
| author | Patrick Mezard <pmezard@gmail.com> |
|---|---|
| date | Sat, 16 Jan 2010 17:25:09 +0100 |
| parents | 1fd3cfa47c5e |
| children | 247110c633f7 |
comparison
equal
deleted
inserted
replaced
| 516:f089f46729ee | 517:ef288fb7f2fe |
|---|---|
| 227 path = path[len(self.subdir):] | 227 path = path[len(self.subdir):] |
| 228 if path and path[0] == '/': | 228 if path and path[0] == '/': |
| 229 path = path[1:] | 229 path = path[1:] |
| 230 return path | 230 return path |
| 231 | 231 |
| 232 def is_path_tag(self, path): | 232 def get_path_tag(self, path): |
| 233 """If path could represent the path to a tag, returns the potential tag | 233 """If path could represent the path to a tag, returns the |
| 234 name. Otherwise, returns False. | 234 potential (non-empty) tag name. Otherwise, returns None |
| 235 | 235 |
| 236 Note that it's only a tag if it was copied from the path '' in a branch | 236 Note that it's only a tag if it was copied from the path '' in a branch |
| 237 (or tag) we have, for our purposes. | 237 (or tag) we have, for our purposes. |
| 238 """ | 238 """ |
| 239 if self.layout == 'single': | 239 if self.layout != 'single': |
| 240 return False | 240 path = self.normalize(path) |
| 241 path = self.normalize(path) | 241 for tagspath in self.tag_locations: |
| 242 for tagspath in self.tag_locations: | 242 if path.startswith(tagspath + '/'): |
| 243 onpath = path.startswith(tagspath) | 243 tag = path[len(tagspath) + 1:] |
| 244 longer = len(path) > len('%s/' % tagspath) | 244 if tag: |
| 245 if path and onpath and longer: | 245 return tag |
| 246 tag, subpath = path[len(tagspath) + 1:], '' | 246 return None |
| 247 return tag | |
| 248 return False | |
| 249 | 247 |
| 250 def split_branch_path(self, path, existing=True): | 248 def split_branch_path(self, path, existing=True): |
| 251 """Figure out which branch inside our repo this path represents, and | 249 """Figure out which branch inside our repo this path represents, and |
| 252 also figure out which path inside that branch it is. | 250 also figure out which path inside that branch it is. |
| 253 | 251 |
| 258 known. Server-side branch path should be relative to our subdirectory. | 256 known. Server-side branch path should be relative to our subdirectory. |
| 259 """ | 257 """ |
| 260 path = self.normalize(path) | 258 path = self.normalize(path) |
| 261 if self.layout == 'single': | 259 if self.layout == 'single': |
| 262 return (path, None, '') | 260 return (path, None, '') |
| 263 if self.is_path_tag(path): | 261 tag = self.get_path_tag(path) |
| 264 tag = self.is_path_tag(path) | 262 if tag: |
| 265 matched = [t for t in self.tags.iterkeys() if tag.startswith(t+'/')] | 263 matched = [t for t in self.tags.iterkeys() if tag.startswith(t+'/')] |
| 266 if not matched: | 264 if not matched: |
| 267 return None, None, None | 265 return None, None, None |
| 268 matched.sort(cmp=lambda x,y: cmp(len(x),len(y)), reverse=True) | 266 matched.sort(cmp=lambda x,y: cmp(len(x),len(y)), reverse=True) |
| 269 brpath = tag[len(matched[0])+1:] | 267 brpath = tag[len(matched[0])+1:] |
| 297 return path, ln, test | 295 return path, ln, test |
| 298 | 296 |
| 299 def _determine_parent_branch(self, p, src_path, src_rev, revnum): | 297 def _determine_parent_branch(self, p, src_path, src_rev, revnum): |
| 300 if src_path is not None: | 298 if src_path is not None: |
| 301 src_file, src_branch = self.split_branch_path(src_path)[:2] | 299 src_file, src_branch = self.split_branch_path(src_path)[:2] |
| 302 src_tag = self.is_path_tag(src_path) | 300 src_tag = self.get_path_tag(src_path) |
| 303 if src_tag != False or src_file == '': # case 2 | 301 if src_tag or src_file == '': |
| 304 ln = self.localname(p) | 302 ln = self.localname(p) |
| 305 if src_tag != False and src_tag in self.tags: | 303 if src_tag and src_tag in self.tags: |
| 306 ci = self.repo[self.tags[src_tag]].extra()['convert_revision'] | 304 ci = self.repo[self.tags[src_tag]].extra()['convert_revision'] |
| 307 src_rev, src_branch, = self.parse_converted_revision(ci) | 305 src_rev, src_branch, = self.parse_converted_revision(ci) |
| 308 return {ln: (src_branch, src_rev, revnum)} | 306 return {ln: (src_branch, src_rev, revnum)} |
| 309 return {} | 307 return {} |
| 310 | 308 |
| 348 return None, None | 346 return None, None |
| 349 | 347 |
| 350 def get_parent_revision(self, number, branch): | 348 def get_parent_revision(self, number, branch): |
| 351 '''Get the parent revision hash for a commit on a specific branch. | 349 '''Get the parent revision hash for a commit on a specific branch. |
| 352 ''' | 350 ''' |
| 353 tag = self.is_path_tag(self.remotename(branch)) | 351 tag = self.get_path_tag(self.remotename(branch)) |
| 354 limitedtags = maps.TagMap(self.repo, endrev=number-1) | 352 limitedtags = maps.TagMap(self.repo, endrev=number-1) |
| 355 if tag and tag in limitedtags: | 353 if tag and tag in limitedtags: |
| 356 ha = limitedtags[tag] | 354 ha = limitedtags[tag] |
| 357 return ha | 355 return ha |
| 358 r, br = self.get_parent_svn_branch_and_rev(number, branch) | 356 r, br = self.get_parent_svn_branch_and_rev(number, branch) |
| 382 added_branches = {} | 380 added_branches = {} |
| 383 added_tags = {} | 381 added_tags = {} |
| 384 self.closebranches = set() | 382 self.closebranches = set() |
| 385 tags_to_delete = set() | 383 tags_to_delete = set() |
| 386 for p in sorted(paths): | 384 for p in sorted(paths): |
| 387 t_name = self.is_path_tag(p) | 385 t_name = self.get_path_tag(p) |
| 388 if t_name != False: | 386 if t_name: |
| 389 src_p, src_rev = paths[p].copyfrom_path, paths[p].copyfrom_rev | 387 src_p, src_rev = paths[p].copyfrom_path, paths[p].copyfrom_rev |
| 390 # if you commit to a tag, I'm calling you stupid and ignoring | 388 # if you commit to a tag, I'm calling you stupid and ignoring |
| 391 # you. | 389 # you. |
| 392 if src_p is not None and src_rev is not None: | 390 if src_p is not None and src_rev is not None: |
| 393 file, branch = self.split_branch_path(src_p)[:2] | 391 file, branch = self.split_branch_path(src_p)[:2] |
| 394 if file is None: | 392 if file is None: |
| 395 # some crazy people make tags from other tags | 393 # some crazy people make tags from other tags |
| 396 from_tag = self.is_path_tag(src_p) | 394 from_tag = self.get_path_tag(src_p) |
| 397 if not from_tag: | 395 if not from_tag: |
| 398 continue | 396 continue |
| 399 if from_tag in self.tags: | 397 if from_tag in self.tags: |
| 400 ci = self.repo[self.tags[from_tag]].extra()['convert_revision'] | 398 ci = self.repo[self.tags[from_tag]].extra()['convert_revision'] |
| 401 src_rev, branch, = self.parse_converted_revision(ci) | 399 src_rev, branch, = self.parse_converted_revision(ci) |
| 525 branches.setdefault(b, []).append(('add', tag, r)) | 523 branches.setdefault(b, []).append(('add', tag, r)) |
| 526 for tag, branch in delta[1].iteritems(): | 524 for tag, branch in delta[1].iteritems(): |
| 527 branches.setdefault(branch, []).append(('rm', tag, None)) | 525 branches.setdefault(branch, []).append(('rm', tag, None)) |
| 528 | 526 |
| 529 for b, tags in branches.iteritems(): | 527 for b, tags in branches.iteritems(): |
| 530 fromtag = self.is_path_tag(self.remotename(b)) | 528 fromtag = self.get_path_tag(self.remotename(b)) |
| 531 # modify parent's .hgtags source | 529 # modify parent's .hgtags source |
| 532 parent = self.repo[self.get_parent_revision(rev.revnum, b)] | 530 parent = self.repo[self.get_parent_revision(rev.revnum, b)] |
| 533 if '.hgtags' not in parent: | 531 if '.hgtags' not in parent: |
| 534 src = '' | 532 src = '' |
| 535 else: | 533 else: |
