Skip to content

Commit

Permalink
diff: don't presume empty file when corresponding object is missing
Browse files Browse the repository at this point in the history
The low-level diff code will happily produce totally bogus diff output
with a broken repository via format-patch and friends by treating missing
objects as empty files.  Let's prevent that from happening any longer.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nicolas Pitre authored and Junio C Hamano committed Oct 22, 2010
1 parent e923eae commit c50c431
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2124,10 +2124,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
}
else {
enum object_type type;
if (size_only)
if (size_only) {
type = sha1_object_info(s->sha1, &s->size);
else {
if (type < 0)
die("unable to read %s", sha1_to_hex(s->sha1));
} else {
s->data = read_sha1_file(s->sha1, &type, &s->size);
if (!s->data)
die("unable to read %s", sha1_to_hex(s->sha1));
s->should_free = 1;
}
}
Expand Down

0 comments on commit c50c431

Please sign in to comment.