git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-svn: doublecheck if really file or dir

From
EWEric Wong <normalperson@yhbt.net>
Date
Aug 3, 2014, 02:45 UTC
Message-ID
<20140803024520.GA12880@dcvr.yhbt.net>
In-Reply-To
<53D46812.3020706@gmail.com>
Andrej Manduch <amanduch@gmail.com> wrote:
Show 6 quoted lines
> On 07/24/2014 12:04 AM, Eric Wong wrote:
> > Andrej Manduch <amanduch@gmail.com> wrote:
> >> * this fixes 'git svn info `pwd`' buggy behaviour
> > 
> > While your patch avoids an error, but the output isn't right, either.
> > I tried it running in /home/ew/ruby, the URL field is bogus:
> Thx, I missed this. However this bug was not introduced with my patch,
> it was there before. If you try use `git svn info full_path` and
> directory is not a root dir this bug will occour even wihout my patch.

Hi Andrej, I could not help thinking your patch was obscuring another bug. I think I have an alternative to your patch which fixes both our bugs. Can you give this a shot? Thanks.

--------------------------- 8< ----------------------------
Subject: [PATCH] git svn: info: correctly handle absolute path args
Calling "git svn info $(pwd)" would hit:
  "Reading from filehandle failed at ..."
errors due to improper prefixing and canonicalization.

Strip the toplevel path from absolute filesystem paths to ensure downstream canonicalization routines are only exposed to paths tracked in git (or SVN).

Noticed-by: Andrej Manduch <amanduch@gmail.com>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 git-svn.perl            | 21 +++++++++++++++------
 t/t9119-git-svn-info.sh | 10 ++++++++++
 2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 1f41ee1..1f9582b 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1477,10 +1477,19 @@ sub cmd_commit_diff {
 	}
 }
 
-
 sub cmd_info {
-	my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
-	my $fullpath = canonicalize_path($cmd_dir_prefix . $path);
+	my $path_arg = defined($_[0]) ? $_[0] : '.';
+	my $path = $path_arg;
+	if ($path =~ m!\A/!) {
+		my $toplevel = eval {
+			my @cmd = qw/rev-parse --show-toplevel/;
+			command_oneline(\@cmd, STDERR => 0);
+		};
+		$path =~ s!\A\Q$toplevel\E/?!!;
+		$path = canonicalize_path($path);
+	} else {
+		$path = canonicalize_path($cmd_dir_prefix . $path);
+	}
 	if (exists $_[1]) {
 		die "Too many arguments specified\n";
 	}
@@ -1501,14 +1510,14 @@ sub cmd_info {
 	# canonicalize_path() will return "" to make libsvn 1.5.x happy,
 	$path = "." if $path eq "";
 
-	my $full_url = canonicalize_url( add_path_to_url( $url, $fullpath ) );
+	my $full_url = canonicalize_url( add_path_to_url( $url, $path ) );
 
 	if ($_url) {
 		print "$full_url\n";
 		return;
 	}
 
-	my $result = "Path: $path\n";
+	my $result = "Path: $path_arg\n";
 	$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
 	$result .= "URL: $full_url\n";
 
@@ -1539,7 +1548,7 @@ sub cmd_info {
 	}
 
 	my ($lc_author, $lc_rev, $lc_date_utc);
-	my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $fullpath);
+	my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $path);
 	my $log = command_output_pipe(@args);
 	my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
 	while (<$log>) {
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index ff19695..4f6e669 100755
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -74,6 +74,16 @@ test_expect_success 'info .' "
 	test_cmp_info expected.info-dot actual.info-dot
 	"
 
+test_expect_success 'info $(pwd)' '
+	(cd svnwc; svn info "$(pwd)") >expected.info-pwd &&
+	(cd gitwc; git svn info "$(pwd)") >actual.info-pwd &&
+	grep -v ^Path: <expected.info-pwd >expected.info-np &&
+	grep -v ^Path: <actual.info-pwd >actual.info-np &&
+	test_cmp_info expected.info-np actual.info-np &&
+	test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \
+	     "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)"
+	'
+
 test_expect_success 'info --url .' '
 	test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo"
 	'
-- 
EW
Previous: Andrej ManduchNext: Andrej Manduch
Message 4 of 5 in “git-svn: doublecheck if really file or dir”
  1. git-svn: doublecheck if really file or dirAndrej Manduch, Jul 18, 2014
  2. Eric WongJul 23, 2014
  3. Andrej ManduchJul 27, 2014
  4. Eric WongAug 3, 2014
  5. Andrej ManduchAug 3, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.