mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
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.
This commit is contained in:
parent
ce06b102df
commit
4e663d3541
@ -19,34 +19,45 @@ def _local(path):
|
||||
return (os.path.isfile(path) and bundlerepo or localrepo)
|
||||
|
||||
def addbranchrevs(lrepo, repo, branches, revs):
|
||||
if not branches:
|
||||
hashbranch, branches = branches
|
||||
if not hashbranch and not branches:
|
||||
return revs or None, revs and revs[0] or None
|
||||
revs = revs and list(revs) or []
|
||||
if not repo.capable('branchmap'):
|
||||
revs.extend(branches)
|
||||
if branches:
|
||||
raise util.Abort(_("remote branch lookup not supported"))
|
||||
revs.append(hashbranch)
|
||||
return revs, revs[0]
|
||||
branchmap = repo.branchmap()
|
||||
for branch in branches:
|
||||
if branch == '.':
|
||||
|
||||
def primary(butf8):
|
||||
if butf8 == '.':
|
||||
if not lrepo or not lrepo.local():
|
||||
raise util.Abort(_("dirstate branch not accessible"))
|
||||
butf8 = lrepo.dirstate.branch()
|
||||
branch = encoding.tolocal(butf8)
|
||||
else:
|
||||
butf8 = encoding.fromlocal(branch)
|
||||
if butf8 in branchmap:
|
||||
revs.extend(node.hex(r) for r in reversed(branchmap[butf8]))
|
||||
return True
|
||||
else:
|
||||
revs.append(branch)
|
||||
return False
|
||||
|
||||
for branch in branches:
|
||||
butf8 = encoding.fromlocal(branch)
|
||||
if not primary(butf8):
|
||||
raise error.RepoLookupError(_("unknown branch '%s'") % branch)
|
||||
if hashbranch:
|
||||
butf8 = encoding.fromlocal(hashbranch)
|
||||
if not primary(butf8):
|
||||
revs.append(hashbranch)
|
||||
return revs, revs[0]
|
||||
|
||||
def parseurl(url, branches=None):
|
||||
'''parse url#branch, returning url, branches+[branch]'''
|
||||
'''parse url#branch, returning (url, (branch, branches))'''
|
||||
|
||||
if '#' not in url:
|
||||
return url, branches or []
|
||||
return url, (None, branches or [])
|
||||
url, branch = url.split('#', 1)
|
||||
return url, (branches or []) + [branch]
|
||||
return url, (branch, branches or [])
|
||||
|
||||
schemes = {
|
||||
'bundle': bundlerepo,
|
||||
|
@ -12,6 +12,7 @@ hg up 0
|
||||
hg branch c
|
||||
echo c > foo
|
||||
hg ci -d '0 0' -mc
|
||||
hg tag -l z
|
||||
cd ..
|
||||
hg clone -r 0 branch branch2
|
||||
cd branch2
|
||||
@ -32,6 +33,10 @@ hg branch -f b
|
||||
echo b2 > foo
|
||||
hg ci -d '0 0' -mb2
|
||||
|
||||
echo unknown branch and fallback
|
||||
hg in -qbz
|
||||
hg in -q ../branch#z
|
||||
hg out -qbz
|
||||
echo in rev c branch a
|
||||
hg in -qr c ../branch#a
|
||||
hg in -qr c -b a
|
||||
|
@ -15,9 +15,14 @@ marked working directory as branch b
|
||||
marked working directory as branch æ
|
||||
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||
marked working directory as branch æ
|
||||
created new head
|
||||
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||
marked working directory as branch b
|
||||
created new head
|
||||
unknown branch and fallback
|
||||
abort: unknown branch 'z'!
|
||||
2:f25d57ab0566
|
||||
abort: unknown branch 'z'!
|
||||
in rev c branch a
|
||||
1:dd6e60a716c6
|
||||
2:f25d57ab0566
|
||||
|
@ -1,5 +1,5 @@
|
||||
http://example.com/no/anchor, branches: []
|
||||
http://example.com/an/anchor, branches: ['foo']
|
||||
http://example.com/no/anchor/branches, branches: ['foo']
|
||||
http://example.com/an/anchor/branches, branches: ['foo', 'bar']
|
||||
http://example.com/an/anchor/branches-None, branches: ['foo']
|
||||
http://example.com/no/anchor, branches: (None, [])
|
||||
http://example.com/an/anchor, branches: ('foo', [])
|
||||
http://example.com/no/anchor/branches, branches: (None, ['foo'])
|
||||
http://example.com/an/anchor/branches, branches: ('bar', ['foo'])
|
||||
http://example.com/an/anchor/branches-None, branches: ('foo', [])
|
||||
|
Loading…
Reference in New Issue
Block a user