hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
Both functions `is_empty_{blob,tree}_oid()` use `the_repository` to derive the hash function that shall be used. Require callers to pass in the hash algorithm to get rid of this implicit dependency. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 14, 2024 at 08:50 UTC
9c34eb93fba703e74f06d20f5b36a1a5e3dc6486
6 files changed
+19
-15
builtin/fast-import.c
+3
-1
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
2361
parse_path_eol(&path, p, "path");
2362
2363
/* Git does not track empty, non-toplevel directories. */
2364
- if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
2364
+ if (S_ISDIR(mode) &&
2365
+ is_empty_tree_oid(&oid, the_repository->hash_algo) &&
2366
+ *path.buf) {
2367
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
2368
return;
2369
}
cache-tree.c
+1
-1
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
422
/*
423
* "sub" can be an empty tree if all subentries are i-t-a.
424
*/
425
- if (contains_ita && is_empty_tree_oid(oid))
425
+ if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
426
continue;
427
428
strbuf_grow(&buffer, entlen + 100);
diffcore-rename.c
+2
-2
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
1422
strcmp(options->single_follow, p->two->path))
1423
continue; /* not interested */
1424
else if (!options->flags.rename_empty &&
1425
- is_empty_blob_oid(&p->two->oid))
1425
+ is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
1426
continue;
1427
else if (add_rename_dst(p) < 0) {
1428
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
1432
}
1433
}
1434
else if (!options->flags.rename_empty &&
1435
- is_empty_blob_oid(&p->one->oid))
1435
+ is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
1436
continue;
1437
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
1438
/*
hash-ll.h
+12
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
350
const char *empty_tree_oid_hex(void);
351
const char *empty_blob_oid_hex(void);
352
353
+static inline int is_empty_blob_oid(const struct object_id *oid,
354
+ const struct git_hash_algo *algop)
355
+{
356
+ return oideq(oid, algop->empty_blob);
357
+}
358
+
359
+static inline int is_empty_tree_oid(const struct object_id *oid,
360
+ const struct git_hash_algo *algop)
361
+{
362
+ return oideq(oid, algop->empty_tree);
363
+}
364
+
365
#endif
hash.h
-10
@@ -6,14 +6,4 @@
6
7
#define the_hash_algo the_repository->hash_algo
8
9
-static inline int is_empty_blob_oid(const struct object_id *oid)
10
-{
11
- return oideq(oid, the_hash_algo->empty_blob);
12
-}
13
-
14
-static inline int is_empty_tree_oid(const struct object_id *oid)
15
-{
16
- return oideq(oid, the_hash_algo->empty_tree);
17
-}
18
-
9
#endif
read-cache.c
+1
-1
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
337
338
/* Racily smudged entry? */
339
if (!ce->ce_stat_data.sd_size) {
340
- if (!is_empty_blob_oid(&ce->oid))
340
+ if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
341
changed |= DATA_CHANGED;
342
}
343