1. Bryan O'Sullivan
  2. hgsubversion


David Schleimer  committed 5bba4d1

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.

  • Participants
  • Parent commits b2d89ba
  • Branches default

Comments (0)

Files changed (3)

File hgsubversion/layouts/detect.py

View file
  • Ignore whitespace
         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

File hgsubversion/svnmeta.py

View file
  • Ignore whitespace
 import util
 import maps
+import layouts
 import editor
         # 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')

File hgsubversion/wrappers.py

View file
  • Ignore whitespace
         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),