Mercurial > hgsubversion
diff hgsubversion/layouts/standard.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 | 80a456b77ade |
line wrap: on
line diff
--- a/hgsubversion/layouts/standard.py +++ b/hgsubversion/layouts/standard.py @@ -64,3 +64,36 @@ class StandardLayout(base.BaseLayout): if tag: return tag return None + + def split_remote_name(self, path, known_branches): + + # this odd evolution is how we deal with people doing things like + # creating brances (note the typo), committing to a branch under it, + # and then moving it to branches + + # we need to find the ../foo branch names, if they exist, before + # trying to create a normally-named branch + + components = path.split('/') + candidate = '' + while self.localname(candidate) not in known_branches and components: + if not candidate: + candidate = components.pop(0) + else: + candidate += '/' + candidate += components.pop(0) + if self.localname(candidate) in known_branches: + return candidate, '/'.join(components) + + if path == 'trunk' or path.startswith('trunk/'): + branch_path = 'trunk' + local_path = '/'.join(path.split('/')[1:]) + elif path.startswith('branches/'): + components = path.split('/') + branch_path = '/'.join(components[:2]) + local_path = '/'.join(components[2:]) + else: + components = path.split('/') + branch_path = '/'.join(components[:-1]) + local_path = components[-1] + return branch_path, local_path