git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* (Resend)[PATCH] git-svn: Translate invalid characters in refname
@ 2007-07-30  9:08 Robert Ewald
  2007-07-30 10:07 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Robert Ewald @ 2007-07-30  9:08 UTC (permalink / raw)
  To: git

In git some characters are invalid as documented
in git-check-ref-format. In subversion these characters might
be valid, so a translation is required.

This patch does this translation by url escaping characters, that
are not allowed.

Credit goes to Eric Wong, martin f. krafft and Jan Hudec

Signed-off-by: Robert Ewald <robewald@gmx.net>
---

Second posting of translating characters. I hope I got it right this
time. Thanks to Alex for taking the time to point me to
Documentation/SubmittingPatches.

 git-svn.perl |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 6c692a7..bc55d05 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -938,8 +938,8 @@ sub resolve_local_globs {
        foreach (command(qw#for-each-ref --format=%(refname) refs/remotes#)) {
                next unless m#^refs/remotes/$ref->{regex}$#;
                my $p = $1;
-               my $pathname = $path->full_path($p);
-               my $refname = $ref->full_path($p);
+               my $pathname = desanitize_refname($path->full_path($p));
+               my $refname = desanitize_refname($ref->full_path($p));
                if (my $existing = $fetch->{$pathname}) {
                        if ($existing ne $refname) {
                                die "Refspec conflict:\n",
@@ -1239,7 +1239,39 @@ sub new {
        $self;
 }
 
-sub refname { "refs/remotes/$_[0]->{ref_id}" }
+sub refname {
+        my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
+
+        # It cannot end with a slash /, we'll throw up on this because
+        # SVN can't have directories with a slash in their name, either:
+        if ($refname =~ m{/$}) {
+                die "ref: '$refname' ends with a trailing slash, this is ",
+                    "not permitted by git nor Subversion\n";
+        }
+
+        # It cannot have ASCII control character space, tilde ~, caret ^,
+        # colon :, question-mark ?, asterisk *, space, or open bracket [
+        # anywhere.
+        #
+        # Additionally, % must be escaped because it is used for escaping
+        # and we want our escaped refname to be reversible
+        $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
+
+        # no slash-separated component can begin with a dot .
+        # /.* becomes /%2E*
+        $refname =~ s{/\.}{/%2E}g;
+        # It cannot have two consecutive dots .. anywhere
+        # .. becomes %2E%2E
+        $refname =~ s{\.\.}{%2E%2E}g;
+
+        $refname;
+}
+
+sub desanitize_refname {
+    my ($refname) = @_;
+    $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
+    $refname;
+}
 
 sub svm_uuid {
        my ($self) = @_;
-- 
1.5.3.rc3-dirty

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

* Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname
  2007-07-30  9:08 (Resend)[PATCH] git-svn: Translate invalid characters in refname Robert Ewald
@ 2007-07-30 10:07 ` Junio C Hamano
  2007-07-30 13:33   ` Robert Ewald
  2007-07-30 19:29   ` Eric Wong
  2007-07-31  0:20 ` Junio C Hamano
  2007-08-15 22:53 ` martin f krafft
  2 siblings, 2 replies; 6+ messages in thread
From: Junio C Hamano @ 2007-07-30 10:07 UTC (permalink / raw)
  To: Robert Ewald; +Cc: git, Eric Wong

Robert Ewald <robert.ewald@nov.com> writes:

> +sub refname {
> +        my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
> +
> +        # It cannot end with a slash /, we'll throw up on this because
> +        # SVN can't have directories with a slash in their name, either:
> +        if ($refname =~ m{/$}) {
> +                die "ref: '$refname' ends with a trailing slash, this is ",
> +                    "not permitted by git nor Subversion\n";
> +        }
> +
> +        # It cannot have ASCII control character space, tilde ~, caret ^,
> +        # colon :, question-mark ?, asterisk *, space, or open bracket [
> +        # anywhere.
> +        #
> +        # Additionally, % must be escaped because it is used for escaping
> +        # and we want our escaped refname to be reversible
> +        $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;

uc of sprintf()?  You meant "%%%02X"?

Other than that, looks sane to me.  I presume that SVN branches
whose name would be mangled with this patch would not have been
successfully imported with older git-svn anyway, so this won't
introduce any regressions?

Eric?

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

* Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname
  2007-07-30 10:07 ` Junio C Hamano
@ 2007-07-30 13:33   ` Robert Ewald
  2007-07-30 19:29   ` Eric Wong
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Ewald @ 2007-07-30 13:33 UTC (permalink / raw)
  To: git

Junio C Hamano wrote:

> Robert Ewald <robert.ewald@nov.com> writes:
> 
>> +sub refname {
>> +        my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
>> +
>> +        # It cannot end with a slash /, we'll throw up on this because
>> +        # SVN can't have directories with a slash in their name, either:
>> +        if ($refname =~ m{/$}) {
>> +                die "ref: '$refname' ends with a trailing slash, this is ",
>> +                    "not permitted by git nor Subversion\n";
>> +        }
>> +
>> +        # It cannot have ASCII control character space, tilde ~, caret ^,
>> +        # colon :, question-mark ?, asterisk *, space, or open bracket [
>> +        # anywhere.
>> +        #
>> +        # Additionally, % must be escaped because it is used for escaping
>> +        # and we want our escaped refname to be reversible
>> +        $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
> 
> uc of sprintf()?  You meant "%%%02X"?

You are right. Being a total Perl noob I just took Eric's suggestion from an
earlier post without really understanding everything.

> Other than that, looks sane to me.  I presume that SVN branches
> whose name would be mangled with this patch would not have been
> successfully imported with older git-svn anyway, so this won't
> introduce any regressions?

Now that you mention it, I am not entirely sure. We introduce the % which is
mangled as well. It wasn't mangled before.

I now could think of a case that someone has a git-svn branch with a % in the
name checked out.

When updates are fetched a new branch head would be created. It wouldn't 
destroy anything, but a script might break. On the other hand, the script needs
to be updated anyway. So I am not sure if % should be handled separately.

> Eric?
Yes, Eric, please comment.

-- 
Robert Ewald

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

* Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname
  2007-07-30 10:07 ` Junio C Hamano
  2007-07-30 13:33   ` Robert Ewald
@ 2007-07-30 19:29   ` Eric Wong
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Wong @ 2007-07-30 19:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Robert Ewald, git

Junio C Hamano <gitster@pobox.com> wrote:
> Robert Ewald <robert.ewald@nov.com> writes:
> 
> > +sub refname {
> > +        my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
> > +
> > +        # It cannot end with a slash /, we'll throw up on this because
> > +        # SVN can't have directories with a slash in their name, either:
> > +        if ($refname =~ m{/$}) {
> > +                die "ref: '$refname' ends with a trailing slash, this is ",
> > +                    "not permitted by git nor Subversion\n";
> > +        }
> > +
> > +        # It cannot have ASCII control character space, tilde ~, caret ^,
> > +        # colon :, question-mark ?, asterisk *, space, or open bracket [
> > +        # anywhere.
> > +        #
> > +        # Additionally, % must be escaped because it is used for escaping
> > +        # and we want our escaped refname to be reversible
> > +        $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
> 
> uc of sprintf()?  You meant "%%%02X"?

Ah, I wasn't sure if X was portable enough, but then again this sprintf
is in Perl.

> Other than that, looks sane to me.  I presume that SVN branches
> whose name would be mangled with this patch would not have been
> successfully imported with older git-svn anyway, so this won't
> introduce any regressions?

Seems alright to me, I haven't had a chance to look at it too hard.  I'm
out of town and haven't been following the mailing list lately.

Acked-by: Eric Wong <normalperson@yhbt.net>

-- 
Eric Wong

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

* Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname
  2007-07-30  9:08 (Resend)[PATCH] git-svn: Translate invalid characters in refname Robert Ewald
  2007-07-30 10:07 ` Junio C Hamano
@ 2007-07-31  0:20 ` Junio C Hamano
  2007-08-15 22:53 ` martin f krafft
  2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2007-07-31  0:20 UTC (permalink / raw)
  To: Robert Ewald; +Cc: git

This patch is totally whitespace mangled, but I'll apply by hand
for now.

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

* Re: (Resend)[PATCH] git-svn: Translate invalid characters in refname
  2007-07-30  9:08 (Resend)[PATCH] git-svn: Translate invalid characters in refname Robert Ewald
  2007-07-30 10:07 ` Junio C Hamano
  2007-07-31  0:20 ` Junio C Hamano
@ 2007-08-15 22:53 ` martin f krafft
  2 siblings, 0 replies; 6+ messages in thread
From: martin f krafft @ 2007-08-15 22:53 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 857 bytes --]

also sprach Robert Ewald <robert.ewald@nov.com> [2007.07.30.1108 +0200]:
> In git some characters are invalid as documented
> in git-check-ref-format. In subversion these characters might
> be valid, so a translation is required.
> 
> This patch does this translation by url escaping characters, that
> are not allowed.

Have you worked more on this? I am back now and could test it on
various svn imports. Just want to make sure I have the latest
version.

-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
 
"we should have a volleyballocracy.
 we elect a six-pack of presidents.
 each one serves until they screw up,
 at which point they rotate."
                                                      -- dennis miller
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital signature (see http://martin-krafft.net/gpg/) --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2007-08-15 22:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-30  9:08 (Resend)[PATCH] git-svn: Translate invalid characters in refname Robert Ewald
2007-07-30 10:07 ` Junio C Hamano
2007-07-30 13:33   ` Robert Ewald
2007-07-30 19:29   ` Eric Wong
2007-07-31  0:20 ` Junio C Hamano
2007-08-15 22:53 ` martin f krafft

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).