# [PATCH] git-svn: mangle refnames forbidden in git

9 messages from 2010-05-06 to 2010-07-08. Participants: Torsten Schmutzler, Eric Wong, Jonathan Nieder, Michael J Gruber, A Large Angry SCM.
Thread: https://gitlist.dev/t/23720

## Torsten Schmutzler, 2010-05-06 20:20

Subject: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <4BE3249B.7050100@theblacksun.eu>
URL: https://gitlist.dev/e/4BE3249B.7050100%40theblacksun.eu

```
git-check-ref-format(1) describes names which
cannot be used as refnames for git.  Some are
legal branchnames in subversion however.
Mangle the not yet handled cases.

Signed-off-by: Torsten Schmutzler <git-ts@theblacksun.eu>
---
 git-svn.perl                          |    8 ++++++++
 t/t9118-git-svn-funky-branch-names.sh |   21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 2c86ea2..57df509 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2086,6 +2086,14 @@ sub refname {
 	# .. becomes %2E%2E
 	$refname =~ s{\.\.}{%2E%2E}g;
 
+	# trailing dots and .lock are not allowed
+	# .$ becomes %2E and .lock becomes %2Elock
+	$refname =~ s{\.(?=$|lock$)}{%2E};
+
+	# the sequence @{ is used to access the reflog
+	# @{ becomes %40{
+	$refname =~ s{\@\{}{%40\{}g;
+
 	return $refname;
 }
 
diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh
index ac52bff..7d7acc3 100755
--- a/t/t9118-git-svn-funky-branch-names.sh
+++ b/t/t9118-git-svn-funky-branch-names.sh
@@ -21,6 +21,14 @@ test_expect_success 'setup svnrepo' '
 	                      "$svnrepo/pr ject/branches/more fun plugin!" &&
 	svn_cmd cp -m "scary" "$svnrepo/pr ject/branches/fun plugin" \
 	              "$svnrepo/pr ject/branches/$scary_uri" &&
+	svn_cmd cp -m "leading dot" "$svnrepo/pr ject/trunk" \
+			"$svnrepo/pr ject/branches/.leading_dot" &&
+	svn_cmd cp -m "trailing dot" "$svnrepo/pr ject/trunk" \
+			"$svnrepo/pr ject/branches/trailing_dot." &&
+	svn_cmd cp -m "trailing .lock" "$svnrepo/pr ject/trunk" \
+			"$svnrepo/pr ject/branches/trailing_dotlock.lock" &&
+	svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
+			"$svnrepo/pr ject/branches/not-a@{0}reflog" &&
 	start_httpd
 	'
 
@@ -30,6 +38,10 @@ test_expect_success 'test clone with funky branch names' '
 		git rev-parse "refs/remotes/fun%20plugin" &&
 		git rev-parse "refs/remotes/more%20fun%20plugin!" &&
 		git rev-parse "refs/remotes/$scary_ref" &&
+		git rev-parse "refs/remotes/%2Eleading_dot" &&
+		git rev-parse "refs/remotes/trailing_dot%2E" &&
+		git rev-parse "refs/remotes/trailing_dotlock%2Elock" &&
+		git rev-parse "refs/remotes/not-a%40{0}reflog" &&
 	cd ..
 	'
 
@@ -51,6 +63,15 @@ test_expect_success 'test dcommit to scary branch' '
 	cd ..
 	'
 
+test_expect_success 'test dcommit to trailing_dotlock branch' '
+	cd project &&
+	git reset --hard "refs/remotes/trailing_dotlock%2Elock" &&
+	echo who names branches like this anyway? >> foo &&
+	git commit -m "bar" -- foo &&
+	git svn dcommit &&
+	cd ..
+	'
+
 stop_httpd
 
 test_done
-- 
1.7.1.12.ge45de

```

## Eric Wong, 2010-05-09 08:35

Subject: Re: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <20100509083500.GB12627@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20100509083500.GB12627%40dcvr.yhbt.net
In-Reply-To: <4BE3249B.7050100@theblacksun.eu>

```
Torsten Schmutzler <git-ts@theblacksun.eu> wrote:
> git-check-ref-format(1) describes names which
> cannot be used as refnames for git.  Some are
> legal branchnames in subversion however.
> Mangle the not yet handled cases.
> 
> Signed-off-by: Torsten Schmutzler <git-ts@theblacksun.eu>

Thanks,

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

...and pushed out to git://git.bogomips.org/git-svn

-- 
Eric Wong

```

## Jonathan Nieder, 2010-07-08 08:43

