# HG changeset patch # User Sean Farley # Date 1395678049 18000 # Node ID 4744b7bfa4768f6302dd3c961df6de0631f43bfb # Parent eded1e736a7eab0166c5756a299e476d0d04c519 layouts: change constructor to take a meta object This change is another step forward to centralize subversion configuration options and help refactor. I couldn't find an easier way to split up this change since there are many interdependent function calls. There is no functionality change in this patch, only renaming ui -> meta. diff --git a/hgsubversion/layouts/__init__.py b/hgsubversion/layouts/__init__.py --- a/hgsubversion/layouts/__init__.py +++ b/hgsubversion/layouts/__init__.py @@ -31,7 +31,7 @@ NAME_TO_CLASS = { } -def layout_from_name(name, ui): +def layout_from_name(name, meta): """Returns a layout module given the layout name You should use one of the layout.detect.* functions to get the @@ -40,5 +40,5 @@ def layout_from_name(name, ui): """ if name not in NAME_TO_CLASS: - raise hgutil.Abort('Unknown hgsubversion layout: %s' %name) - return NAME_TO_CLASS[name](ui) + raise hgutil.Abort('Unknown hgsubversion layout: %s' % name) + return NAME_TO_CLASS[name](meta) diff --git a/hgsubversion/layouts/base.py b/hgsubversion/layouts/base.py --- a/hgsubversion/layouts/base.py +++ b/hgsubversion/layouts/base.py @@ -9,8 +9,8 @@ from mercurial import util as hgutil class BaseLayout(object): - def __init__(self, ui): - self.ui = ui + def __init__(self, meta): + self.meta = meta def __unimplemented(self, method_name): raise NotImplementedError( diff --git a/hgsubversion/layouts/custom.py b/hgsubversion/layouts/custom.py --- a/hgsubversion/layouts/custom.py +++ b/hgsubversion/layouts/custom.py @@ -12,13 +12,13 @@ import base class CustomLayout(base.BaseLayout): - def __init__(self, ui): - base.BaseLayout.__init__(self, ui) + def __init__(self, meta): + base.BaseLayout.__init__(self, meta) self.svn_to_hg = {} self.hg_to_svn = {} - for hg_branch, svn_path in ui.configitems('hgsubversionbranch'): + for hg_branch, svn_path in meta.ui.configitems('hgsubversionbranch'): hg_branch = hg_branch.strip() if hg_branch == 'default' or not hg_branch: diff --git a/hgsubversion/layouts/detect.py b/hgsubversion/layouts/detect.py --- a/hgsubversion/layouts/detect.py +++ b/hgsubversion/layouts/detect.py @@ -12,7 +12,7 @@ from mercurial import util as hgutil import __init__ as layouts -def layout_from_subversion(svn, revision=None, ui=None): +def layout_from_subversion(svn, revision=None, meta=None): """ Guess what layout to use based on directories under the svn root. This is intended for use during bootstrapping. It guesses which @@ -39,10 +39,10 @@ def layout_from_subversion(svn, revision layout = 'standard' else: layout = 'single' - ui.setconfig('hgsubversion', 'layout', layout) + meta.ui.setconfig('hgsubversion', 'layout', layout) return layout -def layout_from_config(ui, allow_auto=False): +def layout_from_config(meta, 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 @@ -51,19 +51,15 @@ def layout_from_config(ui, allow_auto=Fa detect the layout as auto. """ - layout = ui.config('hgsubversion', 'layout', default='auto') + layout = meta.ui.config('hgsubversion', 'layout', default='auto') if layout == 'auto' and not allow_auto: raise hgutil.Abort('layout not yet determined') elif layout not in layouts.NAME_TO_CLASS and layout != 'auto': raise hgutil.Abort("unknown layout '%s'" % layout) return layout -def layout_from_file(metapath, ui=None): +def layout_from_file(meta): """ Load the layout in use from the metadata file. - - If you pass the ui arg, we will also write the layout to the - config for that ui. - """ # import late to avoid trouble when running the test suite @@ -72,13 +68,12 @@ def layout_from_file(metapath, ui=None): except ImportError: from hgsubversion import util - layoutfile = os.path.join(metapath, 'layout') - layout = util.load(layoutfile) - if layout is not None and ui: - ui.setconfig('hgsubversion', 'layout', layout) + layout = util.load(meta.layout_file) + if layout: + meta.ui.setconfig('hgsubversion', 'layout', layout) return layout -def layout_from_commit(subdir, revpath, branch, ui): +def layout_from_commit(subdir, revpath, branch, meta): """ Guess what the layout is based existing commit info Specifically, this compares the subdir for the repository and the @@ -95,7 +90,7 @@ def layout_from_commit(subdir, revpath, candidates = set() for layout in layouts.NAME_TO_CLASS: - layoutobj = layouts.layout_from_name(layout, ui) + layoutobj = layouts.layout_from_name(layout, meta) try: remotepath = layoutobj.remotepath(branch, subdir) except KeyError: @@ -106,7 +101,7 @@ def layout_from_commit(subdir, revpath, if len(candidates) == 1: return candidates.pop() elif candidates: - config_layout = layout_from_config(ui, allow_auto=True) + config_layout = layout_from_config(meta, allow_auto=True) if config_layout in candidates: return config_layout diff --git a/hgsubversion/layouts/standard.py b/hgsubversion/layouts/standard.py --- a/hgsubversion/layouts/standard.py +++ b/hgsubversion/layouts/standard.py @@ -5,18 +5,18 @@ import base class StandardLayout(base.BaseLayout): """The standard trunk, branches, tags layout""" - def __init__(self, ui): - base.BaseLayout.__init__(self, ui) + def __init__(self, meta): + base.BaseLayout.__init__(self, meta) self._tag_locations = None - self._branch_dir = ui.config('hgsubversion', 'branchdir', 'branches') + self._branch_dir = self.meta.ui.config('hgsubversion', 'branchdir', 'branches') if self._branch_dir[0] == '/': self._branch_dir = self._branch_dir[1:] if self._branch_dir[-1] != '/': self._branch_dir += '/' - self._infix = ui.config('hgsubversion', 'infix', '').strip('/') + self._infix = self.meta.ui.config('hgsubversion', 'infix', '').strip('/') if self._infix: self._infix = '/' + self._infix @@ -69,9 +69,9 @@ class StandardLayout(base.BaseLayout): self._tag_locations = util.load(tag_locations_file) if not self._tag_locations: - self._tag_locations = self.ui.configlist('hgsubversion', - 'tagpaths', - ['tags']) + self._tag_locations = self.meta.ui.configlist('hgsubversion', + 'tagpaths', + ['tags']) util.dump(self._tag_locations, tag_locations_file) # ensure nested paths are handled properly diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -189,11 +189,11 @@ def _buildmeta(ui, repo, args, partial=F if layout is None: layout = layouts.detect.layout_from_commit(subdir, revpath, - ctx.branch(), ui) - existing_layout = layouts.detect.layout_from_file(meta.metapath) + ctx.branch(), meta) + existing_layout = layouts.detect.layout_from_file(meta) if layout != existing_layout: util.dump(layout, meta.layout_file) - layoutobj = layouts.layout_from_name(layout, ui) + layoutobj = layouts.layout_from_name(layout, meta) elif layout == 'single': assert (subdir or '/') == revpath, ('Possible layout detection' ' defect in replay') diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -59,8 +59,7 @@ class SVNMeta(object): # misc self.branches = util.load(self.branch_info_file) or {} self.prevbranches = dict(self.branches) - self._layout = layouts.detect.layout_from_file(self.metapath, - ui=self.repo.ui) + self._layout = layouts.detect.layout_from_file(self) def _get_cachedconfig(self, name, filename, configname, default): """Return a cached value for a config option. If the cache is uninitialized @@ -147,14 +146,14 @@ class SVNMeta(object): # resolved into something other than auto before this ever # gets called if not self._layout or self._layout == 'auto': - self._layout = layouts.detect.layout_from_config(self.repo.ui) + self._layout = layouts.detect.layout_from_config(self) util.dump(self._layout, self.layout_file) return self._layout @property def layoutobj(self): if not self._layoutobj: - self._layoutobj = layouts.layout_from_name(self.layout, self.ui) + self._layoutobj = layouts.layout_from_name(self.layout, self) return self._layoutobj @property diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -398,11 +398,11 @@ def pull(repo, source, heads=[], force=F stopat_rev = util.parse_revnum(svn, checkout) - layout = layouts.detect.layout_from_config(repo.ui, allow_auto=True) + layout = layouts.detect.layout_from_config(meta, allow_auto=True) if layout == 'auto': layout = layouts.detect.layout_from_subversion(svn, (stopat_rev or None), - repo.ui) + meta) repo.ui.note('using %s layout\n' % layout) branch = repo.ui.config('hgsubversion', 'branch')