summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-06-14 08:50:13 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-14 19:26:33 +0200
commit9c34eb93fba703e74f06d20f5b36a1a5e3dc6486 (patch)
treebca28f26a6fdd7eebd872ca733ac7af9ed7dc86b
parenthash: make `is_null_oid()` independent of `the_repository` (diff)
downloadgit-9c34eb93fba703e74f06d20f5b36a1a5e3dc6486.tar.xz
git-9c34eb93fba703e74f06d20f5b36a1a5e3dc6486.zip
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>
-rw-r--r--builtin/fast-import.c4
-rw-r--r--cache-tree.c2
-rw-r--r--diffcore-rename.c4
-rw-r--r--hash-ll.h12
-rw-r--r--hash.h10
-rw-r--r--read-cache.c2
6 files changed, 19 insertions, 15 deletions
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 12543488f3..d21c4053a7 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
parse_path_eol(&path, p, "path");
/* Git does not track empty, non-toplevel directories. */
- if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
+ if (S_ISDIR(mode) &&
+ is_empty_tree_oid(&oid, the_repository->hash_algo) &&
+ *path.buf) {
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
return;
}
diff --git a/cache-tree.c b/cache-tree.c
index e4255c4d02..3290a1b8dd 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && is_empty_tree_oid(oid))
+ if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
continue;
strbuf_grow(&buffer, entlen + 100);
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 5a6e2bcac7..5abb958651 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->two->oid))
+ is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
continue;
else if (add_rename_dst(p) < 0) {
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
}
}
else if (!options->flags.rename_empty &&
- is_empty_blob_oid(&p->one->oid))
+ is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
continue;
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
/*
diff --git a/hash-ll.h b/hash-ll.h
index faf6c292d2..1000a9af22 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
+static inline int is_empty_blob_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_blob);
+}
+
+static inline int is_empty_tree_oid(const struct object_id *oid,
+ const struct git_hash_algo *algop)
+{
+ return oideq(oid, algop->empty_tree);
+}
+
#endif
diff --git a/hash.h b/hash.h
index 84f2296cfb..39a0164be3 100644
--- a/hash.h
+++ b/hash.h
@@ -6,14 +6,4 @@
#define the_hash_algo the_repository->hash_algo
-static inline int is_empty_blob_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_blob);
-}
-
-static inline int is_empty_tree_oid(const struct object_id *oid)
-{
- return oideq(oid, the_hash_algo->empty_tree);
-}
-
#endif
diff --git a/read-cache.c b/read-cache.c
index 836f1db721..085b22faf3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) {
- if (!is_empty_blob_oid(&ce->oid))
+ if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
changed |= DATA_CHANGED;
}