Commits

David Schleimer  committed b2d89ba

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.

  • Participants
  • Parent commits 6945d33

Comments (0)

Files changed (3)

File hgsubversion/layouts/__init__.py

+"""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",
+    ]

File hgsubversion/layouts/detect.py

+""" 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

File hgsubversion/wrappers.py

 from mercurial import extensions
 from mercurial import repair
 
+import layouts
 import os
 import replay
 import pushmod
         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')