Add a "hash_object_file_literally()" function to go with the existing "hash_object_file()" function. This is currently a wrapper for its sibling, but this change will allow us to change it to take an "enum object_type" in a subsequent commit. The only caller that wanted to pass a custom type to "check_object_signature()" was the "git fsck" via its "read_loose_object()", which is being changed here. There was an existing hash_object_file_literally() which I'm renaming to "hash_write_object_file_literally()", that function is only used for "hash-object --literally". That renaming is being done because it would be confusing to have a "hash_object_file_literally()" and a "hash_object_file()" that do very different things. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- builtin/hash-object.c | 4 ++-- object-file.c | 18 +++++++++++++----- object-store.h | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index c7b3ad74c60..624e9e677fb 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -25,8 +25,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig if (strbuf_read(&buf, fd, 4096) < 0) ret = -1; else - ret = hash_object_file_literally(buf.buf, buf.len, type, oid, - flags); + ret = hash_write_object_file_literally(buf.buf, buf.len, type, oid, + flags); strbuf_release(&buf); return ret; } diff --git a/object-file.c b/object-file.c index 27d10112960..9fc959fa05d 100644 --- a/object-file.c +++ b/object-file.c @@ -1862,6 +1862,13 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf, write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen); } +static void hash_object_file_literally(const struct git_hash_algo *algo, const void *buf, + unsigned long len, const char *type, + struct object_id *oid) +{ + hash_object_file(algo, buf, len, type, oid); +} + int hash_object_file_oideq(const struct git_hash_algo *algo, const void *buf, unsigned long len, enum object_type type, const struct object_id *oid, @@ -2043,9 +2050,9 @@ int write_object_file_flags(const void *buf, unsigned long len, return write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags); } -int hash_object_file_literally(const void *buf, unsigned long len, - const char *type, struct object_id *oid, - unsigned flags) +int hash_write_object_file_literally(const void *buf, unsigned long len, + const char *type, struct object_id *oid, + unsigned flags) { char *header; int hdrlen, status = 0; @@ -2630,9 +2637,10 @@ int read_loose_object(const char *path, git_inflate_end(&stream); goto out; } - if (check_object_signature(the_repository, expected_oid, + hash_object_file_literally(the_repository->hash_algo, *contents, *size, - oi->type_name->buf, real_oid)) + oi->type_name->buf, real_oid); + if (!oideq(expected_oid, real_oid)) goto out; } diff --git a/object-store.h b/object-store.h index 95907062682..2ddc20b3304 100644 --- a/object-store.h +++ b/object-store.h @@ -272,9 +272,9 @@ static inline int write_object_file(const void *buf, unsigned long len, return write_object_file_flags(buf, len, type, oid, 0); } -int hash_object_file_literally(const void *buf, unsigned long len, - const char *type, struct object_id *oid, - unsigned flags); +int hash_write_object_file_literally(const void *buf, unsigned long len, + const char *type, struct object_id *oid, + unsigned flags); /* * Add an object file to the in-memory object store, without writing it -- 2.35.0.913.g12b4baa2536