{"thread":{"id":"9305","subject":"(Resend)[PATCH] git-svn: Translate invalid characters in refname","startedAt":"2007-07-30T09:08:21Z","lastAt":"2007-08-15T22:53:29Z","messageCount":6,"participants":["Robert Ewald","Junio C Hamano","Eric Wong","martin f krafft"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"49083","messageId":"f8k9q5$927$1@sea.gmane.org","threadId":"9305","inReplyTo":null,"subject":"(Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"Robert Ewald","fromEmail":"robert.ewald@nov.com","sentAt":"2007-07-30T09:08:21Z","receivedAt":"2007-07-30T09:08:21Z","isPatch":true,"sender":{"key":"robert.ewald@nov.com","avatar":null},"body":"In git some characters are invalid as documented\nin git-check-ref-format. In subversion these characters might\nbe valid, so a translation is required.\n\nThis patch does this translation by url escaping characters, that\nare not allowed.\n\nCredit goes to Eric Wong, martin f. krafft and Jan Hudec\n\nSigned-off-by: Robert Ewald <robewald@gmx.net>\n---\n\nSecond posting of translating characters. I hope I got it right this\ntime. Thanks to Alex for taking the time to point me to\nDocumentation/SubmittingPatches.\n\n git-svn.perl |   38 +++++++++++++++++++++++++++++++++++---\n 1 files changed, 35 insertions(+), 3 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 6c692a7..bc55d05 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -938,8 +938,8 @@ sub resolve_local_globs {\n        foreach (command(qw#for-each-ref --format=%(refname) refs/remotes#)) {\n                next unless m#^refs/remotes/$ref->{regex}$#;\n                my $p = $1;\n-               my $pathname = $path->full_path($p);\n-               my $refname = $ref->full_path($p);\n+               my $pathname = desanitize_refname($path->full_path($p));\n+               my $refname = desanitize_refname($ref->full_path($p));\n                if (my $existing = $fetch->{$pathname}) {\n                        if ($existing ne $refname) {\n                                die \"Refspec conflict:\\n\",\n@@ -1239,7 +1239,39 @@ sub new {\n        $self;\n }\n \n-sub refname { \"refs/remotes/$_[0]->{ref_id}\" }\n+sub refname {\n+        my ($refname) = \"refs/remotes/$_[0]->{ref_id}\" ;\n+\n+        # It cannot end with a slash /, we'll throw up on this because\n+        # SVN can't have directories with a slash in their name, either:\n+        if ($refname =~ m{/$}) {\n+                die \"ref: '$refname' ends with a trailing slash, this is \",\n+                    \"not permitted by git nor Subversion\\n\";\n+        }\n+\n+        # It cannot have ASCII control character space, tilde ~, caret ^,\n+        # colon :, question-mark ?, asterisk *, space, or open bracket [\n+        # anywhere.\n+        #\n+        # Additionally, % must be escaped because it is used for escaping\n+        # and we want our escaped refname to be reversible\n+        $refname =~ s{([ \\%~\\^:\\?\\*\\[\\t])}{uc sprintf('%%%02x',ord($1))}eg;\n+\n+        # no slash-separated component can begin with a dot .\n+        # /.* becomes /%2E*\n+        $refname =~ s{/\\.}{/%2E}g;\n+        # It cannot have two consecutive dots .. anywhere\n+        # .. becomes %2E%2E\n+        $refname =~ s{\\.\\.}{%2E%2E}g;\n+\n+        $refname;\n+}\n+\n+sub desanitize_refname {\n+    my ($refname) = @_;\n+    $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;\n+    $refname;\n+}\n \n sub svm_uuid {\n        my ($self) = @_;\n-- \n1.5.3.rc3-dirty\n"},{"id":"49091","messageId":"7v6442kxvu.fsf@assigned-by-dhcp.cox.net","threadId":"9305","inReplyTo":"f8k9q5$927$1@sea.gmane.org","subject":"Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-30T10:07:49Z","receivedAt":"2007-07-30T10:07:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robert Ewald <robert.ewald@nov.com> writes:\n\n> +sub refname {\n> +        my ($refname) = \"refs/remotes/$_[0]->{ref_id}\" ;\n> +\n> +        # It cannot end with a slash /, we'll throw up on this because\n> +        # SVN can't have directories with a slash in their name, either:\n> +        if ($refname =~ m{/$}) {\n> +                die \"ref: '$refname' ends with a trailing slash, this is \",\n> +                    \"not permitted by git nor Subversion\\n\";\n> +        }\n> +\n> +        # It cannot have ASCII control character space, tilde ~, caret ^,\n> +        # colon :, question-mark ?, asterisk *, space, or open bracket [\n> +        # anywhere.\n> +        #\n> +        # Additionally, % must be escaped because it is used for escaping\n> +        # and we want our escaped refname to be reversible\n> +        $refname =~ s{([ \\%~\\^:\\?\\*\\[\\t])}{uc sprintf('%%%02x',ord($1))}eg;\n\nuc of sprintf()?  You meant \"%%%02X\"?\n\nOther than that, looks sane to me.  I presume that SVN branches\nwhose name would be mangled with this patch would not have been\nsuccessfully imported with older git-svn anyway, so this won't\nintroduce any regressions?\n\nEric?\n"},{"id":"49103","messageId":"f8kpan$t6c$1@sea.gmane.org","threadId":"9305","inReplyTo":"7v6442kxvu.fsf@assigned-by-dhcp.cox.net","subject":"Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"Robert Ewald","fromEmail":"robert.ewald@nov.com","sentAt":"2007-07-30T13:33:11Z","receivedAt":"2007-07-30T13:33:11Z","isPatch":true,"sender":{"key":"robert.ewald@nov.com","avatar":null},"body":"Junio C Hamano wrote:\n\n> Robert Ewald <robert.ewald@nov.com> writes:\n> \n>> +sub refname {\n>> +        my ($refname) = \"refs/remotes/$_[0]->{ref_id}\" ;\n>> +\n>> +        # It cannot end with a slash /, we'll throw up on this because\n>> +        # SVN can't have directories with a slash in their name, either:\n>> +        if ($refname =~ m{/$}) {\n>> +                die \"ref: '$refname' ends with a trailing slash, this is \",\n>> +                    \"not permitted by git nor Subversion\\n\";\n>> +        }\n>> +\n>> +        # It cannot have ASCII control character space, tilde ~, caret ^,\n>> +        # colon :, question-mark ?, asterisk *, space, or open bracket [\n>> +        # anywhere.\n>> +        #\n>> +        # Additionally, % must be escaped because it is used for escaping\n>> +        # and we want our escaped refname to be reversible\n>> +        $refname =~ s{([ \\%~\\^:\\?\\*\\[\\t])}{uc sprintf('%%%02x',ord($1))}eg;\n> \n> uc of sprintf()?  You meant \"%%%02X\"?\n\nYou are right. Being a total Perl noob I just took Eric's suggestion from an\nearlier post without really understanding everything.\n\n> Other than that, looks sane to me.  I presume that SVN branches\n> whose name would be mangled with this patch would not have been\n> successfully imported with older git-svn anyway, so this won't\n> introduce any regressions?\n\nNow that you mention it, I am not entirely sure. We introduce the % which is\nmangled as well. It wasn't mangled before.\n\nI now could think of a case that someone has a git-svn branch with a % in the\nname checked out.\n\nWhen updates are fetched a new branch head would be created. It wouldn't \ndestroy anything, but a script might break. On the other hand, the script needs\nto be updated anyway. So I am not sure if % should be handled separately.\n\n> Eric?\nYes, Eric, please comment.\n\n-- \nRobert Ewald\n"},{"id":"49126","messageId":"20070730192929.GB9764@hand.yhbt.net","threadId":"9305","inReplyTo":"7v6442kxvu.fsf@assigned-by-dhcp.cox.net","subject":"Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-07-30T19:29:30Z","receivedAt":"2007-07-30T19:29:30Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> Robert Ewald <robert.ewald@nov.com> writes:\n> \n> > +sub refname {\n> > +        my ($refname) = \"refs/remotes/$_[0]->{ref_id}\" ;\n> > +\n> > +        # It cannot end with a slash /, we'll throw up on this because\n> > +        # SVN can't have directories with a slash in their name, either:\n> > +        if ($refname =~ m{/$}) {\n> > +                die \"ref: '$refname' ends with a trailing slash, this is \",\n> > +                    \"not permitted by git nor Subversion\\n\";\n> > +        }\n> > +\n> > +        # It cannot have ASCII control character space, tilde ~, caret ^,\n> > +        # colon :, question-mark ?, asterisk *, space, or open bracket [\n> > +        # anywhere.\n> > +        #\n> > +        # Additionally, % must be escaped because it is used for escaping\n> > +        # and we want our escaped refname to be reversible\n> > +        $refname =~ s{([ \\%~\\^:\\?\\*\\[\\t])}{uc sprintf('%%%02x',ord($1))}eg;\n> \n> uc of sprintf()?  You meant \"%%%02X\"?\n\nAh, I wasn't sure if X was portable enough, but then again this sprintf\nis in Perl.\n\n> Other than that, looks sane to me.  I presume that SVN branches\n> whose name would be mangled with this patch would not have been\n> successfully imported with older git-svn anyway, so this won't\n> introduce any regressions?\n\nSeems alright to me, I haven't had a chance to look at it too hard.  I'm\nout of town and haven't been following the mailing list lately.\n\nAcked-by: Eric Wong <normalperson@yhbt.net>\n\n-- \nEric Wong\n"},{"id":"49166","messageId":"7vlkcxifuo.fsf@assigned-by-dhcp.cox.net","threadId":"9305","inReplyTo":"f8k9q5$927$1@sea.gmane.org","subject":"Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-31T00:20:15Z","receivedAt":"2007-07-31T00:20:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This patch is totally whitespace mangled, but I'll apply by hand\nfor now.\n"},{"id":"50836","messageId":"20070815225329.GA9174@piper.oerlikon.madduck.net","threadId":"9305","inReplyTo":"f8k9q5$927$1@sea.gmane.org","subject":"Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname","fromName":"martin f krafft","fromEmail":"madduck@madduck.net","sentAt":"2007-08-15T22:53:29Z","receivedAt":"2007-08-15T22:53:29Z","isPatch":true,"sender":{"key":"madduck@madduck.net","avatar":null},"body":"also sprach Robert Ewald <robert.ewald@nov.com> [2007.07.30.1108 +0200]:\n> In git some characters are invalid as documented\n> in git-check-ref-format. In subversion these characters might\n> be valid, so a translation is required.\n> \n> This patch does this translation by url escaping characters, that\n> are not allowed.\n\nHave you worked more on this? I am back now and could test it on\nvarious svn imports. Just want to make sure I have the latest\nversion.\n\n-- \nmartin;              (greetings from the heart of the sun.)\n  \\____ echo mailto: !#^.\"<*>\"|tr \"<*> mailto:\" net@madduck\n \n\"we should have a volleyballocracy.\n we elect a six-pack of presidents.\n each one serves until they screw up,\n at which point they rotate.\"\n                                                      -- dennis miller\n \nspamtraps: madduck.bogus@madduck.net\n"}]}