diff hgsubversion/layouts/__init__.py @ 1012:e8cd211684c4

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.
author David Schleimer <dschleimer@fb.com>
date Wed, 24 Apr 2013 15:07:11 -0700
parents 7a3b938825cd
children 8feff33e387d
line wrap: on
line diff
--- a/hgsubversion/layouts/__init__.py
+++ b/hgsubversion/layouts/__init__.py
@@ -9,10 +9,36 @@ NB: this has a long way to go before it 
 
 """
 
+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]()