Subject: Re: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <20100708084356.GA29856@burratino>
URL: https://gitlist.dev/e/20100708084356.GA29856%40burratino
In-Reply-To: <4BE3249B.7050100@theblacksun.eu>

```
t9118-git-svn-funky-branch-names.sh fails for me:

 [...]
 3402a8497588142722deb77f6e4f42b6caaabc85
 refs/remotes/not-a%40{0}reflog
 fatal: ambiguous argument 'refs/remotes/not-a%40{0}reflog': unknown revision or path not in the working tree.
 Use '--' to separate paths from revisions
 not ok - 2 test clone with funky branch names

More precisely, the failure occurs in the

 	svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
			"$svnrepo/pr ject/branches/not-a@{0}reflog" &&

line in that test: I think svn is handling the @ itself here.

 $ svnadmin create /tmp/foo
 $ svn checkout file:///tmp/foo wc
 Checked out revision 0.
 $ echo hello >wc/source
 $ (cd wc && svn add source)
 A         source
 $ (cd wc && svn commit -m one)
 Adding         source
 Transmitting file data .
 Committed revision 1.
 $ svn cp -m reflog file:///tmp/foo/source 'file:///tmp/foo/not-a@{0}reflog'
 Committed revision 2.
 $ (cd wc && svn update)
 A    not-a
 Updated to revision 2.

 $ svn --version
 svn, version 1.6.12 (r955767)
    compiled Jun 21 2010, 20:24:54
 [...]

Ideas?

```

## Eric Wong, 2010-07-08 08:58

Subject: Re: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <20100708085814.GC10779@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20100708085814.GC10779%40dcvr.yhbt.net
In-Reply-To: <20100708084356.GA29856@burratino>

```
Jonathan Nieder <jrnieder@gmail.com> wrote:
> t9118-git-svn-funky-branch-names.sh fails for me:
> 
>  [...]
>  3402a8497588142722deb77f6e4f42b6caaabc85
>  refs/remotes/not-a%40{0}reflog
>  fatal: ambiguous argument 'refs/remotes/not-a%40{0}reflog': unknown revision or path not in the working tree.
>  Use '--' to separate paths from revisions
>  not ok - 2 test clone with funky branch names
> 
> More precisely, the failure occurs in the
> 
>  	svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
> 			"$svnrepo/pr ject/branches/not-a@{0}reflog" &&
> 
> line in that test: I think svn is handling the @ itself here.
<snip>
>  $ svn --version
>  svn, version 1.6.12 (r955767)
>     compiled Jun 21 2010, 20:24:54
>  [...]
> 
> Ideas?

I can't reproduce it with 1.5.1 here, does URI-escaping the "@{0}"
to "%40%7B0%7D" work?

-- 
Eric Wong

```

## Jonathan Nieder, 2010-07-08 13:03

Subject: Re: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <20100708130315.GA1529@burratino>
URL: https://gitlist.dev/e/20100708130315.GA1529%40burratino
In-Reply-To: <20100708085814.GC10779@dcvr.yhbt.net>

```
Eric Wong wrote:

> I can't reproduce it with 1.5.1 here, does URI-escaping the "@{0}"
> to "%40%7B0%7D" work?

Yes.

 ...
 $ svn cp -m reflog file:///tmp/foo/source 'file:///tmp/foo/not-a%40%7B0%7Dreflog'
 Committed revision 2.
 $ (cd wc && svn update)
 A    not-a@{0}reflog
 Updated to revision 2.

Does that work with svn 1.5.x?

```

## Michael J Gruber, 2010-07-08 18:53

Subject: Re: [PATCH] git-svn: mangle refnames forbidden in git
Message-ID: <4C361EB5.7010704@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4C361EB5.7010704%40drmicha.warpmail.net
In-Reply-To: <20100708130315.GA1529@burratino>

```
Jonathan Nieder venit, vidit, dixit 08.07.2010 15:03:
> Eric Wong wrote:
> 
>> I can't reproduce it with 1.5.1 here, does URI-escaping the "@{0}"
>> to "%40%7B0%7D" work?
> 
> Yes.
> 
>  ...
>  $ svn cp -m reflog file:///tmp/foo/source 'file:///tmp/foo/not-a%40%7B0%7Dreflog'
>  Committed revision 2.
>  $ (cd wc && svn update)
>  A    not-a@{0}reflog
>  Updated to revision 2.
> 
> Does that work with svn 1.5.x?

It turns out this is not so much about general escaping but about the
treatment of so called svn PEG revisions (not so unsimilar to our @{}).

svn r954995 integrated r952973 (which implemented the eating of PEG
revisions) into the 1.6.x branch. It's considered a bug fix.

This "fix" is in 1.6.12 but not in 1.6.11.

Now, git-svn adjusts its behaviour to the svn version for things like
info. But I don't know if it's worth doing in this case - maybe we
should just change the test not to use the PEG revisions identifier "@".

Michael

```

