Skip to content

Commit d683a0e

Browse files
committed
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>
1 parent b2a42f5 commit d683a0e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

git-svn.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,7 @@ sub apply_textdelta {
31913191
if ($fb->{blob}) {
31923192
print $base 'link ' if ($fb->{mode_a} == 120000);
31933193
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);
31953195

31963196
if (defined $exp) {
31973197
seek $base, 0, 0 or croak $!;
@@ -3570,7 +3570,7 @@ sub chg_file {
35703570
$self->change_file_prop($fbat,'svn:special',undef);
35713571
}
35723572
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);
35743574
$fh->flush == 0 or croak $!;
35753575
seek $fh, 0, 0 or croak $!;
35763576

perl/Git.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,12 @@ sub cat_blob {
811811
my $description = <$in>;
812812
if ($description =~ / missing$/) {
813813
carp "$sha1 doesn't exist in the repository";
814-
return 0;
814+
return -1;
815815
}
816816

817817
if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) {
818818
carp "Unexpected result returned from git cat-file";
819-
return 0;
819+
return -1;
820820
}
821821

822822
my $size = $1;

0 commit comments

Comments
 (0)