# Re: git-svn: Fails to drop leading path from empty dir name

4 messages from 2009-11-22 to 2009-11-23. Participants: Eric Wong, Björn Steinbrink.
Thread: https://gitlist.dev/t/21717

## Björn Steinbrink, 2009-11-22 13:46

Subject: git-svn: Fails to drop leading path from empty dir name
Message-ID: <20091122134638.GA12233@atjola.homenet>
URL: https://gitlist.dev/e/20091122134638.GA12233%40atjola.homenet

```
Hi Eric,

the stuff to create empty directories fails to strip leading path
components, e.g. when using
"git svn clone -s svn://whatever/project/trunk".

Instead of creating the empty directory "foo" in the repo root, it
creates "project/trunk/foo".

Ad hoc patch for the test case below.

Björn

diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh
index 5948544..9e22089 100755
--- a/t/t9146-git-svn-empty-dirs.sh
+++ b/t/t9146-git-svn-empty-dirs.sh
@@ -82,4 +82,27 @@ test_expect_success 'git svn mkdirs -r works' '
 	)
 '
 
+test_expect_success 'initialize trunk' '
+	for i in trunk trunk/a trunk/"weird file name"
+	do
+		svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+	done
+'
+
+test_expect_success 'clone trunk' 'git svn clone -s "$svnrepo" trunk'
+
+test_expect_success 'empty directories in trunk exist' '
+	(
+		cd cloned &&
+		for i in trunk/a trunk/"weird file name"
+		do
+			if ! test -d "$i"
+			then
+				echo >&2 "$i does not exist"
+				exit 1
+			fi
+		done
+	)
+'
+
 test_done

```

## Eric Wong, 2009-11-22 23:25

Subject: Re: git-svn: Fails to drop leading path from empty dir name
Message-ID: <20091122232504.GA28127@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20091122232504.GA28127%40dcvr.yhbt.net
In-Reply-To: <20091122134638.GA12233@atjola.homenet>

```
Björn Steinbrink <B.Steinbrink@gmx.de> wrote:
> Hi Eric,
> 
> the stuff to create empty directories fails to strip leading path
> components, e.g. when using
> "git svn clone -s svn://whatever/project/trunk".
> 
> Instead of creating the empty directory "foo" in the repo root, it
> creates "project/trunk/foo".
> 
> Ad hoc patch for the test case below.
> 
> Björn
> 
> diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh
> index 5948544..9e22089 100755
> --- a/t/t9146-git-svn-empty-dirs.sh
> +++ b/t/t9146-git-svn-empty-dirs.sh
> @@ -82,4 +82,27 @@ test_expect_success 'git svn mkdirs -r works' '
>  	)
>  '
>  
> +test_expect_success 'initialize trunk' '
> +	for i in trunk trunk/a trunk/"weird file name"
> +	do
> +		svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
> +	done
> +'
> +

Hi Björn,

I'm having a bit of trouble figuring out exactly what you mean
here, can you double check your tests?  Annotations below, thanks

> +test_expect_success 'clone trunk' 'git svn clone -s "$svnrepo" trunk'
                                                    ^^            ^^^^^
                                                           Huh?

> +test_expect_success 'empty directories in trunk exist' '
> +	(
> +		cd cloned &&
                   ^^^^^^ - ?

> +		for i in trunk/a trunk/"weird file name"
> +		do
> +			if ! test -d "$i"
> +			then
> +				echo >&2 "$i does not exist"
> +				exit 1
> +			fi
> +		done

-- 
Eric Wong

```

## Björn Steinbrink, 2009-11-22 23:52

Subject: Re: git-svn: Fails to drop leading path from empty dir name
Message-ID: <20091122235248.GA17418@atjola.homenet>
URL: https://gitlist.dev/e/20091122235248.GA17418%40atjola.homenet
In-Reply-To: <20091122232504.GA28127@dcvr.yhbt.net>

