All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Simon Ruderich <simon@ruderich.org>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 13/16] remote-hg: allow refs with spaces
Date: Mon, 22 Apr 2013 16:55:21 -0500	[thread overview]
Message-ID: <1366667724-567-14-git-send-email-felipe.contreras@gmail.com> (raw)
In-Reply-To: <1366667724-567-1-git-send-email-felipe.contreras@gmail.com>

Mercurial supports them, Git doesn't.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-hg | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index dbb4091..6f4afd7 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -75,6 +75,12 @@ def hgmode(mode):
 def hghex(node):
     return hg.node.hex(node)
 
+def hgref(ref):
+    return ref.replace('___', ' ')
+
+def gitref(ref):
+    return ref.replace(' ', '___')
+
 def get_config(config):
     cmd = ['git', 'config', '--get', config]
     process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -437,10 +443,10 @@ def export_ref(repo, name, kind, head):
     marks.set_tip(ename, rev)
 
 def export_tag(repo, tag):
-    export_ref(repo, tag, 'tags', repo[tag])
+    export_ref(repo, tag, 'tags', repo[hgref(tag)])
 
 def export_bookmark(repo, bmark):
-    head = bmarks[bmark]
+    head = bmarks[hgref(bmark)]
     export_ref(repo, bmark, 'bookmarks', head)
 
 def export_branch(repo, branch):
@@ -479,14 +485,14 @@ def branch_tip(repo, branch):
 def get_branch_tip(repo, branch):
     global branches
 
-    heads = branches.get(branch, None)
+    heads = branches.get(hgref(branch), None)
     if not heads:
         return None
 
     # verify there's only one head
     if (len(heads) > 1):
         warn("Branch '%s' has more than one head, consider merging" % branch)
-        return branch_tip(repo, branch)
+        return branch_tip(repo, hgref(branch))
 
     return heads[0]
 
@@ -508,6 +514,7 @@ def list_head(repo, cur):
             head = 'master'
         bmarks[head] = node
 
+    head = gitref(head)
     print "@refs/heads/%s HEAD" % head
     g_head = (head, node)
 
@@ -529,15 +536,15 @@ def do_list(parser):
                 branches[branch] = heads
 
         for branch in branches:
-            print "? refs/heads/branches/%s" % branch
+            print "? refs/heads/branches/%s" % gitref(branch)
 
     for bmark in bmarks:
-        print "? refs/heads/%s" % bmark
+        print "? refs/heads/%s" % gitref(bmark)
 
     for tag, node in repo.tagslist():
         if tag == 'tip':
             continue
-        print "? refs/tags/%s" % tag
+        print "? refs/tags/%s" % gitref(tag)
 
     print
 
@@ -674,7 +681,8 @@ def parse_commit(parser):
 
     # Check if the ref is supposed to be a named branch
     if ref.startswith('refs/heads/branches/'):
-        extra['branch'] = ref[len('refs/heads/branches/'):]
+        branch = ref[len('refs/heads/branches/'):]
+        extra['branch'] = hgref(branch)
 
     if mode == 'hg':
         i = data.find('\n--HG--\n')
@@ -803,6 +811,7 @@ def do_export(parser):
             continue
         elif ref.startswith('refs/tags/'):
             tag = ref[len('refs/tags/'):]
+            tag = hgref(tag)
             author, msg = parsed_tags.get(tag, (None, None))
             if mode == 'git':
                 if not msg:
-- 
1.8.2.1.790.g4588561

  parent reply	other threads:[~2013-04-22 22:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-22 21:55 [PATCH 00/16] remote-hg: second round of improvements Felipe Contreras
2013-04-22 21:55 ` [PATCH 01/16] remote-helpers: avoid has_key Felipe Contreras
2013-04-22 22:28   ` Junio C Hamano
2013-04-22 22:35     ` Felipe Contreras
2013-04-22 22:51       ` Dusty Phillips
2013-04-22 21:55 ` [PATCH 02/16] remote-hg: safer bookmark pushing Felipe Contreras
2013-04-22 21:55 ` [PATCH 03/16] remote-hg: use python urlparse Felipe Contreras
2013-04-22 21:55 ` [PATCH 04/16] remote-hg: properly mark branches up-to-date Felipe Contreras
2013-04-22 21:55 ` [PATCH 05/16] remote-hg: add branch_tip() helper Felipe Contreras
2013-04-22 21:55 ` [PATCH 06/16] remote-hg: add support for tag objects Felipe Contreras
2013-04-22 21:55 ` [PATCH 07/16] remote-hg: custom method to write tags Felipe Contreras
2013-04-22 21:55 ` [PATCH 08/16] remote-hg: write tags in the appropriate branch Felipe Contreras
2013-04-22 21:55 ` [PATCH 09/16] remote-hg: add custom local tag write code Felipe Contreras
2013-04-22 21:55 ` [PATCH 10/16] remote-hg: improve email sanitation Felipe Contreras
2013-04-22 21:55 ` [PATCH 11/16] remote-hg: add support for schemes extension Felipe Contreras
2013-04-22 21:55 ` [PATCH 12/16] remote-hg: don't update bookmarks unnecessarily Felipe Contreras
2013-04-22 21:55 ` Felipe Contreras [this message]
2013-04-22 22:32   ` [PATCH 13/16] remote-hg: allow refs with spaces Junio C Hamano
2013-04-22 22:38     ` Felipe Contreras
2013-04-22 23:03       ` Junio C Hamano
2013-04-22 21:55 ` [PATCH 14/16] remote-hg: small performance improvement Felipe Contreras
2013-04-22 21:55 ` [PATCH 15/16] remote-hg: use marks instead of inlined files Felipe Contreras
2013-04-22 22:33   ` Junio C Hamano
2013-04-22 21:55 ` [PATCH 16/16] remote-hg: strip extra newline Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1366667724-567-14-git-send-email-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=simon@ruderich.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.