mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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 090ea12671 (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>
This commit is contained in:
committed by
Junio C Hamano
parent
ee213de22d
commit
0f156dbb04
@@ -127,7 +127,7 @@ static int verify_packfile(struct repository *r,
|
||||
|
||||
if (type == OBJ_BLOB && big_file_threshold <= size) {
|
||||
/*
|
||||
* Let check_object_signature() check it with
|
||||
* Let stream_object_signature() check it with
|
||||
* the streaming interface; no point slurping
|
||||
* the data in-core only to discard.
|
||||
*/
|
||||
@@ -142,8 +142,11 @@ static int verify_packfile(struct repository *r,
|
||||
err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
|
||||
oid_to_hex(&oid), p->pack_name,
|
||||
(uintmax_t)entries[i].offset);
|
||||
else if (check_object_signature(r, &oid, data, size,
|
||||
type_name(type), NULL) < 0)
|
||||
else if (data && check_object_signature(r, &oid, data, size,
|
||||
type_name(type)) < 0)
|
||||
err = error("packed %s from %s is corrupt",
|
||||
oid_to_hex(&oid), p->pack_name);
|
||||
else if (!data && stream_object_signature(r, &oid) < 0)
|
||||
err = error("packed %s from %s is corrupt",
|
||||
oid_to_hex(&oid), p->pack_name);
|
||||
else if (fn) {
|
||||
|
||||
Reference in New Issue
Block a user