]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: require hash algorithm in `empty_tree_oid_hex()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 14 Jun 2024 06:50:18 +0000 (08:50 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2024 17:26:33 +0000 (10:26 -0700)
The `empty_tree_oid_hex()` function 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.

While at it, remove the unused `empty_blob_oid_hex()` function.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c
add-patch.c
builtin/merge.c
builtin/receive-pack.c
hash-ll.h
object-file.c
sequencer.c
submodule.c
wt-status.c

index b5d6cd689a1d5ebdd211b898d63ef5ce9137d2cc..a0961096cd15098682ccb26c28f1725e3c20e5c7 100644 (file)
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
                s.skip_unseen = filter && i;
 
                opt.def = is_initial ?
-                       empty_tree_oid_hex() : oid_to_hex(&head_oid);
+                       empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
 
                repo_init_revisions(r, &rev, NULL);
                setup_revisions(0, NULL, &rev, &opt);
index 814de57c4a70054ebc30e770a16922b4ea71b6e8..86181770f2c0bd7d76e52159a20e83d267eee72b 100644 (file)
@@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
                            /* could be on an unborn branch */
                            !strcmp("HEAD", s->revision) &&
                            repo_get_oid(the_repository, "HEAD", &oid) ?
-                           empty_tree_oid_hex() : s->revision);
+                           empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
        }
        color_arg_index = args.nr;
        /* Use `--no-color` explicitly, just in case `diff.color = always`. */
index abe66311c705187f77aaf6f62f8f033d08b6e543..bb94b7df21c640e1303658b20d46fd7e65a5fbaa 100644 (file)
@@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
 {
        struct child_process cmd = CHILD_PROCESS_INIT;
 
-       strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
+       strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
+                    empty_tree_oid_hex(the_repository->hash_algo),
                     oid_to_hex(oid), NULL);
        cmd.git_cmd = 1;
 
index aa5ba27d175835eee6e4b715117f15df54577167..41d5fb8e60dfe9cf50edd28ad2f98660118edaad 100644 (file)
@@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
        strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
                     "--ignore-submodules",
                     /* diff-index with either HEAD or an empty tree */
-                    head_has_history() ? "HEAD" : empty_tree_oid_hex(),
+                    head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
                     "--", NULL);
        strvec_pushv(&child.env, env->v);
        child.no_stdin = 1;
index 1000a9af228532177986481b9ccc75b6de51778d..3161c778b980bd4faf7f1f5c451d5de8c45c2a2e 100644 (file)
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -347,8 +347,7 @@ static inline int is_null_oid(const struct object_id *oid)
        return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
 }
 
-const char *empty_tree_oid_hex(void);
-const char *empty_blob_oid_hex(void);
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
 
 static inline int is_empty_blob_oid(const struct object_id *oid,
                                    const struct git_hash_algo *algop)
index bb97f8a8090bac6b096e13be07110eb5adaad0a7..72318c8dd479012ea7ab659ddb693ed475afd1d0 100644 (file)
@@ -227,16 +227,10 @@ const struct object_id *null_oid(void)
        return the_hash_algo->null_oid;
 }
 
-const char *empty_tree_oid_hex(void)
+const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
 {
        static char buf[GIT_MAX_HEXSZ + 1];
-       return oid_to_hex_r(buf, the_hash_algo->empty_tree);
-}
-
-const char *empty_blob_oid_hex(void)
-{
-       static char buf[GIT_MAX_HEXSZ + 1];
-       return oid_to_hex_r(buf, the_hash_algo->empty_blob);
+       return oid_to_hex_r(buf, algop->empty_tree);
 }
 
 int hash_algo_by_name(const char *name)
index 68d62a12ff69bc78e0cfcf06a49b7004c6d5bffa..823691e379baaee999ec8242ad5d6f434c28b481 100644 (file)
@@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
                        unborn = 1;
                } else if (unborn)
                        oidcpy(&head, the_hash_algo->empty_tree);
-               if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
+               if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
                                       NULL, 0))
                        return error_dirty_index(r, opts);
        }
index 759cf1e1cda9b0ad10a756523b7d5896bfb3a853..caf3aa5600f77c595753647e602bd76fa6f885ec 100644 (file)
@@ -2119,7 +2119,7 @@ static void submodule_reset_index(const char *path, const char *super_prefix)
        strvec_pushf(&cp.args, "--super-prefix=%s%s/",
                     (super_prefix ? super_prefix : ""), path);
 
-       strvec_push(&cp.args, empty_tree_oid_hex());
+       strvec_push(&cp.args, empty_tree_oid_hex(the_repository->hash_algo));
 
        if (run_command(&cp))
                die(_("could not reset submodule index"));
@@ -2229,9 +2229,9 @@ int submodule_move_head(const char *path, const char *super_prefix,
                strvec_push(&cp.args, "-m");
 
        if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
-               strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
+               strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex(the_repository->hash_algo));
 
-       strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
+       strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex(the_repository->hash_algo));
 
        if (run_command(&cp)) {
                ret = error(_("Submodule '%s' could not be updated."), path);
index ff4be071ca4f8366e4ddf926cf1fc94aea195eca..5051f5e599b03fb0800aff8bd031b16c7a47977a 100644 (file)
@@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
 
        repo_init_revisions(s->repo, &rev, NULL);
        memset(&opt, 0, sizeof(opt));
-       opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+       opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
        setup_revisions(0, NULL, &rev, &opt);
 
        rev.diffopt.flags.override_submodule_config = 1;
@@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
        rev.diffopt.ita_invisible_in_index = 1;
 
        memset(&opt, 0, sizeof(opt));
-       opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
+       opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
        setup_revisions(0, NULL, &rev, &opt);
 
        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;