Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-02-05 02:48:30 +0300
committerJunio C Hamano <gitster@pobox.com>2022-02-26 04:16:31 +0300
commit0f156dbb04b434d95ce5465e6b07d8869d55e8e0 (patch)
treed53cf2b523a488748552b463a499908496592516 /object-file.c
parentee213de22d15e801ba3712be0cb8ecbf7415fa1d (diff)
object-file API: split up and simplify check_object_signature()
Split up the check_object_signature() function into that non-streaming version (it accepts an already filled "buf"), and a new stream_object_signature() which will retrieve the object from storage, and hash it on-the-fly. All of the callers of check_object_signature() were effectively calling two different functions, if we go by cyclomatic complexity. I.e. they'd either take the early "if (map)" branch and return early, or not. This has been the case since the "if (map)" condition was added in 090ea12671b (parse_object: avoid putting whole blob in core, 2012-03-07). We can then further simplify the resulting check_object_signature() function since only one caller wanted to pass a non-NULL "buf" and a non-NULL "real_oidp". That "read_loose_object()" codepath used by "git fsck" can instead use hash_object_file() followed by oideq(). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/object-file.c b/object-file.c
index d628f58c0d..f985492274 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1067,22 +1067,25 @@ int format_object_header(char *str, size_t size, enum object_type type,
}
int check_object_signature(struct repository *r, const struct object_id *oid,
- void *buf, unsigned long size, const char *type,
- struct object_id *real_oidp)
+ void *buf, unsigned long size, const char *type)
{
- struct object_id tmp;
- struct object_id *real_oid = real_oidp ? real_oidp : &tmp;
+ struct object_id real_oid;
+
+ hash_object_file(r->hash_algo, buf, size, type, &real_oid);
+
+ return !oideq(oid, &real_oid) ? -1 : 0;
+}
+
+int stream_object_signature(struct repository *r, const struct object_id *oid)
+{
+ struct object_id real_oid;
+ unsigned long size;
enum object_type obj_type;
struct git_istream *st;
git_hash_ctx c;
char hdr[MAX_HEADER_LEN];
int hdrlen;
- if (buf) {
- hash_object_file(r->hash_algo, buf, size, type, real_oid);
- return !oideq(oid, real_oid) ? -1 : 0;
- }
-
st = open_istream(r, oid, &obj_type, &size, NULL);
if (!st)
return -1;
@@ -1105,9 +1108,9 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
break;
r->hash_algo->update_fn(&c, buf, readlen);
}
- r->hash_algo->final_oid_fn(real_oid, &c);
+ r->hash_algo->final_oid_fn(&real_oid, &c);
close_istream(st);
- return !oideq(oid, real_oid) ? -1 : 0;
+ return !oideq(oid, &real_oid) ? -1 : 0;
}
int git_open_cloexec(const char *name, int flags)
@@ -2611,9 +2614,10 @@ int read_loose_object(const char *path,
git_inflate_end(&stream);
goto out;
}
- if (check_object_signature(the_repository, expected_oid,
- *contents, *size,
- oi->type_name->buf, real_oid) < 0)
+ hash_object_file(the_repository->hash_algo,
+ *contents, *size, oi->type_name->buf,
+ real_oid);
+ if (!oideq(expected_oid, real_oid))
goto out;
}