comparison hgsubversion/svnmeta.py @ 1029:513f2b607b06

layouts: pull out logic for splitting svn paths into branch and local parts There is a single method on svnmeta that is responsible for both splitting a subversion path into a local component, which specifies a path relative to the mercurial root, and a branch component, which specifies the path to the root of a subversion branch, and translating that branch path into a mercurial branch name. This pulls the logic for doing the path splitting into a layout object method that *only* splits the path, and changes the svnmeta to call the layout objects's localname method to do the subversion branch path to mercurial branch name translation.
author David Schleimer <dschleimer@fb.com>
date Wed, 05 Jun 2013 11:06:34 -0700
parents 16045f6f3fef
children 6fa55b6fa3f2
comparison
equal deleted inserted replaced
1028:c4b25a903ad3 1029:513f2b607b06
272 some known branch. If existing=False, then it will guess what the 272 some known branch. If existing=False, then it will guess what the
273 branch would be if it were known. Server-side branch path should be 273 branch would be if it were known. Server-side branch path should be
274 relative to our subdirectory. 274 relative to our subdirectory.
275 """ 275 """
276 path = self.normalize(path) 276 path = self.normalize(path)
277 if self.layout == 'single':
278 return (path, None, '')
279 tag = self.get_path_tag(path) 277 tag = self.get_path_tag(path)
280 if tag: 278 if tag:
281 # consider the new tags when dispatching entries 279 # consider the new tags when dispatching entries
282 matched = [] 280 matched = []
283 for tags in (self.tags, self.addedtags): 281 for tags in (self.tags, self.addedtags):
292 else: 290 else:
293 brpath = tag[len(matched[0])+1:] 291 brpath = tag[len(matched[0])+1:]
294 svrpath = path[:-(len(brpath)+1)] 292 svrpath = path[:-(len(brpath)+1)]
295 ln = self.localname(svrpath) 293 ln = self.localname(svrpath)
296 return brpath, ln, svrpath 294 return brpath, ln, svrpath
297 test = '' 295
298 path_comps = path.split('/') 296 branch_path, local_path = self.layoutobj.split_remote_name(path,
299 while self.localname(test) not in self.branches and len(path_comps): 297 self.branches)
300 if not test: 298 branch_name = self.layoutobj.localname(branch_path)
301 test = path_comps.pop(0) 299
302 else: 300 if branch_name in self.branches:
303 test += '/%s' % path_comps.pop(0) 301 return local_path, branch_name, branch_path
304 if self.localname(test) in self.branches: 302 elif existing or (branch_name and branch_name.startswith('../')):
305 return path[len(test)+1:], self.localname(test), test
306 if existing:
307 return None, None, None 303 return None, None, None
308 if path == 'trunk' or path.startswith('trunk/'):
309 path = '/'.join(path.split('/')[1:])
310 test = 'trunk'
311 elif path.startswith('branches/'):
312 elts = path.split('/')
313 test = '/'.join(elts[:2])
314 path = '/'.join(elts[2:])
315 else: 304 else:
316 path = test.split('/')[-1] 305 return local_path, branch_name, branch_path
317 test = '/'.join(test.split('/')[:-1])
318 ln = self.localname(test)
319 if ln and ln.startswith('../'):
320 return None, None, None
321 return path, ln, test
322 306
323 def _determine_parent_branch(self, p, src_path, src_rev, revnum): 307 def _determine_parent_branch(self, p, src_path, src_rev, revnum):
324 if src_path is not None: 308 if src_path is not None:
325 src_file, src_branch = self.split_branch_path(src_path)[:2] 309 src_file, src_branch = self.split_branch_path(src_path)[:2]
326 src_tag = self.get_path_tag(src_path) 310 src_tag = self.get_path_tag(src_path)