# HG changeset patch # User David Schleimer # Date 1366236033 25200 # Node ID 5bba4d1becded2469e73ea669d99e0d64162b80c # Parent b2d89ba6b871f8b4a89a791098937d89c5c6b1af 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. diff --git a/hgsubversion/layouts/detect.py b/hgsubversion/layouts/detect.py --- 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 diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- 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() diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- 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),