Skip to content

Commit

Permalink
diff: refactor object read
Browse files Browse the repository at this point in the history
Refactor the object reads in diff_populate_filespec() to have the first
object read not be in an if/else branch, because in a future patch, a
retry will be added to that first object read.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
jonathantanmy authored and gitster committed Apr 7, 2020
1 parent 1c37e86 commit c14b6f8
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions diff.c
Expand Up @@ -4023,22 +4023,35 @@ int diff_populate_filespec(struct repository *r,
}
}
else {
enum object_type type;
struct object_info info = {
.sizep = &s->size
};

if (!(size_only || check_binary))
/*
* Set contentp, since there is no chance that merely
* the size is sufficient.
*/
info.contentp = &s->data;

if (oid_object_info_extended(r, &s->oid, &info,
OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));

if (size_only || check_binary) {
type = oid_object_info(r, &s->oid, &s->size);
if (type < 0)
die("unable to read %s",
oid_to_hex(&s->oid));
if (size_only)
return 0;
if (s->size > big_file_threshold && s->is_binary == -1) {
s->is_binary = 1;
return 0;
}
}
s->data = repo_read_object_file(r, &s->oid, &type, &s->size);
if (!s->data)
die("unable to read %s", oid_to_hex(&s->oid));
if (!info.contentp) {
info.contentp = &s->data;
if (oid_object_info_extended(r, &s->oid, &info,
OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
}
return 0;
Expand Down

0 comments on commit c14b6f8

Please sign in to comment.