{"thread":{"id":"34814","subject":"[PATCH] remote-hg: skip ill-formed references","startedAt":"2013-08-31T01:15:42Z","lastAt":"2013-08-31T19:51:58Z","messageCount":6,"participants":["Max Kirillov","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"226389","messageId":"20130831011542.GA10486@wheezy.local","threadId":"34814","inReplyTo":null,"subject":"[PATCH] remote-hg: skip ill-formed references","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2013-08-31T01:15:42Z","receivedAt":"2013-08-31T01:15:42Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"References which fail check_refname_format() cause the whole\nimport to fail. This might be undesirable if the references\nare not important.\n\nA better solution would be to provide some mapping, either\nby some reversible encoding, or by generating and storing\nthe associations locally.\n\nBut this is already going to allow working with many\nexisting repositories.\n---\nIf there is no smarter solution ongoing maybe this could be\nuseful.\n contrib/remote-helpers/git-remote-hg | 17 ++++++++++++++---\n 1 file changed, 14 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg\nindex 0194c67..e32003b 100755\n--- a/contrib/remote-helpers/git-remote-hg\n+++ b/contrib/remote-helpers/git-remote-hg\n@@ -591,6 +591,17 @@ def list_head(repo, cur):\n     print \"@refs/heads/%s HEAD\" % head\n     g_head = (head, node)\n \n+def print_list_entry_if_valid(ref):\n+    # same checks as in check_refname_format() in refs.c\n+    if ref.startswith('.') or ref.find('/.') != -1 or \\\n+            ref.find('..') != -1 or \\\n+            any([(c <= ' ' or c in '~^:\\\\\\177') for c in ref]) or \\\n+            ref.endswith('/') or \\\n+            ref.endswith('.lock'):\n+        warn(\"Ill-named reference '%s' skipped\" % ref)\n+    else:\n+        print \"? %s\" % ref\n+\n def do_list(parser):\n     global branches, bmarks, track_branches\n \n@@ -611,15 +622,15 @@ def do_list(parser):\n \n     if track_branches:\n         for branch in branches:\n-            print \"? refs/heads/branches/%s\" % gitref(branch)\n+            print_list_entry_if_valid(\"refs/heads/branches/%s\" % gitref(branch))\n \n     for bmark in bmarks:\n-        print \"? refs/heads/%s\" % gitref(bmark)\n+        print_list_entry_if_valid(\"refs/heads/%s\" % gitref(bmark))\n \n     for tag, node in repo.tagslist():\n         if tag == 'tip':\n             continue\n-        print \"? refs/tags/%s\" % gitref(tag)\n+        print_list_entry_if_valid(\"refs/tags/%s\" % gitref(tag))\n \n     print\n \n-- \n1.8.4.rc3.902.g80a4b9e\n"},{"id":"226391","messageId":"CAMP44s2f7S4STbCOuh35sgdrgAdw-2Tw1LDkjhO37hXLxX3mRQ@mail.gmail.com","threadId":"34814","inReplyTo":"20130831011542.GA10486@wheezy.local","subject":"Re: [PATCH] remote-hg: skip ill-formed references","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-08-31T01:39:27Z","receivedAt":"2013-08-31T01:39:27Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Aug 30, 2013 at 8:15 PM, Max Kirillov <max@max630.net> wrote:\n> References which fail check_refname_format() cause the whole\n> import to fail. This might be undesirable if the references\n> are not important.\n>\n> A better solution would be to provide some mapping, either\n> by some reversible encoding, or by generating and storing\n> the associations locally.\n>\n> But this is already going to allow working with many\n> existing repositories.\n\nWhich repository triggered this?\n\nMaybe we should do something similar as in git-remote-bzr:\n\n\ndef ref_is_valid(name):\n    return not True in [c in name for c in '~^: \\\\']\n\n\n        if not ref_is_valid(tag):\n            continue\n        print \"? refs/tags/%s\" % tag\n\n-- \nFelipe Contreras\n"},{"id":"226417","messageId":"loom.20130831T155657-714@post.gmane.org","threadId":"34814","inReplyTo":"CAMP44s2f7S4STbCOuh35sgdrgAdw-2Tw1LDkjhO37hXLxX3mRQ@mail.gmail.com","subject":"Re: [PATCH] remote-hg: skip ill-formed references","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2013-08-31T13:58:33Z","receivedAt":"2013-08-31T13:58:33Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"Felipe Contreras <felipe.contreras <at> \ngmail.com> writes:\n> Which repository triggered this?\n\nTha was some of the vim repositories, upstream \nhttps://code.google.com/p/vim/ or debian \nanonscm.debian.org/hg/pkg-vim/vim, or both. \nThey contain tags with ~ symbol.\n\nI don't have any experience with bazaar yet, so \ncannot say much about it.\n\nBr,\n-- \nMax\n"},{"id":"226426","messageId":"CAMP44s0Ht4tu3XuKW5BYFZFMHVMwMZtD8dJgULHqdb47__Hq5g@mail.gmail.com","threadId":"34814","inReplyTo":"loom.20130831T155657-714@post.gmane.org","subject":"Re: [PATCH] remote-hg: skip ill-formed references","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-08-31T17:32:17Z","receivedAt":"2013-08-31T17:32:17Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Aug 31, 2013 at 8:58 AM, Max Kirillov <max@max630.net> wrote:\n> Felipe Contreras <felipe.contreras <at>\n> gmail.com> writes:\n>> Which repository triggered this?\n>\n> Tha was some of the vim repositories, upstream\n> https://code.google.com/p/vim/ or debian\n> anonscm.debian.org/hg/pkg-vim/vim, or both.\n> They contain tags with ~ symbol.\n\nThanks.\n\n> I don't have any experience with bazaar yet, so\n> cannot say much about it.\n\nThat code is independent from bazaar. the ref_is_valid() method should\nreturn True or False depending on whether Git thinks it's a valid ref\nor not, it's independent from Bazaar or Mercurial, and all\nremote-helpers could share the same one.\n\nSo this is what I have in mind:\n\n--- a/git-remote-hg.py\n+++ b/git-remote-hg.py\n@@ -617,6 +617,9 @@ def list_head(repo, cur):\n     print \"@refs/heads/%s HEAD\" % head\n     g_head = (head, node)\n\n+def ref_is_valid(name):\n+    return not True in [c in name for c in '~^: \\\\']\n+\n def do_list(parser):\n     repo = parser.repo\n     for bmark, node in bookmarks.listbookmarks(repo).iteritems():\n@@ -635,15 +638,24 @@ def do_list(parser):\n\n     if track_branches:\n         for branch in branches:\n-            print \"? refs/heads/branches/%s\" % gitref(branch)\n+            branch = gitref(branch)\n+            if not ref_is_valid(branch):\n+                continue\n+            print \"? refs/heads/branches/%s\" % branch\n\n     for bmark in bmarks:\n-        print \"? refs/heads/%s\" % gitref(bmark)\n+        bmark = gitref(bmark)\n+        if not ref_is_valid(bmark):\n+            continue\n+        print \"? refs/heads/%s\" % bmark\n\n     for tag, node in repo.tagslist():\n         if tag == 'tip':\n             continue\n-        print \"? refs/tags/%s\" % gitref(tag)\n+        tag = gitref(tag)\n+        if not ref_is_valid(tag):\n+            continue\n+        print \"? refs/tags/%s\" % tag\n\n     print\n\n-- \nFelipe Contreras\n"},{"id":"226427","messageId":"CAMP44s2VOq_KEDkytF8Knbm4g12tf=K5ZVden8t=udi=KP+yPQ@mail.gmail.com","threadId":"34814","inReplyTo":"loom.20130831T155657-714@post.gmane.org","subject":"Re: [PATCH] remote-hg: skip ill-formed references","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-08-31T17:57:34Z","receivedAt":"2013-08-31T17:57:34Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Aug 31, 2013 at 8:58 AM, Max Kirillov <max@max630.net> wrote:\n> Felipe Contreras <felipe.contreras <at>\n> gmail.com> writes:\n>> Which repository triggered this?\n>\n> Tha was some of the vim repositories, upstream\n> https://code.google.com/p/vim/ or debian\n> anonscm.debian.org/hg/pkg-vim/vim, or both.\n> They contain tags with ~ symbol.\n\nI can clone both fine. This is what I get with the debian one:\n\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.436+hg~e12b9d992389-1' locally\nerror: * Ignoring funny ref\n'refs/tags/debian-7.2.436+hg~e12b9d992389-1+' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.438+hg~d44112feb815-1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.438+hg~d44112feb815-2' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.438+hg~d44112feb815-3' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.438+hg~d44112feb815-4' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.438+hg~d44112feb815-5' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.2.445+hg~cb94c42c0e1a-1' locally\nerror: * Ignoring funny ref\n'refs/tags/debian-7.3b.20100720+hg~7b7508ee56f1-1' locally\nerror: * Ignoring funny ref\n'refs/tags/debian-7.3f.20100812+hg~20e83abf88b1-1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.000+hg~ee53a39d5896-1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.035+hg~8fdc12103333-1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.154+hg~74503f6ee649-1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.154+hg~74503f6ee649-2' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.547-6~bpo60+1' locally\nerror: * Ignoring funny ref 'refs/tags/debian-7.3.547-7~bpo60+1' locally\n\nMaybe you need a newer version of Git. I'm using v1.8.4.\n\n-- \nFelipe Contreras\n"},{"id":"226447","messageId":"20130831195158.GA17436@wheezy.local","threadId":"34814","inReplyTo":"CAMP44s2VOq_KEDkytF8Knbm4g12tf=K5ZVden8t=udi=KP+yPQ@mail.gmail.com","subject":"Re: [PATCH] remote-hg: skip ill-formed references","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2013-08-31T19:51:58Z","receivedAt":"2013-08-31T19:51:58Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"On Sat, Aug 31, 2013 at 12:57:34PM -0500, Felipe Contreras wrote:\n> On Sat, Aug 31, 2013 at 8:58 AM, Max Kirillov <max@max630.net> wrote:\n>> Tha was some of the vim repositories, upstream\n>> https://code.google.com/p/vim/ or debian\n>> anonscm.debian.org/hg/pkg-vim/vim, or both.\n>> They contain tags with ~ symbol.\n> \n> I can clone both fine. This is what I get with the debian one:\n> \n> error: * Ignoring funny ref 'refs/tags/debian-7.2.436+hg~e12b9d992389-1' locally\n\nYes, it really works with the new version. I used 1.7.10\nbefore.\n\nSince it is fixed already, just forget it. Sorry, should\nhave checked it with the latest version.\n\n-- \nMax\n"}]}