Mercurial > hgsubversion
changeset 1298:4ba1481484e6
svnmeta: copy layout_from_commit from detect
This isn't used currently but will be in a future patch when we get rid of
layouts/detect.py and banish the import hgext_ business once and for all.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 11:20:54 -0500 |
parents | fc48e1065926 |
children | 8b3b456afd5f |
files | hgsubversion/svnmeta.py |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -144,6 +144,42 @@ class SVNMeta(object): filename)) setattr(SVNMeta, name, prop) + def layout_from_commit(self, subdir, revpath, branch): + """ Guess what the layout is based existing commit info + + Specifically, this compares the subdir for the repository and the + revpath as extracted from the convinfo in the commit. If they + match, the layout is assumed to be single. Otherwise, it tries + the available layouts and selects the first one that would + translate the given branch to the given revpath. + + """ + + subdir = subdir or '/' + if subdir == revpath: + return 'single' + + candidates = set() + for layout in layouts.NAME_TO_CLASS: + layoutobj = layouts.layout_from_name(layout, self) + try: + remotepath = layoutobj.remotepath(branch, subdir) + except KeyError: + continue + if remotepath == revpath: + candidates.add(layout) + + if len(candidates) == 1: + return candidates.pop() + elif candidates: + config_layout = layouts.detect.layout_from_config(self, + allow_auto=True) + if config_layout in candidates: + return config_layout + + return 'standard' + + @property def layout_file(self): return os.path.join(self.metapath, 'layout')