git-svn: avoid md5 calculation entirely if SVN doesn't provide one
There's no point in calculating an MD5 if we're not going to use it. We'll also avoid the possibility of there being a bug in the Perl MD5 library not being able to handle zero-sized files. This is a followup to 20b3d206acbbb042c7ad5f42d36ff8d036a538c5, which allows us to track repositories that do not provide MD5 checksums. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
May 27, 2007 at 15:59 UTC
7faf068660f0a060066ccbc80f7debbba6bc2d76
1 file changed
+10
-6
git-svn.perl
+10
-6
@@ -2472,12 +2472,16 @@ sub close_file {
2472
my $hash;
2473
my $path = $self->git_path($fb->{path});
2474
if (my $fh = $fb->{fh}) {
2475
- seek($fh, 0, 0) or croak $!;
2476
- my $md5 = Digest::MD5->new;
2477
- $md5->addfile($fh);
2478
- my $got = $md5->hexdigest;
2479
- die "Checksum mismatch: $path\n",
2480
- "expected: $exp\n got: $got\n" if (defined $exp && $got ne $exp);
2475
+ if (defined $exp) {
2476
+ seek($fh, 0, 0) or croak $!;
2477
+ my $md5 = Digest::MD5->new;
2478
+ $md5->addfile($fh);
2479
+ my $got = $md5->hexdigest;
2480
+ if ($got ne $exp) {
2481
+ die "Checksum mismatch: $path\n",
2482
+ "expected: $exp\n got: $got\n";
2483
+ }
2484
+ }
2485
sysseek($fh, 0, 0) or croak $!;
2486
if ($fb->{mode_b} == 120000) {
2487
sysread($fh, my $buf, 5) == 5 or croak $!;