Skip to content

Commit

Permalink
remote-hg: refactor export
Browse files Browse the repository at this point in the history
No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Apr 11, 2013
1 parent f04f489 commit 0ff1b61
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions contrib/remote-helpers/git-remote-hg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Then you can clone with:
# git clone hg::/path/to/mercurial/repo/

from mercurial import hg, ui, bookmarks, context, util, encoding
from mercurial import hg, ui, bookmarks, context, util, encoding, node

import re
import sys
Expand Down Expand Up @@ -60,6 +60,9 @@ def hgmode(mode):
m = { '100755': 'x', '120000': 'l' }
return m.get(mode, '')

def hghex(node):
return hg.node.hex(node)

def get_config(config):
cmd = ['git', 'config', '--get', config]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand Down Expand Up @@ -705,26 +708,26 @@ def do_export(parser):

for ref, node in parsed_refs.iteritems():
if ref.startswith('refs/heads/branches'):
pass
print "ok %s" % ref
elif ref.startswith('refs/heads/'):
bmark = ref[len('refs/heads/'):]
p_bmarks.append((bmark, node))
# handle below
continue
elif ref.startswith('refs/tags/'):
tag = ref[len('refs/tags/'):]
parser.repo.tag([tag], node, None, True, None, {})
print "ok %s" % ref
else:
# transport-helper/fast-export bugs
continue
print "ok %s" % ref

if peer:
parser.repo.push(peer, force=False)

# handle bookmarks
for bmark, node in p_bmarks:
ref = 'refs/heads/' + bmark
new = hghex(node)

if bmark in bmarks:
old = bmarks[bmark].hex()
Expand All @@ -733,10 +736,11 @@ def do_export(parser):

if bmark == 'master' and 'master' not in parser.repo._bookmarks:
# fake bookmark
print "ok %s" % ref
continue

if not bookmarks.pushbookmark(parser.repo, bmark, old, node):
pass
elif bookmarks.pushbookmark(parser.repo, bmark, old, new):
# updated locally
pass
else:
print "error %s" % ref
continue

Expand Down

0 comments on commit 0ff1b61

Please sign in to comment.