@matheusbsbs / matheus-bagliano / commits / c14b6f83ec
Fork 0

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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Apr 7, 2020 at 15:11 UTC c14b6f83ec7453d2a93bba04f45caf26905f2bff
1 file changed +21 -8
diff.c
+21 -8
@@ -4023,12 +4023,22 @@ int diff_populate_filespec(struct repository *r,
4023 }
4024 }
4025 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 +
4041 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));
4042 if (size_only)
4043 return 0;
4044 if (s->size > big_file_threshold && s->is_binary == -1) {
@@ -4036,9 +4046,12 @@ int diff_populate_filespec(struct repository *r,
4046 return 0;
4047 }
4048 }
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 + }
4055 s->should_free = 1;
4056 }
4057 return 0;