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

[PATCH] remote-hg: skip ill-formed references

From
Max Kirillov <max@max630.net>
Date
Aug 31, 2013, 01:15 UTC
Message-ID
<20130831011542.GA10486@wheezy.local>

References which fail check_refname_format() cause the whole import to fail. This might be undesirable if the references are not important.

A better solution would be to provide some mapping, either by some reversible encoding, or by generating and storing the associations locally.

But this is already going to allow working with many
existing repositories.
---
If there is no smarter solution ongoing maybe this could be
useful.
 contrib/remote-helpers/git-remote-hg | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index 0194c67..e32003b 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -591,6 +591,17 @@ def list_head(repo, cur):
     print "@refs/heads/%s HEAD" % head
     g_head = (head, node)
 
+def print_list_entry_if_valid(ref):
+    # same checks as in check_refname_format() in refs.c
+    if ref.startswith('.') or ref.find('/.') != -1 or \
+            ref.find('..') != -1 or \
+            any([(c <= ' ' or c in '~^:\\\177') for c in ref]) or \
+            ref.endswith('/') or \
+            ref.endswith('.lock'):
+        warn("Ill-named reference '%s' skipped" % ref)
+    else:
+        print "? %s" % ref
+
 def do_list(parser):
     global branches, bmarks, track_branches
 
@@ -611,15 +622,15 @@ def do_list(parser):
 
     if track_branches:
         for branch in branches:
-            print "? refs/heads/branches/%s" % gitref(branch)
+            print_list_entry_if_valid("refs/heads/branches/%s" % gitref(branch))
 
     for bmark in bmarks:
-        print "? refs/heads/%s" % gitref(bmark)
+        print_list_entry_if_valid("refs/heads/%s" % gitref(bmark))
 
     for tag, node in repo.tagslist():
         if tag == 'tip':
             continue
-        print "? refs/tags/%s" % gitref(tag)
+        print_list_entry_if_valid("refs/tags/%s" % gitref(tag))
 
     print
 
-- 
1.8.4.rc3.902.g80a4b9e
Next: Felipe Contreras
Message 1 of 6 in “remote-hg: skip ill-formed references”
  1. remote-hg: skip ill-formed referencesMax Kirillov, Aug 31, 2013
  2. Felipe ContrerasAug 31, 2013
  3. Max KirillovAug 31, 2013
  4. Felipe ContrerasAug 31, 2013
  5. Felipe ContrerasAug 31, 2013
  6. Max KirillovAug 31, 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.