]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: add a compat_oid_in parameter to write_object_file_flags
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 2 Oct 2023 02:40:12 +0000 (21:40 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Oct 2023 21:57:39 +0000 (14:57 -0700)
To create the proper signatures for commit objects both versions of
the commit object need to be generated and signed.  After that it is
a waste to throw away the work of generating the compatibility hash
so update write_object_file_flags to take a compatibility hash input
parameter that it can use to skip the work of generating the
compatability hash.

Update the places that don't generate the compatability hash to
pass NULL so it is easy to tell write_object_file_flags should
not attempt to use their compatability hash.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache-tree.c
object-file.c
object-store-ll.h

index 641427ed410af39be80be22460a103dbad2d3d35..ddc7d3d8695933ed39573c694a9d3fc6d0b9f1e3 100644 (file)
@@ -448,7 +448,7 @@ static int update_one(struct cache_tree *it,
                hash_object_file(the_hash_algo, buffer.buf, buffer.len,
                                 OBJ_TREE, &it->oid);
        } else if (write_object_file_flags(buffer.buf, buffer.len, OBJ_TREE,
-                                          &it->oid, flags & WRITE_TREE_SILENT
+                                          &it->oid, NULL, flags & WRITE_TREE_SILENT
                                           ? HASH_SILENT : 0)) {
                strbuf_release(&buffer);
                return -1;
index 4e55f475b3b4796822efd70343d415f2a698e8b2..820810a5f4b32197152215fa1fbbbff12b250c31 100644 (file)
@@ -2235,7 +2235,7 @@ cleanup:
 
 int write_object_file_flags(const void *buf, unsigned long len,
                            enum object_type type, struct object_id *oid,
-                           unsigned flags)
+                           struct object_id *compat_oid_in, unsigned flags)
 {
        struct repository *repo = the_repository;
        const struct git_hash_algo *algo = repo->hash_algo;
@@ -2246,7 +2246,9 @@ int write_object_file_flags(const void *buf, unsigned long len,
 
        /* Generate compat_oid */
        if (compat) {
-               if (type == OBJ_BLOB)
+               if (compat_oid_in)
+                       oidcpy(&compat_oid, compat_oid_in);
+               else if (type == OBJ_BLOB)
                        hash_object_file(compat, buf, len, type, &compat_oid);
                else {
                        struct strbuf converted = STRBUF_INIT;
index bc76d6bec80d9cc81818ad475d0fcce1a964abca..c5f2bb2fc2fe6eb36cafa559b038dcd3095395da 100644 (file)
@@ -255,11 +255,11 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
 
 int write_object_file_flags(const void *buf, unsigned long len,
                            enum object_type type, struct object_id *oid,
-                           unsigned flags);
+                           struct object_id *comapt_oid_in, unsigned flags);
 static inline int write_object_file(const void *buf, unsigned long len,
                                    enum object_type type, struct object_id *oid)
 {
-       return write_object_file_flags(buf, len, type, oid, 0);
+       return write_object_file_flags(buf, len, type, oid, NULL, 0);
 }
 
 int write_object_file_literally(const void *buf, unsigned long len,