Skip to content

Commit c14b6f8

Browse files
jonathantanmygitster
authored andcommitted
diff: refactor object read
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c37e86 commit c14b6f8

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

diff.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,22 +4023,35 @@ int diff_populate_filespec(struct repository *r,
40234023
}
40244024
}
40254025
else {
4026-
enum object_type type;
4026+
struct object_info info = {
4027+
.sizep = &s->size
4028+
};
4029+
4030+
if (!(size_only || check_binary))
4031+
/*
4032+
* Set contentp, since there is no chance that merely
4033+
* the size is sufficient.
4034+
*/
4035+
info.contentp = &s->data;
4036+
4037+
if (oid_object_info_extended(r, &s->oid, &info,
4038+
OBJECT_INFO_LOOKUP_REPLACE))
4039+
die("unable to read %s", oid_to_hex(&s->oid));
4040+
40274041
if (size_only || check_binary) {
4028-
type = oid_object_info(r, &s->oid, &s->size);
4029-
if (type < 0)
4030-
die("unable to read %s",
4031-
oid_to_hex(&s->oid));
40324042
if (size_only)
40334043
return 0;
40344044
if (s->size > big_file_threshold && s->is_binary == -1) {
40354045
s->is_binary = 1;
40364046
return 0;
40374047
}
40384048
}
4039-
s->data = repo_read_object_file(r, &s->oid, &type, &s->size);
4040-
if (!s->data)
4041-
die("unable to read %s", oid_to_hex(&s->oid));
4049+
if (!info.contentp) {
4050+
info.contentp = &s->data;
4051+
if (oid_object_info_extended(r, &s->oid, &info,
4052+
OBJECT_INFO_LOOKUP_REPLACE))
4053+
die("unable to read %s", oid_to_hex(&s->oid));
4054+
}
40424055
s->should_free = 1;
40434056
}
40444057
return 0;

0 commit comments

Comments
 (0)