diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2022-02-05 00:48:30 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-02-25 17:16:31 -0800 |
commit | 0f156dbb04b434d95ce5465e6b07d8869d55e8e0 (patch) | |
tree | d53cf2b523a488748552b463a499908496592516 /builtin | |
parent | object API users + docs: check <0, not !0 with check_object_signature() (diff) | |
download | tgif-0f156dbb04b434d95ce5465e6b07d8869d55e8e0.tar.xz |
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 'builtin')
-rw-r--r-- | builtin/fast-export.c | 2 | ||||
-rw-r--r-- | builtin/index-pack.c | 2 | ||||
-rw-r--r-- | builtin/mktag.c | 5 |
3 files changed, 4 insertions, 5 deletions
diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 9f1c730e58..319859db30 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -300,7 +300,7 @@ static void export_blob(const struct object_id *oid) if (!buf) die("could not read blob %s", oid_to_hex(oid)); if (check_object_signature(the_repository, oid, buf, size, - type_name(type), NULL) < 0) + type_name(type)) < 0) die("oid mismatch in blob %s", oid_to_hex(oid)); object = parse_object_buffer(the_repository, oid, type, size, buf, &eaten); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 416f60a98c..e1927205a7 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1413,7 +1413,7 @@ static void fix_unresolved_deltas(struct hashfile *f) continue; if (check_object_signature(the_repository, &d->oid, data, size, - type_name(type), NULL) < 0) + type_name(type)) < 0) die(_("local object %s is corrupt"), oid_to_hex(&d->oid)); /* diff --git a/builtin/mktag.c b/builtin/mktag.c index 98d1e66f32..4d28eceeba 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -61,9 +61,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type) type_name(*tagged_type), type_name(type)); repl = lookup_replace_object(the_repository, tagged_oid); - ret = check_object_signature(the_repository, repl, - buffer, size, type_name(*tagged_type), - NULL); + ret = check_object_signature(the_repository, repl, buffer, size, + type_name(*tagged_type)); free(buffer); return ret; |