]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 14 Jun 2024 06:50:13 +0000 (08:50 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2024 17:26:33 +0000 (10:26 -0700)
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>
builtin/fast-import.c
cache-tree.c
diffcore-rename.c
hash-ll.h
hash.h
read-cache.c

index 12543488f3d48d69bffd8babfecb6a2dc227e9db..d21c4053a7e4d96e785b8d5424660ee5e9a42d08 100644 (file)
@@ -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;
        }
index e4255c4d022da326a40448050bbce52ace7e0073..3290a1b8dd784b44c0a282d16782e6908524faee 100644 (file)
@@ -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);
index 5a6e2bcac7147e487624c1bf53e1572a54b0d93d..5abb9586516af9ad46180985f8a6c81985f900cb 100644 (file)
@@ -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)) {
                        /*
index faf6c292d25079be540f1386ba126cc215fa0d22..1000a9af228532177986481b9ccc75b6de51778d 100644 (file)
--- 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 84f2296cfbb72614be9e76475ba334cada79c3cb..39a0164be32256fef2737c7f15a2b4c57f977569 100644 (file)
--- 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
index 836f1db721f5094b3e33b10d3baa1c466ff544b3..085b22faf3a01b86c849b67072625b5a11568cfc 100644 (file)
@@ -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;
        }