changeset 1005:5bba4d1becde

layouts: refactor layout loading based on config into function Refactor the logic for loading the layout based on config, and for validating that config is sane into a single function.
author David Schleimer <dschleimer@fb.com>
date Wed, 17 Apr 2013 15:00:33 -0700
parents b2d89ba6b871
children 7a3b938825cd
files hgsubversion/layouts/detect.py hgsubversion/svnmeta.py hgsubversion/wrappers.py
diffstat 3 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/layouts/detect.py
+++ b/hgsubversion/layouts/detect.py
@@ -34,3 +34,19 @@ def layout_from_subversion(svn, revision
         layout = 'single'
     ui.setconfig('hgsubversion', 'layout', layout)
     return layout
+
+def layout_from_config(ui, allow_auto=False):
+    """ Load the layout we are using based on config
+
+    We will read the config from the ui object.  Pass allow_auto=True
+    if you are doing bootstrapping and can detect the layout in
+    another manner if you get auto.  Otherwise, we will abort if we
+    detect the layout as auto.
+    """
+
+    layout = ui.config('hgsubversion', 'layout', default='auto')
+    if layout == 'auto' and not allow_auto:
+        raise hgutil.Abort('layout not yet determined')
+    elif layout not in ('auto', 'single', 'standard'):
+        raise hgutil.Abort("unknown layout '%s'" % layout)
+    return layout
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -10,6 +10,7 @@ from mercurial import node
 
 import util
 import maps
+import layouts
 import editor
 
 
@@ -107,12 +108,7 @@ class SVNMeta(object):
         # resolved into something other than auto before this ever
         # gets called
         if not self._layout or self._layout == 'auto':
-            lo = self.repo.ui.config('hgsubversion', 'layout', default='auto')
-            if lo == 'auto':
-                raise hgutil.Abort('layout not yet determined')
-            elif not lo in ('single', 'standard'):
-                raise hgutil.Abort("unknown layout '%s'" % lo)
-            self._layout = lo
+            self._layout = layouts.detect.layout_from_config(self.repo.ui)
             f = open(self.layoutfile, 'w')
             f.write(self._layout)
             f.close()
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -353,9 +353,7 @@ def pull(repo, source, heads=[], force=F
 
         stopat_rev = util.parse_revnum(svn, checkout)
 
-        layout = repo.ui.config('hgsubversion', 'layout', 'auto')
-        if not layout in ('auto', 'single', 'standard'):
-            raise hgutil.Abort("unknown layout '%s'" % layout)
+        layout = layouts.detect.layout_from_config(repo.ui, allow_auto=True)
         if layout == 'auto':
             layout = layouts.detect.layout_from_subversion(svn,
                                                            (stopat_rev or None),