threads / discuss / 26856

Re: [msysGit] Trailing spaces in branchname (git-svn)

Subject: Re: [msysGit] Trailing spaces in branchname (git-svn)

## tl;dr

5 messages between Mar 24, 2011 and Jun 21, 2011.

replies: 4people: 2as markdown or json

Erik Faye-Lund· Mar 24, 2011, 21:26 UTC · lore
On Thu, Mar 24, 2011 at 9:16 PM, Barthus <magnus.kallstrom@gmail.com> wrote:
Show 29 quoted lines
> I am trying to clone a subversion repository that has a branchname
> with a trailing space. Since I can't find a solution I downloaded the
> code to try to understand the problem. Since I am not familiar with
> perl it is a bit hard for me. This is what I have found out so far:
>
> In git-svn.perl:
> tmp_index_do is called and tries to create the folder with the
> trailing space (under svn/refs/remotes) with the following line of
> code:
> mkpath([$dir]) unless -d $dir;
> reading the solution above, I figured that I should be able to
> "sanitize" the path -reusing som code already existing in the script:
>        sub refname
> I then tried to:
> git svn fetch
>
> Now the folder gets created, but then some lockfile is supposed to be
> created (with the trailing space in the path), and it fails again.
>
> I have not been able to locate the call that tries to create the
> lockfile (yet), and I guess there will be more fileoperations made to
> the folder. If I manage to figure out the code my theory now is to
> "sanitize" the branchname in the structure where it is contained when
> it comes from subversion (possibly adding a "sanitized" storage to not
> destroy the original name if it is needed), and see if the clone/fetch
> can continue.
>
> My hope is though, that someone who understands this maybe can fix it,
> or maybe point me in the right direction.

This kind of question is usually better to ask on the main Git mailing list, as it's not really Windows specific.

Erik Faye-Lund· Jun 15, 2011, 14:00 UTC · lore

Re: Trailing spaces in branchname (git-svn)

Please don't cull the CC-list.
On Wed, Jun 15, 2011 at 3:38 PM, Barthus <magnus.kallstrom@gmail.com> wrote:
Show 11 quoted lines
>
>> This kind of question is usually better to ask on the main Git mailing
>> list, as it's not really Windows specific.
>
> I found a similar (older) thread in the git-mailing-list, discussing
> the same issue. This led me to try cloning the same repository on a
> Linux-machine - with success. Linux (at least my distro - Ubuntu)
> handles trailing spaces in directory names.
>
> Isn't this a msysgit-issue? (I just want to make sure that I don't
> spend my (and your) time in the wrong place)
If it works on Linux then yes, it's probably a Git for Windows issue.

Some quick testing reveals that paths can have a trailing space on Linux, but not on Windows. It sounds to me like you need to modify the refname subroutine in git-svn.perl to escape this. Something like this seems to work for me: ---8<---

