git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 13/16] remote-hg: allow refs with spaces

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 22, 2013, 22:32 UTC
Message-ID
<7v61zenqm4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1366667724-567-14-git-send-email-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
> Mercurial supports them, Git doesn't.

Another important thing to note is that you represent a SP with three underscores on our side, no?

Show 97 quoted lines
> 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:
Previous: Felipe ContrerasNext: Felipe Contreras
Message 18 of 24 in “remote-hg: second round of improvements”
  1. 00/16 remote-hg: second round of improvementsFelipe Contreras, Apr 22, 2013
  2. 01/16 remote-helpers: avoid has_keyFelipe Contreras, Apr 22, 2013
  3. Junio C HamanoApr 22, 2013
  4. Felipe ContrerasApr 22, 2013
  5. Dusty PhillipsApr 22, 2013
  6. 02/16 remote-hg: safer bookmark pushingFelipe Contreras, Apr 22, 2013
  7. 03/16 remote-hg: use python urlparseFelipe Contreras, Apr 22, 2013
  8. 04/16 remote-hg: properly mark branches up-to-dateFelipe Contreras, Apr 22, 2013
  9. 05/16 remote-hg: add branch_tip() helperFelipe Contreras, Apr 22, 2013
  10. 06/16 remote-hg: add support for tag objectsFelipe Contreras, Apr 22, 2013
  11. 07/16 remote-hg: custom method to write tagsFelipe Contreras, Apr 22, 2013
  12. 08/16 remote-hg: write tags in the appropriate branchFelipe Contreras, Apr 22, 2013
  13. 09/16 remote-hg: add custom local tag write codeFelipe Contreras, Apr 22, 2013
  14. 10/16 remote-hg: improve email sanitationFelipe Contreras, Apr 22, 2013
  15. 11/16 remote-hg: add support for schemes extensionFelipe Contreras, Apr 22, 2013
  16. 12/16 remote-hg: don't update bookmarks unnecessarilyFelipe Contreras, Apr 22, 2013
  17. 13/16 remote-hg: allow refs with spacesFelipe Contreras, Apr 22, 2013
  18. Junio C HamanoApr 22, 2013
  19. Felipe ContrerasApr 22, 2013
  20. Junio C HamanoApr 22, 2013
  21. 14/16 remote-hg: small performance improvementFelipe Contreras, Apr 22, 2013
  22. 15/16 remote-hg: use marks instead of inlined filesFelipe Contreras, Apr 22, 2013
  23. Junio C HamanoApr 22, 2013
  24. 16/16 remote-hg: strip extra newlineFelipe Contreras, Apr 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.