git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFH/PATCH] git-svn: adjust info to svn 1.7 and 1.8
@ 2015-03-24 15:10 Michael J Gruber
  2015-03-26 16:02 ` Michael J Gruber
  0 siblings, 1 reply; 2+ messages in thread
From: Michael J Gruber @ 2015-03-24 15:10 UTC (permalink / raw)
  To: git; +Cc: Eric Wong

t9119 refuses to run with svn versions greater than 1.6 since "git svn
info" does not even try to match the output of "svn info" for later
versions.

Adjust "git svn info" to match these versions and make t9119 run with
them. This requires the following changes:

* compute checksums with SHA1 instead of MD5 with svn >= 1.7.0
* omit the line "Revision: 0" for added content with svn >= 1.8.0 (TBC)
* print the "Repository UUID" line even for added content with svn >=
  1.8.0 (TBC)
* add a "Relative URL" line for svn >= 1.8.0
* add a "Working Copy Root Path" line for svn >= 1.8.0 (TBC, RFH)

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---

Notes:
    While trying to increase my test run coverage I noticed that most of us won't
    run t9119 at all. Bad bad.
    
    My svn is 1.8.11 (r1643975) on Fedora 21.
    
    I would appreciate help with the following items:
    
    TBC = to be confirmed: confirm the svn version where this change kicked it,
    or run this patch and t9119 with an svn version other than mine. Please
    run with "-v" to make sure only the RFH item fails, see below.
    
    RFH = request for help: I couldn't figure out how to get the working
    copy root path in cmd_info.
    
    18 subtests will fail because of the RFH item.

 git-svn.perl            | 38 +++++++++++++++++++++++++++++++++-----
 t/t9119-git-svn-info.sh |  2 +-
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 36f7240..00c9cc1 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1580,6 +1580,7 @@ sub cmd_info {
 	}
 
 	# canonicalize_path() will return "" to make libsvn 1.5.x happy,
+	my $rpath = $path;
 	$path = "." if $path eq "";
 
 	my $full_url = canonicalize_url( add_path_to_url( $url, $path ) );
@@ -1591,7 +1592,9 @@ sub cmd_info {
 
 	my $result = "Path: $path_arg\n";
 	$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
+	$result .= "Working Copy Root Path: " . $gs->path . "\n" if ::compare_svn_version('1.7.0') >= 0; #TODO
 	$result .= "URL: $full_url\n";
+	$result .= "Relative URL: ^/" . $rpath . "\n" if ::compare_svn_version('1.8.0')>=0;
 
 	eval {
 		my $repos_root = $gs->repos_root;
@@ -1603,8 +1606,10 @@ sub cmd_info {
 	}
 	::_req_svn();
 	$result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
+		::compare_svn_version('1.8.0') < 0 &&
 		(::compare_svn_version('1.5.4') <= 0 || $file_type ne "dir");
-	$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
+	$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n" unless
+		$diff_status eq "A" && ::compare_svn_version('1.8.0') >= 0;
 
 	$result .= "Node Kind: " .
 		   ($file_type eq "dir" ? "directory" : "file") . "\n";
@@ -1653,19 +1658,19 @@ sub cmd_info {
 			    command_output_pipe(qw(cat-file blob), "HEAD:$path");
 			if ($file_type eq "link") {
 				my $file_name = <$fh>;
-				$checksum = md5sum("link $file_name");
+				$checksum = md5sha1sum("link $file_name");
 			} else {
-				$checksum = md5sum($fh);
+				$checksum = md5sha1sum($fh);
 			}
 			command_close_pipe($fh, $ctx);
 		} elsif ($file_type eq "link") {
 			my $file_name =
 			    command(qw(cat-file blob), "HEAD:$path");
 			$checksum =
-			    md5sum("link " . $file_name);
+			    md5sha1sum("link " . $file_name);
 		} else {
 			open FILE, "<", $path or die $!;
-			$checksum = md5sum(\*FILE);
+			$checksum = md5sha1sum(\*FILE);
 			close FILE or die $!;
 		}
 		$result .= "Checksum: " . $checksum . "\n";
@@ -2135,6 +2140,29 @@ sub md5sum {
 	return $md5->hexdigest();
 }
 
+sub md5sha1sum {
+	my $arg = shift;
+	my $ref = ref $arg;
+	my $md5;
+	if (::compare_svn_version('1.7.0') < 0)	{
+		require Digest::MD5;
+		$md5 = Digest::MD5->new();
+	} else {
+		require Digest::SHA1;
+		$md5 = Digest::SHA1->new();
+	}
+        if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
+		$md5->addfile($arg) or croak $!;
+	} elsif ($ref eq 'SCALAR') {
+		$md5->add($$arg) or croak $!;
+	} elsif (!$ref) {
+		$md5->add($arg) or croak $!;
+	} else {
+		fatal "Can't provide MD5 hash for unknown ref type: '", $ref, "'";
+	}
+	return $md5->hexdigest();
+}
+
 sub gc_directory {
 	if (can_compress() && -f $_ && basename($_) eq "unhandled.log") {
 		my $out_filename = $_ . ".gz";
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index f16f323..b7476c7 100755
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -10,7 +10,7 @@ test_description='git svn info'
 # Tested with: svn, version 1.6.[12345689]
 v=`svn_cmd --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p'`
 case $v in
-1.[456].*)
+1.[45678].*)
 	;;
 *)
 	skip_all="skipping svn-info test (SVN version: $v not supported)"
-- 
2.3.4.518.g406241f

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

end of thread, other threads:[~2015-03-26 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-24 15:10 [RFH/PATCH] git-svn: adjust info to svn 1.7 and 1.8 Michael J Gruber
2015-03-26 16:02 ` Michael J Gruber

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