diff --git a/git-svn.perl b/git-svn.perl
index 7849cfc..7a44145 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2126,6 +2126,9 @@ sub refname {
 	# @{ becomes %40{
 	$refname =~ s{\@\{}{%40\{}g;

+	# trailing space is not not allowed on Windows
+	$refname =~ s{ $}{%20};
+
 	return $refname;
 }


---8<---
If it works for you, I'll submit a proper patch for it.
Erik Faye-Lund· Jun 15, 2011, 14:38 UTC · lore

Re: [msysGit] Re: Trailing spaces in branchname (git-svn)

Again, please don't cull the CC-list. When replying, hit "reply all" in your e-mail client.

Also, please don't top-post either. It makes it harder for others to follow the discussion. I've corrected the quoting this time.

On Wed, Jun 15, 2011 at 4:12 PM, Barthus <magnus.kallstrom@gmail.com> wrote:
Show 43 quoted lines
> On 15 Juni, 16:00, Erik Faye-Lund <kusmab...@gmail.com> wrote:
>> Please don't cull the CC-list.
>>
>> On Wed, Jun 15, 2011 at 3:38 PM, Barthus <magnus.kallst...@gmail.com> wrote:
>>
>> >> This kind of question is usually better to ask on the main Git mailing
>> >> list, as it's not really Windows specific.
>>
>> > I found a similar (older) thread in the git-mailing-list, discussing
>> > the same issue. This led me to try cloning the same repository on a
>> > Linux-machine - with success. Linux (at least my distro - Ubuntu)
>> > handles trailing spaces in directory names.
>>
>> > Isn't this a msysgit-issue? (I just want to make sure that I don't
>> > spend my (and your) time in the wrong place)
>>
>> If it works on Linux then yes, it's probably a Git for Windows issue.
>>
>> Some quick testing reveals that paths can have a trailing space on
>> Linux, but not on Windows. It sounds to me like you need to modify the
>> refname subroutine in git-svn.perl to escape this. Something like this
>> seems to work for me:
>> ---8<---
>> diff --git a/git-svn.perl b/git-svn.perl
>> index 7849cfc..7a44145 100755
>> --- a/git-svn.perl
>> +++ b/git-svn.perl
>> @@ -2126,6 +2126,9 @@ sub refname {
>>         # @{ becomes %40{
>>         $refname =~ s{\@\{}{%40\{}g;
>>
>> +       # trailing space is not not allowed on Windows
>> +       $refname =~ s{ $}{%20};
>> +
>>         return $refname;
>>  }
>>
>> ---8<---
>> If it works for you, I'll submit a proper patch for it.
>
> Ok, thanks. I'll try as soon as possible (will be away for a few
> days...)
>

You might want to try this patch instead, as it deals with refnames like "foo /bar" and "foo \bar" also:

diff --git a/git-svn.perl b/git-svn.perl
index 7849cfc..54894e4 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2126,6 +2126,9 @@ sub refname {
 	# @{ becomes %40{
 	$refname =~ s{\@\{}{%40\{}g;

+	# trailing space is not not allowed on Windows
+	$refname =~ s{ (?=/|\\|$)}{%20}g;
+
 	return $refname;
 }
Magnus Kallström· Jun 15, 2011, 21:13 UTC · re: Erik Faye-Lund · lore

Re: Re: Trailing spaces in branchname (git-svn)

(I hope I get it right now - previously I used Googles web-interface, and I just couldn't find a way to respond to all. Trying from my email client instead now... I have even read the 'Welcome post' again :) )
Unfortunately, the patch didn't work.

This is the error I get when it aborts: Found branch parent: (refs/remotes/CR3533 sökning pÃ¥ fakturabelopp ) be4dd98d152d82f098b90089f4df6a2d411d84e1 fatal: Unable to create 'd:/Dev/GIT/svk/KOB/.git/svn/refs/remotes/CR3533 sökning på fakturabelopp /index.lock': No such file or directory read-tree be4dd98d152d82f098b90089f4df6a2d411d84e1: command returned error: 128

The patch itself is probably working for other parts, and I even tried a similar patch back in March. I never managed to figure out where the call to the locking-function got it's path though. 
Magnus Kallström· Jun 21, 2011, 22:16 UTC · re: Magnus Kallström · lore

Re: Re: Trailing spaces in branchname (git-svn)

2011/6/15 Magnus Kallström <magnus.kallstrom@gmail.com>
Show 18 quoted lines
> (I hope I get it right now - previously I used Googles web-interface, and I
> just couldn't find a way to respond to all. Trying from my email client
> instead now... I have even read the 'Welcome post' again :) )
>
> Unfortunately, the patch didn't work.
>
> This is the error I get when it aborts:
> Found branch parent: (refs/remotes/CR3533 sökning på fakturabelopp )
> be4dd98d152d82f098b90089f4df6a2d411d84e1
> fatal: Unable to create 'd:/Dev/GIT/svk/KOB/.git/svn/refs/remotes/CR3533
> sökning på fakturabelopp /index.lock': No such file or directory
> read-tree be4dd98d152d82f098b90089f4df6a2d411d84e1: command returned error:
> 128
>
> The patch itself is probably working for other parts, and I even tried a
> similar patch back in March. I never managed to figure out where the call to
> the locking-function got it's path though.
>
Hi again!

I have now successfully cloned "my" repository with the following changes in git-svn.perl. I'm not sure if the change in "sub refname" is needed, but I will try to reproduce the error when I find the time for it (the full clone fails after 2-3 days).

I can't tell if it breaks anything else, but as far as I can tell, the clone is working.

Does it look as if the modification is done in the right place?
/Magnus
---8<---
diff --git a/git-svn.perl b/git-svn.perl
index 7849cfc..c5e2d23 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2126,6 +2126,9 @@ sub refname {
     # @{ becomes %40{
     $refname =~ s{\@\{}{%40\{}g;

+    # trailing space is not not allowed on Windows
+    $refname =~ s{ (?=/|\\|$)}{%20}g;
+
     return $refname;
 }

@@ -3883,6 +3886,7 @@ sub _new {
     }

     $_[3] = $path = '' unless (defined $path);
+    $dir =~ s{ (?=/|\\|$)}{%20}g;
     mkpath([$dir]);
     bless {
         ref_id => $ref_id, dir => $dir, index => "$dir/index",
---8<---

← back to recent threads