## Michael J Gruber, 2010-07-08 19:16

Subject: [PATCH] t9118: avoid PEG revision identifier in tests
Message-ID: <2f9f1bd8efb818456fcc386f419fc17f4e435e19.1278616418.git.git@drmicha.warpmail.net>
URL: https://gitlist.dev/e/2f9f1bd8efb818456fcc386f419fc17f4e435e19.1278616418.git.git%40drmicha.warpmail.net
In-Reply-To: <4C361EB5.7010704@drmicha.warpmail.net>

```
@ is SVN's identifier for PEG revisions. But SVN's treatment of PEG
identifiers in copy target URLs changed in r954995/r952973, i.e. between
1.6.11 and 1.6.12. They get eaten now (which is considered the right
way).

Therefore, avoid the @ in the tests with funky branch names.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
This version is tested with svn 1.6.9 and 1.6.12.

 t/t9118-git-svn-funky-branch-names.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh
index 7d7acc3..45d5b2d 100755
--- a/t/t9118-git-svn-funky-branch-names.sh
+++ b/t/t9118-git-svn-funky-branch-names.sh
@@ -28,7 +28,7 @@ test_expect_success 'setup svnrepo' '
 	svn_cmd cp -m "trailing .lock" "$svnrepo/pr ject/trunk" \
 			"$svnrepo/pr ject/branches/trailing_dotlock.lock" &&
 	svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
-			"$svnrepo/pr ject/branches/not-a@{0}reflog" &&
+			"$svnrepo/pr ject/branches/not-a%40{0}reflog" &&
 	start_httpd
 	'
 
-- 
1.7.2.rc1.212.g850a

```

## A Large Angry SCM, 2010-07-08 19:33

Subject: Re: [PATCH] t9118: avoid PEG revision identifier in tests
Message-ID: <4C362807.80703@gmail.com>
URL: https://gitlist.dev/e/4C362807.80703%40gmail.com
In-Reply-To: <2f9f1bd8efb818456fcc386f419fc17f4e435e19.1278616418.git.git@drmicha.warpmail.net>

```
On 07/08/2010 03:16 PM, Michael J Gruber wrote:
> @ is SVN's identifier for PEG revisions. But SVN's treatment of PEG
> identifiers in copy target URLs changed in r954995/r952973, i.e. between
> 1.6.11 and 1.6.12. They get eaten now (which is considered the right
> way).
>
> Therefore, avoid the @ in the tests with funky branch names.
>
> Signed-off-by: Michael J Gruber<git@drmicha.warpmail.net>
> ---
> This version is tested with svn 1.6.9 and 1.6.12.
>
>   t/t9118-git-svn-funky-branch-names.sh |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh
> index 7d7acc3..45d5b2d 100755
> --- a/t/t9118-git-svn-funky-branch-names.sh
> +++ b/t/t9118-git-svn-funky-branch-names.sh
> @@ -28,7 +28,7 @@ test_expect_success 'setup svnrepo' '
>   	svn_cmd cp -m "trailing .lock" "$svnrepo/pr ject/trunk" \
>   			"$svnrepo/pr ject/branches/trailing_dotlock.lock"&&
>   	svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \
> -			"$svnrepo/pr ject/branches/not-a@{0}reflog"&&
> +			"$svnrepo/pr ject/branches/not-a%40{0}reflog"&&
>   	start_httpd
>   	'
>

With this patch, 'make test' now passes, and make -j4 test' does also.

```

## Eric Wong, 2010-07-08 20:38

Subject: Re: [PATCH] t9118: avoid PEG revision identifier in tests
Message-ID: <20100708203809.GA2991@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20100708203809.GA2991%40dcvr.yhbt.net
In-Reply-To: <2f9f1bd8efb818456fcc386f419fc17f4e435e19.1278616418.git.git@drmicha.warpmail.net>

```
Michael J Gruber <git@drmicha.warpmail.net> wrote:
> @ is SVN's identifier for PEG revisions. But SVN's treatment of PEG
> identifiers in copy target URLs changed in r954995/r952973, i.e. between
> 1.6.11 and 1.6.12. They get eaten now (which is considered the right
> way).
> 
> Therefore, avoid the @ in the tests with funky branch names.
> 
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
> This version is tested with svn 1.6.9 and 1.6.12.

Thanks Michael, also tested with svn 1.5.1.
Acked and pushed up to git://git.bogomips.org/git-svn

-- 
Eric Wong

```
