object-file: add a compat_oid_in parameter to write_object_file_flags
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>
Eric W. Biederman committed
Oct 1, 2023 at 21:40 UTC
c2538492df8259885abc18acdadacc22b1e77e5a
3 files changed
+7
-5
cache-tree.c
+1
-1
@@ -448,7 +448,7 @@ static int update_one(struct cache_tree *it,
448
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
449
OBJ_TREE, &it->oid);
450
} else if (write_object_file_flags(buffer.buf, buffer.len, OBJ_TREE,
451
- &it->oid, flags & WRITE_TREE_SILENT
451
+ &it->oid, NULL, flags & WRITE_TREE_SILENT
452
? HASH_SILENT : 0)) {
453
strbuf_release(&buffer);
454
return -1;
object-file.c
+4
-2
@@ -2235,7 +2235,7 @@ cleanup:
2235
2236
int write_object_file_flags(const void *buf, unsigned long len,
2237
enum object_type type, struct object_id *oid,
2238
- unsigned flags)
2238
+ struct object_id *compat_oid_in, unsigned flags)
2239
{
2240
struct repository *repo = the_repository;
2241
const struct git_hash_algo *algo = repo->hash_algo;
@@ -2246,7 +2246,9 @@ int write_object_file_flags(const void *buf, unsigned long len,
2246
2247
/* Generate compat_oid */
2248
if (compat) {
2249
- if (type == OBJ_BLOB)
2249
+ if (compat_oid_in)
2250
+ oidcpy(&compat_oid, compat_oid_in);
2251
+ else if (type == OBJ_BLOB)
2252
hash_object_file(compat, buf, len, type, &compat_oid);
2253
else {
2254
struct strbuf converted = STRBUF_INIT;
object-store-ll.h
+2
-2
@@ -255,11 +255,11 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
255
256
int write_object_file_flags(const void *buf, unsigned long len,
257
enum object_type type, struct object_id *oid,
258
- unsigned flags);
258
+ struct object_id *comapt_oid_in, unsigned flags);
259
static inline int write_object_file(const void *buf, unsigned long len,
260
enum object_type type, struct object_id *oid)
261
{
262
- return write_object_file_flags(buf, len, type, oid, 0);
262
+ return write_object_file_flags(buf, len, type, oid, NULL, 0);
263
}
264
265
int write_object_file_literally(const void *buf, unsigned long len,