Mercurial > hg
comparison mercurial/hg.py @ 11322:3d6915f5a2bb
improve --branch processing (and differentiate from # syntax)
Previously #foo and --branch foo were handled identically.
The behavior of #foo hasn't changed, but --branch now works like this:
1) If branchmap is not supported on the remote, the operation fails.
2) If branch is '.', substitute with branch of the working dir parent.
3) If branch exists remotely, its heads are expanded.
4) Otherwise, the operation fails.
Tests have been added for the new cases.
author | Sune Foldager <cryo@cyanite.org> |
---|---|
date | Thu, 10 Jun 2010 12:46:09 +0200 |
parents | 3f1409082720 |
children | be5e86c80628 |
comparison
equal
deleted
inserted
replaced
11321:40c06bbf58be | 11322:3d6915f5a2bb |
---|---|
17 def _local(path): | 17 def _local(path): |
18 path = util.expandpath(util.drop_scheme('file', path)) | 18 path = util.expandpath(util.drop_scheme('file', path)) |
19 return (os.path.isfile(path) and bundlerepo or localrepo) | 19 return (os.path.isfile(path) and bundlerepo or localrepo) |
20 | 20 |
21 def addbranchrevs(lrepo, repo, branches, revs): | 21 def addbranchrevs(lrepo, repo, branches, revs): |
22 if not branches: | 22 hashbranch, branches = branches |
23 if not hashbranch and not branches: | |
23 return revs or None, revs and revs[0] or None | 24 return revs or None, revs and revs[0] or None |
24 revs = revs and list(revs) or [] | 25 revs = revs and list(revs) or [] |
25 if not repo.capable('branchmap'): | 26 if not repo.capable('branchmap'): |
26 revs.extend(branches) | 27 if branches: |
28 raise util.Abort(_("remote branch lookup not supported")) | |
29 revs.append(hashbranch) | |
27 return revs, revs[0] | 30 return revs, revs[0] |
28 branchmap = repo.branchmap() | 31 branchmap = repo.branchmap() |
29 for branch in branches: | 32 |
30 if branch == '.': | 33 def primary(butf8): |
34 if butf8 == '.': | |
31 if not lrepo or not lrepo.local(): | 35 if not lrepo or not lrepo.local(): |
32 raise util.Abort(_("dirstate branch not accessible")) | 36 raise util.Abort(_("dirstate branch not accessible")) |
33 butf8 = lrepo.dirstate.branch() | 37 butf8 = lrepo.dirstate.branch() |
34 branch = encoding.tolocal(butf8) | |
35 else: | |
36 butf8 = encoding.fromlocal(branch) | |
37 if butf8 in branchmap: | 38 if butf8 in branchmap: |
38 revs.extend(node.hex(r) for r in reversed(branchmap[butf8])) | 39 revs.extend(node.hex(r) for r in reversed(branchmap[butf8])) |
40 return True | |
39 else: | 41 else: |
40 revs.append(branch) | 42 return False |
43 | |
44 for branch in branches: | |
45 butf8 = encoding.fromlocal(branch) | |
46 if not primary(butf8): | |
47 raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
48 if hashbranch: | |
49 butf8 = encoding.fromlocal(hashbranch) | |
50 if not primary(butf8): | |
51 revs.append(hashbranch) | |
41 return revs, revs[0] | 52 return revs, revs[0] |
42 | 53 |
43 def parseurl(url, branches=None): | 54 def parseurl(url, branches=None): |
44 '''parse url#branch, returning url, branches+[branch]''' | 55 '''parse url#branch, returning (url, (branch, branches))''' |
45 | 56 |
46 if '#' not in url: | 57 if '#' not in url: |
47 return url, branches or [] | 58 return url, (None, branches or []) |
48 url, branch = url.split('#', 1) | 59 url, branch = url.split('#', 1) |
49 return url, (branches or []) + [branch] | 60 return url, (branch, branches or []) |
50 | 61 |
51 schemes = { | 62 schemes = { |
52 'bundle': bundlerepo, | 63 'bundle': bundlerepo, |
53 'file': _local, | 64 'file': _local, |
54 'http': httprepo, | 65 'http': httprepo, |