# HG changeset patch # User David Schleimer # Date 1366233047 25200 # Node ID b2d89ba6b871f8b4a89a791098937d89c5c6b1af # Parent 6945d335945667e7969902d783ccf189575e0349 layouts: pull out code for detecting layout from subversion This is the start of an effort to refactor the code for how we handle subversion layoout to mercurial layout mapping. Specifically, it pulls out the logic for guessing what layout to use based on the contents of subversion. It also sets up a bit of the structure for the new library. diff --git a/hgsubversion/layouts/__init__.py b/hgsubversion/layouts/__init__.py new file mode 100644 --- /dev/null +++ b/hgsubversion/layouts/__init__.py @@ -0,0 +1,16 @@ +"""Code for dealing with subversion layouts + +This package is intended to encapsulate everything about subversion +layouts. This includes detecting the layout based on looking at +subversion, mapping subversion paths to hg branches, and doing any +other path translation necessary. + +NB: this has a long way to go before it does everything it claims to + +""" + +import detect + +__all__ = [ + "detect", + ] diff --git a/hgsubversion/layouts/detect.py b/hgsubversion/layouts/detect.py new file mode 100644 --- /dev/null +++ b/hgsubversion/layouts/detect.py @@ -0,0 +1,36 @@ +""" Layout detection for subversion repos. + +Figure out what layout we should be using, based on config, command +line flags, subversion contents, and anything else we decide to base +it on. + +""" + +from mercurial import util as hgutil + +import hgsubversion.svnwrap + +def layout_from_subversion(svn, revision=None, ui=None): + """ Guess what layout to use based on directories under the svn root. + + This is intended for use during bootstrapping. It guesses which + layout to use based on the presence or absence of the conventional + trunk, branches, tags dirs immediately under the path your are + cloning. + + Additionally, this will write the layout in use to the ui object + passed, if any. + + """ + + try: + rootlist = svn.list_dir('', revision=revision) + except svnwrap.SubversionException, e: + err = "%s (subversion error: %d)" % (e.args[0], e.args[1]) + raise hgutil.Abort(err) + if sum(map(lambda x: x in rootlist, ('branches', 'tags', 'trunk'))): + layout = 'standard' + else: + layout = 'single' + ui.setconfig('hgsubversion', 'layout', layout) + return layout diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -14,6 +14,7 @@ from mercurial import i18n from mercurial import extensions from mercurial import repair +import layouts import os import replay import pushmod @@ -356,16 +357,9 @@ def pull(repo, source, heads=[], force=F if not layout in ('auto', 'single', 'standard'): raise hgutil.Abort("unknown layout '%s'" % layout) if layout == 'auto': - try: - rootlist = svn.list_dir('', revision=(stopat_rev or None)) - except svnwrap.SubversionException, e: - err = "%s (subversion error: %d)" % (e.args[0], e.args[1]) - raise hgutil.Abort(err) - if sum(map(lambda x: x in rootlist, ('branches', 'tags', 'trunk'))): - layout = 'standard' - else: - layout = 'single' - repo.ui.setconfig('hgsubversion', 'layout', layout) + layout = layouts.detect.layout_from_subversion(svn, + (stopat_rev or None), + repo.ui) repo.ui.note('using %s layout\n' % layout) branch = repo.ui.config('hgsubversion', 'branch')