Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 10365:d757bc0c7865
interpret repo#name url syntax as branch instead of revision
Previously, the name part of an repo#name url was interpreted as a
revision, similar to using the --rev option. Now it is instead looked
up as a branch first, and if that succeeds all the heads of the branch
will be processed instead of just its tip-most head. If the branch
lookup fails, it will be assumed to be an revision as before (e.g. for
tags).
author | Sune Foldager <cryo@cyanite.org> |
---|---|
date | Sun, 07 Feb 2010 14:29:07 +0100 |
parents | d42821cd5c96 |
children | a78bfaf988e1 |
comparison
equal
deleted
inserted
replaced
10364:de1e7099d100 | 10365:d757bc0c7865 |
---|---|
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 | 8 |
9 from i18n import _ | 9 from i18n import _ |
10 from lock import release | 10 from lock import release |
11 import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo | 11 import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo |
12 import lock, util, extensions, error, encoding | 12 import lock, util, extensions, error, encoding, node |
13 import merge as _merge | 13 import merge as _merge |
14 import verify as _verify | 14 import verify as _verify |
15 import errno, os, shutil | 15 import errno, os, shutil |
16 | 16 |
17 def _local(path): | 17 def _local(path): |
18 return (os.path.isfile(util.drop_scheme('file', path)) and | 18 return (os.path.isfile(util.drop_scheme('file', path)) and |
19 bundlerepo or localrepo) | 19 bundlerepo or localrepo) |
20 | 20 |
21 def parseurl(url, revs=[]): | 21 def addbranchrevs(lrepo, repo, branches, revs): |
22 '''parse url#branch, returning url, branch + revs''' | 22 if not branches: |
23 return revs or None, revs and revs[0] or None | |
24 branchmap = repo.branchmap() | |
25 revs = revs and list(revs) or [] | |
26 for branch in branches: | |
27 if branch == '.': | |
28 if not lrepo or not lrepo.local(): | |
29 raise util.Abort(_("dirstate branch not accessible")) | |
30 revs.append(lrepo.dirstate.branch()) | |
31 else: | |
32 butf8 = encoding.fromlocal(branch) | |
33 if butf8 in branchmap: | |
34 revs.extend(node.hex(r) for r in reversed(branchmap[butf8])) | |
35 else: | |
36 revs.append(branch) | |
37 return revs, revs[0] | |
38 | |
39 def parseurl(url, branches=None): | |
40 '''parse url#branch, returning url, branches+[branch]''' | |
23 | 41 |
24 if '#' not in url: | 42 if '#' not in url: |
25 return url, (revs or None), revs and revs[0] or None | 43 return url, branches or [] |
26 | |
27 url, branch = url.split('#', 1) | 44 url, branch = url.split('#', 1) |
28 checkout = revs and revs[0] or branch | 45 return url, (branches or []) + [branch] |
29 return url, (revs or []) + [branch], checkout | |
30 | 46 |
31 schemes = { | 47 schemes = { |
32 'bundle': bundlerepo, | 48 'bundle': bundlerepo, |
33 'file': _local, | 49 'file': _local, |
34 'http': httprepo, | 50 'http': httprepo, |
92 else: | 108 else: |
93 dest = ui.expandpath(dest) | 109 dest = ui.expandpath(dest) |
94 | 110 |
95 if isinstance(source, str): | 111 if isinstance(source, str): |
96 origsource = ui.expandpath(source) | 112 origsource = ui.expandpath(source) |
97 source, rev, checkout = parseurl(origsource, '') | 113 source, branches = parseurl(origsource) |
98 srcrepo = repository(ui, source) | 114 srcrepo = repository(ui, source) |
115 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) | |
99 else: | 116 else: |
100 srcrepo = source | 117 srcrepo = source |
101 origsource = source = srcrepo.url() | 118 origsource = source = srcrepo.url() |
102 checkout = None | 119 checkout = None |
103 | 120 |
181 anything else is treated as a revision) | 198 anything else is treated as a revision) |
182 """ | 199 """ |
183 | 200 |
184 if isinstance(source, str): | 201 if isinstance(source, str): |
185 origsource = ui.expandpath(source) | 202 origsource = ui.expandpath(source) |
186 source, rev, checkout = parseurl(origsource, rev) | 203 source, branch = parseurl(origsource) |
187 src_repo = repository(ui, source) | 204 src_repo = repository(ui, source) |
188 else: | 205 else: |
189 src_repo = source | 206 src_repo = source |
190 origsource = source = src_repo.url() | 207 origsource = source = src_repo.url() |
191 checkout = rev and rev[0] or None | 208 rev, checkout = addbranchrevs(src_repo, src_repo, branch, rev) |
192 | 209 |
193 if dest is None: | 210 if dest is None: |
194 dest = defaultdest(source) | 211 dest = defaultdest(source) |
195 ui.status(_("destination directory: %s\n") % dest) | 212 ui.status(_("destination directory: %s\n") % dest) |
196 else: | 213 else: |