Mercurial > hg
comparison mercurial/hg.py @ 14568:5f002e3336ba
hg: split peer and repo lookup tables
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 11 Jun 2011 14:14:52 -0500 |
parents | 517e1d88bf7e |
children | 9f1139cf5c76 |
comparison
equal
deleted
inserted
replaced
14567:b72cef1b8b26 | 14568:5f002e3336ba |
---|---|
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 schemes = { | 64 _reposchemes = { |
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 _lookup(path): | 73 def _repolookup(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 = schemes.get(scheme) or schemes['file'] | 76 thing = _reposchemes.get(scheme) or _reposchemes['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 _lookup(repo).islocal(repo) | 86 return _repolookup(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 = _lookup(path).instance(ui, path, create) | 93 repo = _repolookup(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 | 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 | |
101 def peer(ui, opts, path, create=False): | 119 def peer(ui, opts, path, create=False): |
102 '''return a repository peer for the specified path''' | 120 '''return a repository peer for the specified path''' |
103 rui = remoteui(ui, opts) | 121 rui = remoteui(ui, opts) |
104 return _lookup(path).instance(rui, path, create) | 122 return _peerlookup(path).instance(rui, path, create) |
105 | 123 |
106 def defaultdest(source): | 124 def defaultdest(source): |
107 '''return default destination of clone if none is given''' | 125 '''return default destination of clone if none is given''' |
108 return os.path.basename(os.path.normpath(source)) | 126 return os.path.basename(os.path.normpath(source)) |
109 | 127 |