remote-hg: allow refs with spaces
Mercurial supports them, Git doesn't. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 22, 2013 at 16:55 UTC
b0f6c5835dd298106a286cac83abe4e8cee02567
1 file changed
+17
-8
contrib/remote-helpers/git-remote-hg
+17
-8
@@ -75,6 +75,12 @@ def hgmode(mode):
75
def hghex(node):
76
return hg.node.hex(node)
77
78
+def hgref(ref):
79
+ return ref.replace('___', ' ')
80
+
81
+def gitref(ref):
82
+ return ref.replace(' ', '___')
83
+
84
def get_config(config):
85
cmd = ['git', 'config', '--get', config]
86
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -437,10 +443,10 @@ def export_ref(repo, name, kind, head):
443
marks.set_tip(ename, rev)
444
445
def export_tag(repo, tag):
440
- export_ref(repo, tag, 'tags', repo[tag])
446
+ export_ref(repo, tag, 'tags', repo[hgref(tag)])
447
448
def export_bookmark(repo, bmark):
443
- head = bmarks[bmark]
449
+ head = bmarks[hgref(bmark)]
450
export_ref(repo, bmark, 'bookmarks', head)
451
452
def export_branch(repo, branch):
@@ -479,14 +485,14 @@ def branch_tip(repo, branch):
485
def get_branch_tip(repo, branch):
486
global branches
487
482
- heads = branches.get(branch, None)
488
+ heads = branches.get(hgref(branch), None)
489
if not heads:
490
return None
491
492
# verify there's only one head
493
if (len(heads) > 1):
494
warn("Branch '%s' has more than one head, consider merging" % branch)
489
- return branch_tip(repo, branch)
495
+ return branch_tip(repo, hgref(branch))
496
497
return heads[0]
498
@@ -508,6 +514,7 @@ def list_head(repo, cur):
514
head = 'master'
515
bmarks[head] = node
516
517
+ head = gitref(head)
518
print "@refs/heads/%s HEAD" % head
519
g_head = (head, node)
520
@@ -529,15 +536,15 @@ def do_list(parser):
536
branches[branch] = heads
537
538
for branch in branches:
532
- print "? refs/heads/branches/%s" % branch
539
+ print "? refs/heads/branches/%s" % gitref(branch)
540
541
for bmark in bmarks:
535
- print "? refs/heads/%s" % bmark
542
+ print "? refs/heads/%s" % gitref(bmark)
543
544
for tag, node in repo.tagslist():
545
if tag == 'tip':
546
continue
540
- print "? refs/tags/%s" % tag
547
+ print "? refs/tags/%s" % gitref(tag)
548
549
print
550
@@ -674,7 +681,8 @@ def parse_commit(parser):
681
682
# Check if the ref is supposed to be a named branch
683
if ref.startswith('refs/heads/branches/'):
677
- extra['branch'] = ref[len('refs/heads/branches/'):]
684
+ branch = ref[len('refs/heads/branches/'):]
685
+ extra['branch'] = hgref(branch)
686
687
if mode == 'hg':
688
i = data.find('\n--HG--\n')
@@ -803,6 +811,7 @@ def do_export(parser):
811
continue
812
elif ref.startswith('refs/tags/'):
813
tag = ref[len('refs/tags/'):]
814
+ tag = hgref(tag)
815
author, msg = parsed_tags.get(tag, (None, None))
816
if mode == 'git':
817
if not msg: