-sub read_cat_in_full ($$$) {
- my ($self, $in, $left) = @_;
- my $offset = 0;
- my $buf = '';
- while ($left > 0) {
- my $r = read($in, $buf, $left, $offset);
- defined($r) or fail($self, "read failed: $!");
- $r == 0 and fail($self, 'exited unexpectedly');
- $left -= $r;
- $offset += $r;
- }
- my $r = read($in, my $lf, 1);
- defined($r) or fail($self, "read failed: $!");
- fail($self, 'newline missing after blob') if ($r != 1 || $lf ne "\n");
+sub read_cat_in_full ($$) {
+ my ($self, $len) = @_;
+ ++$len; # for final "\n" added by git
+ read($self->{in}, my $buf, $len) == $len or fail($self, 'short read');
+ chop($buf) eq "\n" or fail($self, 'newline missing after blob');