comparison hg_delta_editor.py @ 116:30580c05dccc

hg_delta_editor: merge _is_path_valid() and _path_and_branch_from_path()
author Patrick Mezard <pmezard@gmail.com>
date Sat, 29 Nov 2008 11:24:31 -0600
parents 5497d1264b4d
children ea65fe2b0856
comparison
equal deleted inserted replaced
115:ed42f6e5705a 116:30580c05dccc
145 '''Given a list of paths, return mapping of all branches touched 145 '''Given a list of paths, return mapping of all branches touched
146 to their branch path. 146 to their branch path.
147 ''' 147 '''
148 branches = {} 148 branches = {}
149 for p in paths: 149 for p in paths:
150 if self._is_path_valid(p): 150 relpath, branch, branchpath = self._split_branch_path(p)
151 junk, branch, branchpath = self._split_branch_path(p) 151 if relpath is not None:
152 branches[branch] = branchpath 152 branches[branch] = branchpath
153 return branches 153 return branches
154 154
155 def _path_and_branch_for_path(self, path): 155 def _path_and_branch_for_path(self, path):
156 return self._split_branch_path(path)[:2] 156 return self._split_branch_path(path)[:2]
168 p = p[1:] 168 p = p[1:]
169 return p, None, 'trunk' 169 return p, None, 'trunk'
170 elif path.startswith('branches/'): 170 elif path.startswith('branches/'):
171 p = path[len('branches/'):] 171 p = path[len('branches/'):]
172 br = p.split('/')[0] 172 br = p.split('/')[0]
173 p = p[len(br)+1:] 173 if br:
174 if p and p[0] == '/': 174 p = p[len(br)+1:]
175 p = p[1:] 175 if p and p[0] == '/':
176 return p, br, 'branches/' + br 176 p = p[1:]
177 return p, br, 'branches/' + br
177 return None, None, None 178 return None, None, None
178 raise Exception,'Things went boom: ' + path
179 179
180 def set_current_rev(self, rev): 180 def set_current_rev(self, rev):
181 '''Set the revision we're currently converting. 181 '''Set the revision we're currently converting.
182 ''' 182 '''
183 self.current_rev = rev 183 self.current_rev = rev
200 if path and path[0] == '/': 200 if path and path[0] == '/':
201 path = path[1:] 201 path = path[1:]
202 return path 202 return path
203 203
204 def _is_path_valid(self, path): 204 def _is_path_valid(self, path):
205 path = self._normalize_path(path) 205 return self._split_branch_path(path)[0] is not None
206 if path.startswith('trunk'):
207 return True
208 elif path.startswith('branches/'):
209 br = path.split('/')[1]
210 return len(br) > 0
211 return False
212 206
213 def _is_path_tag(self, path): 207 def _is_path_tag(self, path):
214 """If path represents the path to a tag, returns the tag name. 208 """If path represents the path to a tag, returns the tag name.
215 209
216 Otherwise, returns False. 210 Otherwise, returns False.
260 added_branches = {} 254 added_branches = {}
261 added_tags = {} 255 added_tags = {}
262 tags_to_delete = set() 256 tags_to_delete = set()
263 branches_to_delete = set() 257 branches_to_delete = set()
264 for p in paths: 258 for p in paths:
265 if self._is_path_valid(p): 259 fi, br = self._path_and_branch_for_path(p)
266 fi, br = self._path_and_branch_for_path(p) 260 if fi is not None:
267 if fi == '' and br not in self.branches: 261 if fi == '' and br not in self.branches:
268 src_p = paths[p].copyfrom_path 262 src_p = paths[p].copyfrom_path
269 src_rev = paths[p].copyfrom_rev 263 src_rev = paths[p].copyfrom_rev
270 src_tag = self._is_path_tag(src_p) 264 src_tag = self._is_path_tag(src_p)
271 265
278 src_rev = revision.revnum 272 src_rev = revision.revnum
279 elif src_tag: 273 elif src_tag:
280 # this is a branch created from a tag. Note that this 274 # this is a branch created from a tag. Note that this
281 # really does happen (see Django) 275 # really does happen (see Django)
282 src_branch, src_rev = self.tags[src_tag] 276 src_branch, src_rev = self.tags[src_tag]
283 added_branches[br] = (src_branch, src_rev,
284 revision.revnum)
285 else: 277 else:
286 # Not from a tag, and from a valid repo path 278 # Not from a tag, and from a valid repo path
287 (src_p, 279 (src_p,
288 src_branch) = self._path_and_branch_for_path(src_p) 280 src_branch) = self._path_and_branch_for_path(src_p)
281 if src_p is None:
282 continue
289 added_branches[br] = src_branch, src_rev, revision.revnum 283 added_branches[br] = src_branch, src_rev, revision.revnum
290 elif fi == '' and br in self.branches: 284 elif fi == '' and br in self.branches:
291 br2 = br or 'default' 285 br2 = br or 'default'
292 if br2 not in self.repo.branchtags() and paths[p].action == 'D': 286 if br2 not in self.repo.branchtags() and paths[p].action == 'D':
293 branches_to_delete.add(br) 287 branches_to_delete.add(br)
301 continue 295 continue
302 src_p, src_rev = paths[p].copyfrom_path, paths[p].copyfrom_rev 296 src_p, src_rev = paths[p].copyfrom_path, paths[p].copyfrom_rev
303 # if you commit to a tag, I'm calling you stupid and ignoring 297 # if you commit to a tag, I'm calling you stupid and ignoring
304 # you. 298 # you.
305 if src_p is not None and src_rev is not None: 299 if src_p is not None and src_rev is not None:
306 if self._is_path_valid(src_p): 300 file, branch = self._path_and_branch_for_path(src_p)
307 file, branch = self._path_and_branch_for_path(src_p) 301 if file is None:
308 else:
309 # some crazy people make tags from other tags 302 # some crazy people make tags from other tags
310 file = '' 303 file = ''
311 from_tag = self._is_path_tag(src_p) 304 from_tag = self._is_path_tag(src_p)
312 if not from_tag: 305 if not from_tag:
313 continue 306 continue
466 def url(self): 459 def url(self):
467 return open(self.svn_url_file).read() 460 return open(self.svn_url_file).read()
468 461
469 @stash_exception_on_self 462 @stash_exception_on_self
470 def delete_entry(self, path, revision_bogus, parent_baton, pool=None): 463 def delete_entry(self, path, revision_bogus, parent_baton, pool=None):
471 if self._is_path_valid(path): 464 br_path, branch = self._path_and_branch_for_path(path)
472 br_path, branch = self._path_and_branch_for_path(path) 465 if br_path is not None:
473 ha = self.get_parent_revision(self.current_rev.revnum, branch) 466 ha = self.get_parent_revision(self.current_rev.revnum, branch)
474 if ha == revlog.nullid: 467 if ha == revlog.nullid:
475 return 468 return
476 ctx = self.repo.changectx(ha) 469 ctx = self.repo.changectx(ha)
477 if br_path not in ctx: 470 if br_path not in ctx:
569 self.copies[path] = from_file 562 self.copies[path] = from_file
570 563
571 @stash_exception_on_self 564 @stash_exception_on_self
572 def add_directory(self, path, parent_baton, copyfrom_path, 565 def add_directory(self, path, parent_baton, copyfrom_path,
573 copyfrom_revision, dir_pool=None): 566 copyfrom_revision, dir_pool=None):
574 if self._is_path_valid(path): 567 br_path, branch = self._path_and_branch_for_path(path)
575 junk, branch = self._path_and_branch_for_path(path) 568 if br_path is not None:
576 if not copyfrom_path and not junk: 569 if not copyfrom_path and not br_path:
577 self.commit_branches_empty[branch] = True 570 self.commit_branches_empty[branch] = True
578 else: 571 else:
579 self.commit_branches_empty[branch] = False 572 self.commit_branches_empty[branch] = False
580 if not self._is_path_valid(path) or not copyfrom_path: 573 if br_path is None or not copyfrom_path:
581 return 574 return
582 if copyfrom_path: 575 if copyfrom_path:
583 tag = self._is_path_tag(copyfrom_path) 576 tag = self._is_path_tag(copyfrom_path)
584 if tag not in self.tags: 577 if tag not in self.tags:
585 tag = None 578 tag = None
631 elif name == 'svn:special': 624 elif name == 'svn:special':
632 self.current_files_symlink[self.current_file] = bool(value is not None) 625 self.current_files_symlink[self.current_file] = bool(value is not None)
633 626
634 @stash_exception_on_self 627 @stash_exception_on_self
635 def open_directory(self, path, parent_baton, base_revision, dir_pool=None): 628 def open_directory(self, path, parent_baton, base_revision, dir_pool=None):
636 if self._is_path_valid(path): 629 p_, branch = self._path_and_branch_for_path(path)
637 p_, branch = self._path_and_branch_for_path(path) 630 if p_ == '':
638 if p_ == '': 631 self.commit_branches_empty[branch] = False
639 self.commit_branches_empty[branch] = False
640 632
641 @stash_exception_on_self 633 @stash_exception_on_self
642 def apply_textdelta(self, file_baton, base_checksum, pool=None): 634 def apply_textdelta(self, file_baton, base_checksum, pool=None):
643 base = '' 635 base = ''
644 if not self._is_path_valid(self.current_file): 636 if not self._is_path_valid(self.current_file):