remote-hg: reorganize bookmark handling

We don't need to update both internal and remote bookmarks, so let's do
one or the other, and move the shared code earlier, so it's simpler.

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:46 -05:00 committed by Junio C Hamano
parent 0bf9ee5720
commit aaadca28b6

View File

@ -885,8 +885,17 @@ def do_export(parser):
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/'):]
p_bmarks.append((bmark, node)) new = node
old = bmarks[bmark].hex() if bmark in bmarks else ''
if old == new:
continue continue
print "ok %s" % ref
if bmark != fake_bmark and \
not (bmark == 'master' and bmark not in parser.repo._bookmarks):
p_bmarks.append((ref, bmark, old, new))
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)
@ -906,39 +915,18 @@ def do_export(parser):
if peer: if peer:
parser.repo.push(peer, force=force_push, newbranch=True) parser.repo.push(peer, force=force_push, newbranch=True)
# update remote bookmarks
remote_bmarks = peer.listkeys('bookmarks') remote_bmarks = peer.listkeys('bookmarks')
for ref, bmark, old, new in p_bmarks:
# handle bookmarks
for bmark, node in p_bmarks:
ref = 'refs/heads/' + bmark
new = node
if bmark in bmarks:
old = bmarks[bmark].hex()
else:
old = ''
if old == new:
continue
if bmark == fake_bmark or \
bmark == 'master' and 'master' not in parser.repo._bookmarks:
print "ok %s" % ref
continue
elif bookmarks.pushbookmark(parser.repo, bmark, old, new):
# updated locally
pass
else:
print "error %s" % ref
continue
if peer:
old = remote_bmarks.get(bmark, '') old = remote_bmarks.get(bmark, '')
if not peer.pushkey('bookmarks', bmark, old, new): if not peer.pushkey('bookmarks', bmark, old, new):
print "error %s" % ref print "error %s" % ref
continue else:
# update local bookmarks
print "ok %s" % ref for ref, bmark, old, new in p_bmarks:
if not bookmarks.pushbookmark(parser.repo, bmark, old, new):
print "error %s" % ref
print print