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:
parent
19a8cefc44
commit
883d7be110
@ -857,18 +857,19 @@ def write_tag(repo, tag, node, msg, author):
|
|||||||
|
|
||||||
encoding.encoding = tmp
|
encoding.encoding = tmp
|
||||||
|
|
||||||
return tagnode
|
return (tagnode, branch)
|
||||||
|
|
||||||
def checkheads(repo, remote, p_revs):
|
def checkheads(repo, remote, p_revs):
|
||||||
|
|
||||||
remotemap = remote.branchmap()
|
remotemap = remote.branchmap()
|
||||||
if not remotemap:
|
if not remotemap:
|
||||||
# empty repo
|
# empty repo
|
||||||
return
|
return True
|
||||||
|
|
||||||
new = {}
|
new = {}
|
||||||
|
ret = True
|
||||||
|
|
||||||
for node in p_revs:
|
for node, ref in p_revs.iteritems():
|
||||||
ctx = repo[node]
|
ctx = repo[node]
|
||||||
branch = ctx.branch()
|
branch = ctx.branch()
|
||||||
if not branch in remotemap:
|
if not branch in remotemap:
|
||||||
@ -893,7 +894,11 @@ def checkheads(repo, remote, p_revs):
|
|||||||
if found:
|
if found:
|
||||||
continue
|
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):
|
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)
|
commoninc = fci(repo, remote, force=force)
|
||||||
common, _, remoteheads = commoninc
|
common, _, remoteheads = commoninc
|
||||||
|
|
||||||
if not force:
|
if not force and not checkheads(repo, remote, p_revs):
|
||||||
checkheads(repo, remote, p_revs)
|
return None
|
||||||
|
|
||||||
cg = repo.getbundle('push', heads=list(p_revs), common=common)
|
cg = repo.getbundle('push', heads=list(p_revs), common=common)
|
||||||
|
|
||||||
@ -940,7 +945,7 @@ def do_export(parser):
|
|||||||
global parsed_refs, bmarks, peer
|
global parsed_refs, bmarks, peer
|
||||||
|
|
||||||
p_bmarks = []
|
p_bmarks = []
|
||||||
p_revs = set()
|
p_revs = {}
|
||||||
|
|
||||||
parser.next()
|
parser.next()
|
||||||
|
|
||||||
@ -965,7 +970,7 @@ def do_export(parser):
|
|||||||
if branch in branches and bnode in branches[branch]:
|
if branch in branches and bnode in branches[branch]:
|
||||||
# up to date
|
# up to date
|
||||||
continue
|
continue
|
||||||
p_revs.add(bnode)
|
p_revs[bnode] = ref
|
||||||
print "ok %s" % ref
|
print "ok %s" % ref
|
||||||
elif ref.startswith('refs/heads/'):
|
elif ref.startswith('refs/heads/'):
|
||||||
bmark = ref[len('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):
|
not (bmark == 'master' and bmark not in parser.repo._bookmarks):
|
||||||
p_bmarks.append((ref, bmark, old, new))
|
p_bmarks.append((ref, bmark, old, new))
|
||||||
|
|
||||||
p_revs.add(bnode)
|
p_revs[bnode] = ref
|
||||||
elif ref.startswith('refs/tags/'):
|
elif ref.startswith('refs/tags/'):
|
||||||
tag = ref[len('refs/tags/'):]
|
tag = ref[len('refs/tags/'):]
|
||||||
tag = hgref(tag)
|
tag = hgref(tag)
|
||||||
@ -988,20 +993,23 @@ def do_export(parser):
|
|||||||
if mode == 'git':
|
if mode == 'git':
|
||||||
if not msg:
|
if not msg:
|
||||||
msg = 'Added tag %s for changeset %s' % (tag, node[:12]);
|
msg = 'Added tag %s for changeset %s' % (tag, node[:12]);
|
||||||
tagnode = write_tag(parser.repo, tag, node, msg, author)
|
tagnode, branch = write_tag(parser.repo, tag, node, msg, author)
|
||||||
p_revs.add(tagnode)
|
p_revs[tagnode] = 'refs/heads/branches/' + gitref(branch)
|
||||||
else:
|
else:
|
||||||
fp = parser.repo.opener('localtags', 'a')
|
fp = parser.repo.opener('localtags', 'a')
|
||||||
fp.write('%s %s\n' % (node, tag))
|
fp.write('%s %s\n' % (node, tag))
|
||||||
fp.close()
|
fp.close()
|
||||||
p_revs.add(bnode)
|
p_revs[bnode] = ref
|
||||||
print "ok %s" % ref
|
print "ok %s" % ref
|
||||||
else:
|
else:
|
||||||
# transport-helper/fast-export bugs
|
# transport-helper/fast-export bugs
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if peer:
|
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
|
# update remote bookmarks
|
||||||
remote_bmarks = peer.listkeys('bookmarks')
|
remote_bmarks = peer.listkeys('bookmarks')
|
||||||
|
@ -328,7 +328,7 @@ test_expect_success 'remote new bookmark' '
|
|||||||
check_bookmark hgrepo feature-b feature-b
|
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*" &&
|
test_when_finished "rm -rf gitrepo*" &&
|
||||||
|
|
||||||
git clone "hg::hgrepo" gitrepo &&
|
git clone "hg::hgrepo" gitrepo &&
|
||||||
@ -351,7 +351,7 @@ test_expect_failure 'remote push diverged' '
|
|||||||
check_branch hgrepo default bump
|
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*" &&
|
test_when_finished "rm -rf gitrepo*" &&
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -398,7 +398,7 @@ test_expect_failure 'remote new bookmark multiple branch head' '
|
|||||||
# cleanup previous stuff
|
# cleanup previous stuff
|
||||||
rm -rf hgrepo
|
rm -rf hgrepo
|
||||||
|
|
||||||
test_expect_failure 'remote big push' '
|
test_expect_success 'remote big push' '
|
||||||
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
||||||
|
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user