git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remote-hg: skip ill-formed references
@ 2013-08-31  1:15 Max Kirillov
  2013-08-31  1:39 ` Felipe Contreras
  0 siblings, 1 reply; 6+ messages in thread
From: Max Kirillov @ 2013-08-31  1:15 UTC (permalink / raw)
  To: Felipe Contreras, Junio C Hamano; +Cc: git

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-31 19:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-31  1:15 [PATCH] remote-hg: skip ill-formed references Max Kirillov
2013-08-31  1:39 ` Felipe Contreras
2013-08-31 13:58   ` Max Kirillov
2013-08-31 17:32     ` Felipe Contreras
2013-08-31 17:57     ` Felipe Contreras
2013-08-31 19:51       ` Max Kirillov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).