remote-hg: refactor export

No functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Apr 11, 2013 at 07:23 UTC 0ff1b61770f42921d68b488f0ec3756d5477bc78
1 file changed +12 -8
contrib/remote-helpers/git-remote-hg
+12 -8
@@ -9,7 +9,7 @@
9 # Then you can clone with:
10 # git clone hg::/path/to/mercurial/repo/
11
12 -from mercurial import hg, ui, bookmarks, context, util, encoding
12 +from mercurial import hg, ui, bookmarks, context, util, encoding, node
13
14 import re
15 import sys
@@ -60,6 +60,9 @@ def hgmode(mode):
60 m = { '100755': 'x', '120000': 'l' }
61 return m.get(mode, '')
62
63 +def hghex(node):
64 + return hg.node.hex(node)
65 +
66 def get_config(config):
67 cmd = ['git', 'config', '--get', config]
68 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -705,19 +708,18 @@ def do_export(parser):
708
709 for ref, node in parsed_refs.iteritems():
710 if ref.startswith('refs/heads/branches'):
708 - pass
711 + print "ok %s" % ref
712 elif ref.startswith('refs/heads/'):
713 bmark = ref[len('refs/heads/'):]
714 p_bmarks.append((bmark, node))
712 - # handle below
715 continue
716 elif ref.startswith('refs/tags/'):
717 tag = ref[len('refs/tags/'):]
718 parser.repo.tag([tag], node, None, True, None, {})
719 + print "ok %s" % ref
720 else:
721 # transport-helper/fast-export bugs
722 continue
720 - print "ok %s" % ref
723
724 if peer:
725 parser.repo.push(peer, force=False)
@@ -725,6 +727,7 @@ def do_export(parser):
727 # handle bookmarks
728 for bmark, node in p_bmarks:
729 ref = 'refs/heads/' + bmark
730 + new = hghex(node)
731
732 if bmark in bmarks:
733 old = bmarks[bmark].hex()
@@ -733,10 +736,11 @@ def do_export(parser):
736
737 if bmark == 'master' and 'master' not in parser.repo._bookmarks:
738 # fake bookmark
736 - print "ok %s" % ref
737 - continue
738 -
739 - if not bookmarks.pushbookmark(parser.repo, bmark, old, node):
739 + pass
740 + elif bookmarks.pushbookmark(parser.repo, bmark, old, new):
741 + # updated locally
742 + pass
743 + else:
744 print "error %s" % ref
745 continue
746