remote-hg: pass around revision refs

So that when a diverge is detected, we know which ref to report an error
for.

Also, since we are not throwing an exception, return a proper error
code.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Felipe Contreras 2013-05-24 21:29:51 -05:00 committed by Junio C Hamano
parent 19a8cefc44
commit 883d7be110
2 changed files with 24 additions and 16 deletions

View File

@ -857,18 +857,19 @@ def write_tag(repo, tag, node, msg, author):
encoding.encoding = tmp
return tagnode
return (tagnode, branch)
def checkheads(repo, remote, p_revs):
remotemap = remote.branchmap()
if not remotemap:
# empty repo
return
return True
new = {}
ret = True
for node in p_revs:
for node, ref in p_revs.iteritems():
ctx = repo[node]
branch = ctx.branch()
if not branch in remotemap:
@ -893,7 +894,11 @@ def checkheads(repo, remote, p_revs):
if found:
continue
raise Exception("non-fast-forward")
node = repo.changelog.node(rev)
print "error %s non-fast forward" % p_revs[node]
ret = False
return ret
def push_unsafe(repo, remote, parsed_refs, p_revs):
@ -903,8 +908,8 @@ def push_unsafe(repo, remote, parsed_refs, p_revs):
commoninc = fci(repo, remote, force=force)
common, _, remoteheads = commoninc
if not force:
checkheads(repo, remote, p_revs)
if not force and not checkheads(repo, remote, p_revs):
return None
cg = repo.getbundle('push', heads=list(p_revs), common=common)
@ -940,7 +945,7 @@ def do_export(parser):
global parsed_refs, bmarks, peer
p_bmarks = []
p_revs = set()
p_revs = {}
parser.next()
@ -965,7 +970,7 @@ def do_export(parser):
if branch in branches and bnode in branches[branch]:
# up to date
continue
p_revs.add(bnode)
p_revs[bnode] = ref
print "ok %s" % ref
elif ref.startswith('refs/heads/'):
bmark = ref[len('refs/heads/'):]
@ -980,7 +985,7 @@ def do_export(parser):
not (bmark == 'master' and bmark not in parser.repo._bookmarks):
p_bmarks.append((ref, bmark, old, new))
p_revs.add(bnode)
p_revs[bnode] = ref
elif ref.startswith('refs/tags/'):
tag = ref[len('refs/tags/'):]
tag = hgref(tag)
@ -988,20 +993,23 @@ def do_export(parser):
if mode == 'git':
if not msg:
msg = 'Added tag %s for changeset %s' % (tag, node[:12]);
tagnode = write_tag(parser.repo, tag, node, msg, author)
p_revs.add(tagnode)
tagnode, branch = write_tag(parser.repo, tag, node, msg, author)
p_revs[tagnode] = 'refs/heads/branches/' + gitref(branch)
else:
fp = parser.repo.opener('localtags', 'a')
fp.write('%s %s\n' % (node, tag))
fp.close()
p_revs.add(bnode)
p_revs[bnode] = ref
print "ok %s" % ref
else:
# transport-helper/fast-export bugs
continue
if peer:
push(parser.repo, peer, parsed_refs, p_revs)
if not push(parser.repo, peer, parsed_refs, p_revs):
# do not update bookmarks
print
return
# update remote bookmarks
remote_bmarks = peer.listkeys('bookmarks')

View File

@ -328,7 +328,7 @@ test_expect_success 'remote new bookmark' '
check_bookmark hgrepo feature-b feature-b
'
test_expect_failure 'remote push diverged' '
test_expect_success 'remote push diverged' '
test_when_finished "rm -rf gitrepo*" &&
git clone "hg::hgrepo" gitrepo &&
@ -351,7 +351,7 @@ test_expect_failure 'remote push diverged' '
check_branch hgrepo default bump
'
test_expect_failure 'remote update bookmark diverge' '
test_expect_success 'remote update bookmark diverge' '
test_when_finished "rm -rf gitrepo*" &&
(
@ -398,7 +398,7 @@ test_expect_failure 'remote new bookmark multiple branch head' '
# cleanup previous stuff
rm -rf hgrepo
test_expect_failure 'remote big push' '
test_expect_success 'remote big push' '
test_when_finished "rm -rf hgrepo gitrepo*" &&
(