Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 14605:9f1139cf5c76
hg: rearrange peer scheme lookup
There is now only peer scheme lookup. Repository lookup goes through
peer scheme lookup. When peer and repo types are finally separated,
repo lookup will use peer.local() to get a repository object.
The underbar is dropped so that extensions can patch the table.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 13 Jun 2011 14:53:23 -0500 |
parents | 5f002e3336ba |
children | 6e631c24c6d9 |
comparison
equal
deleted
inserted
replaced
14604:b1a534335548 | 14605:9f1139cf5c76 |
---|---|
59 if u.fragment: | 59 if u.fragment: |
60 branch = u.fragment | 60 branch = u.fragment |
61 u.fragment = None | 61 u.fragment = None |
62 return str(u), (branch, branches or []) | 62 return str(u), (branch, branches or []) |
63 | 63 |
64 _reposchemes = { | 64 peerschemes = { |
65 'bundle': bundlerepo, | 65 'bundle': bundlerepo, |
66 'file': _local, | 66 'file': _local, |
67 'http': httprepo, | 67 'http': httprepo, |
68 'https': httprepo, | 68 'https': httprepo, |
69 'ssh': sshrepo, | 69 'ssh': sshrepo, |
70 'static-http': statichttprepo, | 70 'static-http': statichttprepo, |
71 } | 71 } |
72 | 72 |
73 def _repolookup(path): | 73 def _peerlookup(path): |
74 u = util.url(path) | 74 u = util.url(path) |
75 scheme = u.scheme or 'file' | 75 scheme = u.scheme or 'file' |
76 thing = _reposchemes.get(scheme) or _reposchemes['file'] | 76 thing = peerschemes.get(scheme) or peerschemes['file'] |
77 try: | 77 try: |
78 return thing(path) | 78 return thing(path) |
79 except TypeError: | 79 except TypeError: |
80 return thing | 80 return thing |
81 | 81 |
82 def islocal(repo): | 82 def islocal(repo): |
83 '''return true if repo or path is local''' | 83 '''return true if repo or path is local''' |
84 if isinstance(repo, str): | 84 if isinstance(repo, str): |
85 try: | 85 try: |
86 return _repolookup(repo).islocal(repo) | 86 return _peerlookup(repo).islocal(repo) |
87 except AttributeError: | 87 except AttributeError: |
88 return False | 88 return False |
89 return repo.local() | 89 return repo.local() |
90 | 90 |
91 def repository(ui, path='', create=False): | 91 def repository(ui, path='', create=False): |
92 """return a repository object for the specified path""" | 92 """return a repository object for the specified path""" |
93 repo = _repolookup(path).instance(ui, path, create) | 93 repo = _peerlookup(path).instance(ui, path, create) |
94 ui = getattr(repo, "ui", ui) | 94 ui = getattr(repo, "ui", ui) |
95 for name, module in extensions.extensions(): | 95 for name, module in extensions.extensions(): |
96 hook = getattr(module, 'reposetup', None) | 96 hook = getattr(module, 'reposetup', None) |
97 if hook: | 97 if hook: |
98 hook(ui, repo) | 98 hook(ui, repo) |
99 return repo | 99 return repo |
100 | |
101 _peerschemes = { | |
102 'bundle': bundlerepo, | |
103 'file': _local, | |
104 'http': httprepo, | |
105 'https': httprepo, | |
106 'ssh': sshrepo, | |
107 'static-http': statichttprepo, | |
108 } | |
109 | |
110 def _peerlookup(path): | |
111 u = util.url(path) | |
112 scheme = u.scheme or 'file' | |
113 thing = _peerschemes.get(scheme) or _peerschemes['file'] | |
114 try: | |
115 return thing(path) | |
116 except TypeError: | |
117 return thing | |
118 | 100 |
119 def peer(ui, opts, path, create=False): | 101 def peer(ui, opts, path, create=False): |
120 '''return a repository peer for the specified path''' | 102 '''return a repository peer for the specified path''' |
121 rui = remoteui(ui, opts) | 103 rui = remoteui(ui, opts) |
122 return _peerlookup(path).instance(rui, path, create) | 104 return _peerlookup(path).instance(rui, path, create) |