Git::cat_blob: allow using an empty blob to fix git-svn breakage
authorJunio C Hamano <gitster@pobox.com>
Wed, 28 May 2008 06:33:22 +0000 (23:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 May 2008 06:35:55 +0000 (23:35 -0700)
Recent "git-svn optimization" series introduced Git::cat_blob() subroutine
whose interface was broken in that it returned the size of the blob but
signalled an error by returning 0.  You can never use an empty blob with
such an interface.

This fixes the interface to return a negative value to signal an error.

Reported by Björn Steinbrink.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-svn.perl
perl/Git.pm

index 37976f2..3a6eb1c 100755 (executable)
@@ -3191,7 +3191,7 @@ sub apply_textdelta {
        if ($fb->{blob}) {
                print $base 'link ' if ($fb->{mode_a} == 120000);
                my $size = $::_repository->cat_blob($fb->{blob}, $base);
-               die "Failed to read object $fb->{blob}" unless $size;
+               die "Failed to read object $fb->{blob}" if ($size < 0);
 
                if (defined $exp) {
                        seek $base, 0, 0 or croak $!;
@@ -3570,7 +3570,7 @@ sub chg_file {
                $self->change_file_prop($fbat,'svn:special',undef);
        }
        my $size = $::_repository->cat_blob($m->{sha1_b}, $fh);
-       croak "Failed to read object $m->{sha1_b}" unless $size;
+       croak "Failed to read object $m->{sha1_b}" if ($size < 0);
        $fh->flush == 0 or croak $!;
        seek $fh, 0, 0 or croak $!;
 
index 6ba8ee5..d05b633 100644 (file)
@@ -811,12 +811,12 @@ sub cat_blob {
        my $description = <$in>;
        if ($description =~ / missing$/) {
                carp "$sha1 doesn't exist in the repository";
-               return 0;
+               return -1;
        }
 
        if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) {
                carp "Unexpected result returned from git cat-file";
-               return 0;
+               return -1;
        }
 
        my $size = $1;