[PATCH 1 of 6] layouts: refactor out svn path to mercurial branch logic
# HG changeset patch
# User David Schleimer <dschleimer@...>
# Date 1366841231 25200
# Wed Apr 24 15:07:11 2013 -0700
# Node ID 8552fbda8e3b552a901fe22425597ff199a77b4f
# Parent bdc9b21ea8d079ace9832f9e7240a670a2eba52d
layouts: refactor out svn path to mercurial branch logic
This pulls the logic for mapping from svn path to mercurial branch
name out of svnmeta.py and into the new layouts library. It also sets
up the structure for that library. This diff does not modify any call
to svnmeta.localname, rather leaving it in place as a simple proxy to
the new layout object.
diff --git a/hgsubversion/layouts/__init__.py b/hgsubversion/layouts/__init__.py
--- a/hgsubversion/layouts/__init__.py
+++ b/hgsubversion/layouts/__init__.py
<at> <at> -9,10 +9,36 <at> <at>
"""
+from mercurial import util as hgutil
+
import detect
import persist
+import single
+import standard
__all__ = [
"detect",
+ "layout_from_name",
"persist",
]
+
+# This is the authoritative store of what layouts are available.
+# The intention is for extension authors who wish to build their own
+# layout to add it to this dict.
+NAME_TO_CLASS = {
+ "single": single.SingleLayout,
+ "standard": standard.StandardLayout,
+}
+
+
+def layout_from_name(name):
+ """Returns a layout module given the layout name
+
+ You should use one of the layout.detect.* functions to get the
+ name to pass to this function.
+
+ """
+
+ if name not in NAME_TO_CLASS:
+ raise hgutil.Abort('Unknown hgsubversion layout: %s' %name)
+ return NAME_TO_CLASS[name]()
diff --git a/hgsubversion/layouts/base.py b/hgsubversion/layouts/base.py
new file mode 100644
--- /dev/null
+++ b/hgsubversion/layouts/base.py
<at> <at> -0,0 +1,20 <at> <at>
+"""Module to hold the base API for layout classes.
+
+This module should not contain any implementation, just a definition
+of the API concrete layouts are expected to implement.
+
+"""
+
+from mercurial import util as hgutil
+
+class BaseLayout(object):
+
+ def __unimplemented(self, method_name):
+ raise hgutil.Abort(
+ "Incomplete layout implementation: %s.%s doesn't implement %s" %
+ (self.__module__, self.__name__, method_name))
+
+ def localname(self, path):
+ """Compute the local name for a branch located at path.
+ """
+ self.__unimplemented('localname')
diff --git a/hgsubversion/layouts/single.py b/hgsubversion/layouts/single.py
new file mode 100644
--- /dev/null
+++ b/hgsubversion/layouts/single.py
<at> <at> -0,0 +1,9 <at> <at>
+
+
+import base
+
+class SingleLayout(base.BaseLayout):
+ """A layout with only the default branch"""
+
+ def localname(self, path):
+ return 'default'
diff --git a/hgsubversion/layouts/standard.py b/hgsubversion/layouts/standard.py
new file mode 100644
--- /dev/null
+++ b/hgsubversion/layouts/standard.py
<at> <at> -0,0 +1,14 <at> <at>
+
+
+import base
+
+
+class StandardLayout(base.BaseLayout):
+ """The standard trunk, branches, tags layout"""
+
+ def localname(self, path):
+ if path == 'trunk':
+ return None
+ elif path.startswith('branches/'):
+ return path[len('branches/'):]
+ return '../%s' % path
diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
<at> <at> -72,6 +72,7 <at> <at>
self.tag_locations = tag_locations
self._layout = layouts.detect.layout_from_file(self.meta_data_dir,
ui=self.repo.ui)
+ self._layoutobj = None
pickle_atomic(self.tag_locations, self.tag_locations_file)
# ensure nested paths are handled properly
self.tag_locations.sort()
<at> <at> -108,6 +109,12 <at> <at>
return self._layout
<at> property
+ def layoutobj(self):
+ if not self._layoutobj:
+ self._layoutobj = layouts.layout_from_name(self.layout)
+ return self._layoutobj
+
+ <at> property
def editor(self):
if not hasattr(self, '_editor'):
self._editor = editor.HgEditor(self)
<at> <at> -215,13 +222,7 <at> <at>
def localname(self, path):
"""Compute the local name for a branch located at path.
"""
- if self.layout == 'single':
- return 'default'
- if path == 'trunk':
- return None
- elif path.startswith('branches/'):
- return path[len('branches/'):]
- return '../%s' % path
+ return self.layoutobj.localname(path)
def remotename(self, branch):
if self.layout == 'single':
--
--
You received this message because you are subscribed to the Google Groups "hgsubversion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hgsubversion+unsubscribe@...
To post to this group, send email to hgsubversion@...
Visit this group at http://groups.google.com/group/hgsubversion?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.