comparison 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
comparison
equal deleted inserted replaced
1011:cc774e975aed 1012:e8cd211684c4
7 7
8 NB: this has a long way to go before it does everything it claims to 8 NB: this has a long way to go before it does everything it claims to
9 9
10 """ 10 """
11 11
12 from mercurial import util as hgutil
13
12 import detect 14 import detect
13 import persist 15 import persist
16 import single
17 import standard
14 18
15 __all__ = [ 19 __all__ = [
16 "detect", 20 "detect",
21 "layout_from_name",
17 "persist", 22 "persist",
18 ] 23 ]
24
25 # This is the authoritative store of what layouts are available.
26 # The intention is for extension authors who wish to build their own
27 # layout to add it to this dict.
28 NAME_TO_CLASS = {
29 "single": single.SingleLayout,
30 "standard": standard.StandardLayout,
31 }
32
33
34 def layout_from_name(name):
35 """Returns a layout module given the layout name
36
37 You should use one of the layout.detect.* functions to get the
38 name to pass to this function.
39
40 """
41
42 if name not in NAME_TO_CLASS:
43 raise hgutil.Abort('Unknown hgsubversion layout: %s' %name)
44 return NAME_TO_CLASS[name]()