@matheusbsbs / matheus-bagliano / commits / d683a0e00c
Fork 0

Git::cat_blob: allow using an empty blob to fix git-svn breakage

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>

Junio C Hamano committed May 27, 2008 at 23:33 UTC d683a0e00cd4734b4fab704baef1ee76205722be
2 files changed +4 -4
git-svn.perl
+2 -2
@@ -3191,7 +3191,7 @@ sub apply_textdelta {
3191 if ($fb->{blob}) {
3192 print $base 'link ' if ($fb->{mode_a} == 120000);
3193 my $size = $::_repository->cat_blob($fb->{blob}, $base);
3194 - die "Failed to read object $fb->{blob}" unless $size;
3194 + die "Failed to read object $fb->{blob}" if ($size < 0);
3195
3196 if (defined $exp) {
3197 seek $base, 0, 0 or croak $!;
@@ -3570,7 +3570,7 @@ sub chg_file {
3570 $self->change_file_prop($fbat,'svn:special',undef);
3571 }
3572 my $size = $::_repository->cat_blob($m->{sha1_b}, $fh);
3573 - croak "Failed to read object $m->{sha1_b}" unless $size;
3573 + croak "Failed to read object $m->{sha1_b}" if ($size < 0);
3574 $fh->flush == 0 or croak $!;
3575 seek $fh, 0, 0 or croak $!;
3576
perl/Git.pm
+2 -2
@@ -811,12 +811,12 @@ sub cat_blob {
811 my $description = <$in>;
812 if ($description =~ / missing$/) {
813 carp "$sha1 doesn't exist in the repository";
814 - return 0;
814 + return -1;
815 }
816
817 if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) {
818 carp "Unexpected result returned from git cat-file";
819 - return 0;
819 + return -1;
820 }
821
822 my $size = $1;