```
Hi Eric,

On 2009.11.22 15:25:04 -0800, Eric Wong wrote:
> Björn Steinbrink <B.Steinbrink@gmx.de> wrote:

> I'm having a bit of trouble figuring out exactly what you mean
> here, can you double check your tests?  Annotations below, thanks
> 
> > +test_expect_success 'clone trunk' 'git svn clone -s "$svnrepo" trunk'
>                                                     ^^            ^^^^^
>                                                            Huh?
> 
> > +test_expect_success 'empty directories in trunk exist' '
> > +	(
> > +		cd cloned &&
>                    ^^^^^^ - ?
> 
> > +		for i in trunk/a trunk/"weird file name"

Argh, yeah, I messed that patch up, the test only failed because I also
messed up this line, adding the trunk prefix there, too. Fixed patch
below.

SVN Repo layout:

/
|
|---trunk
|   |
... |---foo/ # Empty
    |
    |---bar/
        |
        somefile

with "git svn clone -s svn://host/path/to/repo you get:

.git
bar/
bar/somefile
trunk/foo # This should be just foo/

i.e. the empty directories have their path relative to the repo root,
instead of relative to the directory the git branch is associated with.

Sorry for the messed up first patch.

Björn

diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh
index 5948544..70c52c1 100755
--- a/t/t9146-git-svn-empty-dirs.sh
+++ b/t/t9146-git-svn-empty-dirs.sh
@@ -82,4 +82,27 @@ test_expect_success 'git svn mkdirs -r works' '
 	)
 '
 
+test_expect_success 'initialize trunk' '
+	for i in trunk trunk/a trunk/"weird file name"
+	do
+		svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+	done
+'
+
+test_expect_success 'clone trunk' 'git svn clone -s "$svnrepo" trunk'
+
+test_expect_success 'empty directories in trunk exist' '
+	(
+		cd trunk &&
+		for i in a "weird file name"
+		do
+			if ! test -d "$i"
+			then
+				echo >&2 "$i does not exist"
+				exit 1
+			fi
+		done
+	)
+'
+
 test_done

```

## Eric Wong, 2009-11-23 02:21

Subject: [PATCH] git svn: strip leading path when making empty dirs
Message-ID: <20091123022136.GA1055@dcvr.yhbt.net>
URL: https://gitlist.dev/e/20091123022136.GA1055%40dcvr.yhbt.net
In-Reply-To: <20091122235248.GA17418@atjola.homenet>

```
Björn Steinbrink <B.Steinbrink@gmx.de> wrote:
> Argh, yeah, I messed that patch up, the test only failed because I also
> messed up this line, adding the trunk prefix there, too. Fixed patch
> below.
> 
> SVN Repo layout:
> 
> /
> |
> |---trunk
> |   |
> ... |---foo/ # Empty
>     |
>     |---bar/
>         |
>         somefile
> 
> with "git svn clone -s svn://host/path/to/repo you get:
> 
> .git
> bar/
> bar/somefile
> trunk/foo # This should be just foo/
> 
> i.e. the empty directories have their path relative to the repo root,
> instead of relative to the directory the git branch is associated with.
> 
> Sorry for the messed up first patch.

No worries, thanks for the bug report and test case.  My brain's been
completely fried lately so I was completely confused :x
Anyways this should fix it:

     Also pushed out to git://git.bogomips.org/git-svn:
	Eric Wong (2):
	      git svn: always reuse existing remotes on fetch
	      git svn: strip leading path when making empty dirs

From 9be30eed61993a6f2d04a1609723e64e7632a64e Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Sun, 22 Nov 2009 18:11:32 -0800
Subject: [PATCH] git svn: strip leading path when making empty dirs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since unhandled.log stores paths relative to the repository
root, we need to strip out leading path components if the
directories we're tracking are not the repository root.

Reported-by: Björn Steinbrink
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 git-svn.perl                  |    3 +++
 t/t9146-git-svn-empty-dirs.sh |   23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 7f7a56f..957d44e 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -2752,8 +2752,11 @@ sub mkemptydirs {
 		}
 	}
 	close $fh;
+
+	my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
 	foreach my $d (sort keys %empty_dirs) {
 		$d = uri_decode($d);
+		$d =~ s/$strip//;
 		next if -d $d;
 		if (-e _) {
 			warn "$d exists but is not a directory\n";
diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh
index 5948544..70c52c1 100755
--- a/t/t9146-git-svn-empty-dirs.sh
+++ b/t/t9146-git-svn-empty-dirs.sh
@@ -82,4 +82,27 @@ test_expect_success 'git svn mkdirs -r works' '
 	)
 '
 
+test_expect_success 'initialize trunk' '
+	for i in trunk trunk/a trunk/"weird file name"
+	do
+		svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+	done
+'
+
+test_expect_success 'clone trunk' 'git svn clone -s "$svnrepo" trunk'
+
+test_expect_success 'empty directories in trunk exist' '
+	(
+		cd trunk &&
+		for i in a "weird file name"
+		do
+			if ! test -d "$i"
+			then
+				echo >&2 "$i does not exist"
+				exit 1
+			fi
+		done
+	)
+'
+
 test_done
-- 
Eric Wong

```
