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>

Felipe Contreras committed May 24, 2013 at 21:29 UTC aaadca28b6148c262385c258c761e166eff6fbeb
1 file changed +19 -31
contrib/remote-helpers/git-remote-hg
+19 -31
@@ -885,8 +885,17 @@ def do_export(parser):
885 print "ok %s" % ref
886 elif ref.startswith('refs/heads/'):
887 bmark = ref[len('refs/heads/'):]
888 - p_bmarks.append((bmark, node))
889 - continue
888 + new = node
889 + old = bmarks[bmark].hex() if bmark in bmarks else ''
890 +
891 + if old == new:
892 + continue
893 +
894 + print "ok %s" % ref
895 + if bmark != fake_bmark and \
896 + not (bmark == 'master' and bmark not in parser.repo._bookmarks):
897 + p_bmarks.append((ref, bmark, old, new))
898 +
899 elif ref.startswith('refs/tags/'):
900 tag = ref[len('refs/tags/'):]
901 tag = hgref(tag)
@@ -906,39 +915,18 @@ def do_export(parser):
915
916 if peer:
917 parser.repo.push(peer, force=force_push, newbranch=True)
909 - remote_bmarks = peer.listkeys('bookmarks')
910 -
911 - # handle bookmarks
912 - for bmark, node in p_bmarks:
913 - ref = 'refs/heads/' + bmark
914 - new = node
915 -
916 - if bmark in bmarks:
917 - old = bmarks[bmark].hex()
918 - else:
919 - old = ''
920 -
921 - if old == new:
922 - continue
918
924 - if bmark == fake_bmark or \
925 - bmark == 'master' and 'master' not in parser.repo._bookmarks:
926 - print "ok %s" % ref
927 - continue
928 - elif bookmarks.pushbookmark(parser.repo, bmark, old, new):
929 - # updated locally
930 - pass
931 - else:
932 - print "error %s" % ref
933 - continue
934 -
935 - if peer:
919 + # update remote bookmarks
920 + remote_bmarks = peer.listkeys('bookmarks')
921 + for ref, bmark, old, new in p_bmarks:
922 old = remote_bmarks.get(bmark, '')
923 if not peer.pushkey('bookmarks', bmark, old, new):
924 print "error %s" % ref
939 - continue
940 -
941 - print "ok %s" % ref
925 + else:
926 + # update local bookmarks
927 + for ref, bmark, old, new in p_bmarks:
928 + if not bookmarks.pushbookmark(parser.repo, bmark, old, new):
929 + print "error %s" % ref
930
931 print
932