]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: provide per-algorithm null OIDs
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 26 Apr 2021 01:02:56 +0000 (01:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Apr 2021 07:31:39 +0000 (16:31 +0900)
Up until recently, object IDs did not have an algorithm member, only a
hash.  Consequently, it was possible to share one null (all-zeros)
object ID among all hash algorithms.  Now that we're going to be
handling objects from multiple hash algorithms, it's important to make
sure that all object IDs have a correct algorithm field.

Introduce a per-algorithm null OID, and add it to struct hash_algo.
Introduce a wrapper function as well, and use it everywhere we used to
use the null_oid constant.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
42 files changed:
archive.c
blame.c
branch.c
builtin/checkout.c
builtin/clone.c
builtin/describe.c
builtin/diff.c
builtin/fast-export.c
builtin/grep.c
builtin/ls-files.c
builtin/rebase.c
builtin/receive-pack.c
builtin/submodule--helper.c
builtin/unpack-objects.c
builtin/worktree.c
combine-diff.c
connect.c
diff-lib.c
diff-no-index.c
diff.c
dir.c
grep.c
hash.h
log-tree.c
merge-ort.c
merge-recursive.c
notes-merge.c
notes.c
object-file.c
parse-options-cb.c
range-diff.c
refs.c
refs/debug.c
refs/files-backend.c
reset.c
sequencer.c
submodule-config.c
submodule.c
t/helper/test-submodule-nested-repo-config.c
tree-diff.c
wt-status.c
xdiff-interface.c

index 6cfb9e42d6ce96fbbc152ac038d890d28620ca98..ff2bb54f6229293157a14660729874791eba661e 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -275,9 +275,11 @@ int write_archive_entries(struct archiver_args *args,
        int err;
        struct strbuf path_in_archive = STRBUF_INIT;
        struct strbuf content = STRBUF_INIT;
-       struct object_id fake_oid = null_oid;
+       struct object_id fake_oid;
        int i;
 
+       oidcpy(&fake_oid, null_oid());
+
        if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
                size_t len = args->baselen;
 
diff --git a/blame.c b/blame.c
index 5018bb8fb2ce810f18f7e57ab26c659b6f943745..206c295660f29b1fd44842ef0f28caf4d2e04788 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -242,7 +242,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
                switch (st.st_mode & S_IFMT) {
                case S_IFREG:
                        if (opt->flags.allow_textconv &&
-                           textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
+                           textconv_object(r, read_from, mode, null_oid(), 0, &buf_ptr, &buf_len))
                                strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
                        else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
                                die_errno("cannot open or read '%s'", read_from);
index 9c9dae1eae321c6878607a3b624a187fcb176380..8db10f849612b2dfcfe8d853ad045174c6c19f5f 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -322,7 +322,7 @@ void create_branch(struct repository *r,
                transaction = ref_transaction_begin(&err);
                if (!transaction ||
                    ref_transaction_update(transaction, ref.buf,
-                                          &oid, forcing ? NULL : &null_oid,
+                                          &oid, forcing ? NULL : null_oid(),
                                           0, msg, &err) ||
                    ref_transaction_commit(transaction, &err))
                        die("%s", err.buf);
index 4c696ef4805b73a30c2ba19e7b3319a836b1c169..8a12b92c5f1bc7b9853df9af312f09e6b3118fe6 100644 (file)
@@ -106,8 +106,8 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
                              int changed)
 {
        return run_hook_le(NULL, "post-checkout",
-                          oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid),
-                          oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid),
+                          oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
+                          oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
                           changed ? "1" : "0", NULL);
        /* "new_commit" can be NULL when checking out from the index before
           a commit exists. */
@@ -638,7 +638,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
        opts.src_index = &the_index;
        opts.dst_index = &the_index;
        init_checkout_metadata(&opts.meta, info->refname,
-                              info->commit ? &info->commit->object.oid : &null_oid,
+                              info->commit ? &info->commit->object.oid : null_oid(),
                               NULL);
        parse_tree(tree);
        init_tree_desc(&tree_desc, tree->buffer, tree->size);
index f6b0c48beda5fe32fab4d4ab65802f1e5dc9a09f..eeb74c0217cf654381f91d57aaf8575bc9c2ad57 100644 (file)
@@ -820,7 +820,7 @@ static int checkout(int submodule_progress)
        if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
-       err |= run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid),
+       err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()),
                           oid_to_hex(&oid), "1", NULL);
 
        if (!err && (option_recurse_submodules.nr > 0)) {
index 40482d8e9f855b6248a865559b12acc27ab84e22..e912ba50d7bac4fbd562774e00cf454e17651baf 100644 (file)
@@ -502,7 +502,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
 {
        struct rev_info revs;
        struct strvec args = STRVEC_INIT;
-       struct process_commit_data pcd = { null_oid, oid, dst, &revs};
+       struct process_commit_data pcd = { *null_oid(), oid, dst, &revs};
 
        strvec_pushl(&args, "internal: The first arg is not parsed",
                     "--objects", "--in-commit-order", "--reverse", "HEAD",
index 617b9a4101dbd8255983664d403316a238e0c952..2d87c37a17674fda2fa7e90425164f69bcd78f41 100644 (file)
@@ -98,7 +98,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
 
        stuff_change(&revs->diffopt,
                     blob[0]->mode, canon_mode(st.st_mode),
-                    &blob[0]->item->oid, &null_oid,
+                    &blob[0]->item->oid, null_oid(),
                     1, 0,
                     blob[0]->path ? blob[0]->path : path,
                     path);
index 85a76e0ef8be683cfb7511b46192f90f6519ad6d..3c20f164f0f05178cb12d66102939fa8cc607457 100644 (file)
@@ -870,7 +870,7 @@ static void handle_tag(const char *name, struct tag *tag)
                                p = rewrite_commit((struct commit *)tagged);
                                if (!p) {
                                        printf("reset %s\nfrom %s\n\n",
-                                              name, oid_to_hex(&null_oid));
+                                              name, oid_to_hex(null_oid()));
                                        free(buf);
                                        return;
                                }
@@ -884,7 +884,7 @@ static void handle_tag(const char *name, struct tag *tag)
 
        if (tagged->type == OBJ_TAG) {
                printf("reset %s\nfrom %s\n\n",
-                      name, oid_to_hex(&null_oid));
+                      name, oid_to_hex(null_oid()));
        }
        skip_prefix(name, "refs/tags/", &name);
        printf("tag %s\n", name);
@@ -1016,7 +1016,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
                                 * it.
                                 */
                                printf("reset %s\nfrom %s\n\n",
-                                      name, oid_to_hex(&null_oid));
+                                      name, oid_to_hex(null_oid()));
                                continue;
                        }
 
@@ -1035,7 +1035,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
                                if (!reference_excluded_commits) {
                                        /* delete the ref */
                                        printf("reset %s\nfrom %s\n\n",
-                                              name, oid_to_hex(&null_oid));
+                                              name, oid_to_hex(null_oid()));
                                        continue;
                                }
                                /* set ref to commit using oid, not mark */
@@ -1146,7 +1146,7 @@ static void handle_deletes(void)
                        continue;
 
                printf("reset %s\nfrom %s\n\n",
-                               refspec->dst, oid_to_hex(&null_oid));
+                               refspec->dst, oid_to_hex(null_oid()));
        }
 }
 
index 5de725f904419e3db520cc9bedbfd38808b132f2..e0e326004e7a10740bd9dae89b726099aaf0d48a 100644 (file)
@@ -421,7 +421,7 @@ static int grep_submodule(struct grep_opt *opt,
        struct grep_opt subopt;
        int hit;
 
-       sub = submodule_from_path(superproject, &null_oid, path);
+       sub = submodule_from_path(superproject, null_oid(), path);
 
        if (!is_submodule_active(superproject, path))
                return 0;
index 60a2913a01e9d00bad828fa8eca57fdb18eff787..c589eb7f89171f7b7de3252da1afdccf7b238a28 100644 (file)
@@ -210,7 +210,7 @@ static void show_submodule(struct repository *superproject,
 {
        struct repository subrepo;
        const struct submodule *sub = submodule_from_path(superproject,
-                                                         &null_oid, path);
+                                                         null_oid(), path);
 
        if (repo_submodule_init(&subrepo, superproject, sub))
                return;
index 783b526f6e758a05a75524d86f91088bb7ba5b87..c9206b40ea2349d77c447436d7f1ff802b93038e 100644 (file)
@@ -485,7 +485,7 @@ static const char * const builtin_rebase_interactive_usage[] = {
 int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
 {
        struct rebase_options opts = REBASE_OPTIONS_INIT;
-       struct object_id squash_onto = null_oid;
+       struct object_id squash_onto = *null_oid();
        enum action command = ACTION_NONE;
        struct option options[] = {
                OPT_NEGBIT(0, "ff", &opts.flags, N_("allow fast-forward"),
@@ -1139,7 +1139,7 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
 
        merge_bases = get_merge_bases(onto, head);
        if (!merge_bases || merge_bases->next) {
-               oidcpy(merge_base, &null_oid);
+               oidcpy(merge_base, null_oid());
                goto done;
        }
 
index 6bc12c828aa3516b356c9eb0b42e1fe4fea03c97..a34742513aca7e771c60263ded17d24d0cdc9df5 100644 (file)
@@ -329,7 +329,7 @@ static void write_head_info(void)
        for_each_alternate_ref(show_one_alternate_ref, &seen);
        oidset_clear(&seen);
        if (!sent_capabilities)
-               show_ref("capabilities^{}", &null_oid);
+               show_ref("capabilities^{}", null_oid());
 
        advertise_shallow_grafts(1);
 
index 9d505a6329c8e2a61a91f27c84ee24f668bc688e..d55f6262e9c93be95112a88983eafe8826e5558c 100644 (file)
@@ -426,7 +426,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
                const struct cache_entry *ce = list.entries[i];
 
                if (ce_stage(ce))
-                       printf("%06o %s U\t", ce->ce_mode, oid_to_hex(&null_oid));
+                       printf("%06o %s U\t", ce->ce_mode,
+                              oid_to_hex(null_oid()));
                else
                        printf("%06o %s %d\t", ce->ce_mode,
                               oid_to_hex(&ce->oid), ce_stage(ce));
@@ -466,7 +467,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
 
        displaypath = get_submodule_displaypath(path, info->prefix);
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
 
        if (!sub)
                die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -623,7 +624,7 @@ static void init_submodule(const char *path, const char *prefix,
 
        displaypath = get_submodule_displaypath(path, prefix);
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
 
        if (!sub)
                die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -783,14 +784,14 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
        struct strbuf buf = STRBUF_INIT;
        const char *git_dir;
 
-       if (!submodule_from_path(the_repository, &null_oid, path))
+       if (!submodule_from_path(the_repository, null_oid(), path))
                die(_("no submodule mapping found in .gitmodules for path '%s'"),
                      path);
 
        displaypath = get_submodule_displaypath(path, prefix);
 
        if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
-               print_status(flags, 'U', path, &null_oid, displaypath);
+               print_status(flags, 'U', path, null_oid(), displaypath);
                goto cleanup;
        }
 
@@ -916,7 +917,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
        if (argc != 2)
                usage(_("git submodule--helper name <path>"));
 
-       sub = submodule_from_path(the_repository, &null_oid, argv[1]);
+       sub = submodule_from_path(the_repository, null_oid(), argv[1]);
 
        if (!sub)
                die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -1040,7 +1041,7 @@ static void generate_submodule_summary(struct summary_cb *info,
        char *errmsg = NULL;
        int total_commits = -1;
 
-       if (!info->cached && oideq(&p->oid_dst, &null_oid)) {
+       if (!info->cached && oideq(&p->oid_dst, null_oid())) {
                if (S_ISGITLINK(p->mod_dst)) {
                        struct ref_store *refs = get_submodule_ref_store(p->sm_path);
                        if (refs)
@@ -1177,7 +1178,7 @@ static void prepare_submodule_summary(struct summary_cb *info,
 
                if (info->for_status && p->status != 'A' &&
                    (sub = submodule_from_path(the_repository,
-                                              &null_oid, p->sm_path))) {
+                                              null_oid(), p->sm_path))) {
                        char *config_key = NULL;
                        const char *value;
                        int ignore_all = 0;
@@ -1373,7 +1374,7 @@ static void sync_submodule(const char *path, const char *prefix,
        if (!is_submodule_active(the_repository, path))
                return;
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
 
        if (sub && sub->url) {
                if (starts_with_dot_dot_slash(sub->url) ||
@@ -1525,7 +1526,7 @@ static void deinit_submodule(const char *path, const char *prefix,
        struct strbuf sb_config = STRBUF_INIT;
        char *sub_git_dir = xstrfmt("%s/.git", path);
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
 
        if (!sub || !sub->name)
                goto cleanup;
@@ -1925,7 +1926,7 @@ static void determine_submodule_update_strategy(struct repository *r,
                                                const char *update,
                                                struct submodule_update_strategy *out)
 {
-       const struct submodule *sub = submodule_from_path(r, &null_oid, path);
+       const struct submodule *sub = submodule_from_path(r, null_oid(), path);
        char *key;
        const char *val;
 
@@ -2077,7 +2078,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
                goto cleanup;
        }
 
-       sub = submodule_from_path(the_repository, &null_oid, ce->name);
+       sub = submodule_from_path(the_repository, null_oid(), ce->name);
 
        if (suc->recursive_prefix)
                displaypath = relative_path(suc->recursive_prefix,
@@ -2395,7 +2396,7 @@ static const char *remote_submodule_branch(const char *path)
        const char *branch = NULL;
        char *key;
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
        if (!sub)
                return NULL;
 
@@ -2533,7 +2534,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
 
        path = argv[1];
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
        if (!sub)
                BUG("We could get the submodule handle before?");
 
index 6ac90dc5f7a5206999dc7e3f463fac83304d2fca..4a9466295ba10de5752cca92fa08b1a28461777b 100644 (file)
@@ -421,7 +421,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
                         * has not been resolved yet.
                         */
                        oidclr(&obj_list[nr].oid);
-                       add_delta_to_list(nr, &null_oid, base_offset, delta_data, delta_size);
+                       add_delta_to_list(nr, null_oid(), base_offset,
+                                         delta_data, delta_size);
                        return;
                }
        }
index 87714534938189f8dc25ba112bb660ee5e7f60ee..f754978e47a409771fb5b37972bf3257098e54ed 100644 (file)
@@ -331,7 +331,7 @@ static int add_worktree(const char *path, const char *refname,
         */
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
-       write_file(sb.buf, "%s", oid_to_hex(&null_oid));
+       write_file(sb.buf, "%s", oid_to_hex(null_oid()));
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
        write_file(sb.buf, "../..");
@@ -394,7 +394,7 @@ done:
                        cp.argv = NULL;
                        cp.trace2_hook_name = "post-checkout";
                        strvec_pushl(&cp.args, absolute_path(hook),
-                                    oid_to_hex(&null_oid),
+                                    oid_to_hex(null_oid()),
                                     oid_to_hex(&commit->object.oid),
                                     "1", NULL);
                        ret = run_command(&cp);
index 06635f91bc21a54a5e7bfa4355c2d8e4b536f257..7d925ce9ce44c8de5915a706c081466400b9cbe9 100644 (file)
@@ -1068,7 +1068,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                                                   &result_size, NULL, NULL);
                } else if (textconv) {
                        struct diff_filespec *df = alloc_filespec(elem->path);
-                       fill_filespec(df, &null_oid, 0, st.st_mode);
+                       fill_filespec(df, null_oid(), 0, st.st_mode);
                        result_size = fill_textconv(opt->repo, textconv, df, &result);
                        free_filespec(df);
                } else if (0 <= (fd = open(elem->path, O_RDONLY))) {
index 40b5c15f811305648e22e0c2db55fbd1998cf211..70b13389ba5f706045b2b77114fa6f4797b58d28 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -254,7 +254,7 @@ static int process_dummy_ref(const struct packet_reader *reader)
                return 0;
        name++;
 
-       return oideq(&null_oid, &oid) && !strcmp(name, "capabilities^{}");
+       return oideq(null_oid(), &oid) && !strcmp(name, "capabilities^{}");
 }
 
 static void check_no_capabilities(const char *line, int len)
index e5a58c9259cfdfac91090e2baabd45ccf1945960..c2ac9250fe92c21f1678ffd70e7a652c83126007 100644 (file)
@@ -232,7 +232,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                   ce_intent_to_add(ce)) {
                                newmode = ce_mode_from_stat(ce, st.st_mode);
                                diff_addremove(&revs->diffopt, '+', newmode,
-                                              &null_oid, 0, ce->name, 0);
+                                              null_oid(), 0, ce->name, 0);
                                continue;
                        }
 
@@ -249,7 +249,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                }
                oldmode = ce->ce_mode;
                old_oid = &ce->oid;
-               new_oid = changed ? &null_oid : &ce->oid;
+               new_oid = changed ? null_oid() : &ce->oid;
                diff_change(&revs->diffopt, oldmode, newmode,
                            old_oid, new_oid,
                            !is_null_oid(old_oid),
@@ -307,7 +307,7 @@ static int get_stat_data(const struct index_state *istate,
                                                    0, dirty_submodule);
                if (changed) {
                        mode = ce_mode_from_stat(ce, st.st_mode);
-                       oid = &null_oid;
+                       oid = null_oid();
                }
        }
 
index 7814eabfe0289125fd50d4f3b0bba06fe08ccac4..308922e2b331362e11ac1c86a0e28802c960b8cf 100644 (file)
@@ -83,7 +83,7 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode)
        if (!name)
                name = "/dev/null";
        s = alloc_filespec(name);
-       fill_filespec(s, &null_oid, 0, mode);
+       fill_filespec(s, null_oid(), 0, mode);
        if (name == file_from_standard_input)
                populate_from_stdin(s);
        return s;
diff --git a/diff.c b/diff.c
index 97c62f47dfbe607483a9a76461773c47ee1ad19a..7c730fe64492d3b87cf6a9bb5a65d7b798193054 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4190,7 +4190,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
                                die_errno("readlink(%s)", name);
                        prep_temp_blob(r->index, name, temp, sb.buf, sb.len,
                                       (one->oid_valid ?
-                                       &one->oid : &null_oid),
+                                       &one->oid : null_oid()),
                                       (one->oid_valid ?
                                        one->mode : S_IFLNK));
                        strbuf_release(&sb);
@@ -4199,7 +4199,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
                        /* we can borrow from the file in the work tree */
                        temp->name = name;
                        if (!one->oid_valid)
-                               oid_to_hex_r(temp->hex, &null_oid);
+                               oid_to_hex_r(temp->hex, null_oid());
                        else
                                oid_to_hex_r(temp->hex, &one->oid);
                        /* Even though we may sometimes borrow the
diff --git a/dir.c b/dir.c
index 813dd7ba53723442dc54d095d38f1930a869a808..037474337fda15b9b3695c2f49fee33e70ad4a41 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -3556,7 +3556,7 @@ static void connect_wt_gitdir_in_nested(const char *sub_worktree,
                         */
                        i++;
 
-               sub = submodule_from_path(&subrepo, &null_oid, ce->name);
+               sub = submodule_from_path(&subrepo, null_oid(), ce->name);
                if (!sub || !is_submodule_active(&subrepo, ce->name))
                        /* .gitmodules broken or inactive sub */
                        continue;
diff --git a/grep.c b/grep.c
index c5c348be55ddf062a538522a2a86f31d2dcc0c0d..8f91af1cb006f95ee25668f0c080ec09c745c141 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1494,7 +1494,7 @@ static int fill_textconv_grep(struct repository *r,
                fill_filespec(df, gs->identifier, 1, 0100644);
                break;
        case GREP_SOURCE_FILE:
-               fill_filespec(df, &null_oid, 0, 0100644);
+               fill_filespec(df, null_oid(), 0, 0100644);
                break;
        default:
                BUG("attempt to textconv something without a path?");
diff --git a/hash.h b/hash.h
index 0e85e448ed4206a85951ff491f2305b93e35910e..2986f991c66f5bf258c63f2b9ea842b61798538d 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -170,6 +170,9 @@ struct git_hash_algo {
 
        /* The OID of the empty blob. */
        const struct object_id *empty_blob;
+
+       /* The all-zeros OID. */
+       const struct object_id *null_oid;
 };
 extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
 
@@ -190,7 +193,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
 
 #define the_hash_algo the_repository->hash_algo
 
-extern const struct object_id null_oid;
+const struct object_id *null_oid(void);
 
 static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
 {
@@ -246,7 +249,7 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
 
 static inline int is_null_oid(const struct object_id *oid)
 {
-       return oideq(oid, &null_oid);
+       return oideq(oid, null_oid());
 }
 
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
index f3178a66a95bb15915eaca9713dc442dd7397984..7b823786c2cba7733df8c2977b4a3d6c0478b459 100644 (file)
@@ -419,7 +419,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 {
        const char *extra_headers = opt->extra_headers;
        const char *name = oid_to_hex(opt->zero_commit ?
-                                     &null_oid : &commit->object.oid);
+                                     null_oid() : &commit->object.oid);
 
        *need_8bit_cte_p = 0; /* unknown */
 
index 5e118a85ee042a45ef3cb628289b96db010fc52d..3e552cfd21b4427158c8c9c8103fdd888ef2c44f 100644 (file)
@@ -1291,7 +1291,7 @@ static int handle_content_merge(struct merge_options *opt,
                two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
 
                merge_status = merge_3way(opt, path,
-                                         two_way ? &null_oid : &o->oid,
+                                         two_way ? null_oid() : &o->oid,
                                          &a->oid, &b->oid,
                                          pathnames, extra_marker_size,
                                          &result_buf);
@@ -1313,7 +1313,7 @@ static int handle_content_merge(struct merge_options *opt,
        } else if (S_ISGITLINK(a->mode)) {
                int two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
                clean = merge_submodule(opt, pathnames[0],
-                                       two_way ? &null_oid : &o->oid,
+                                       two_way ? null_oid() : &o->oid,
                                        &a->oid, &b->oid, &result->oid);
                if (opt->priv->call_depth && two_way && !clean) {
                        result->mode = o->mode;
@@ -2123,7 +2123,7 @@ static int process_renames(struct merge_options *opt,
                        if (type_changed) {
                                /* rename vs. typechange */
                                /* Mark the original as resolved by removal */
-                               memcpy(&oldinfo->stages[0].oid, &null_oid,
+                               memcpy(&oldinfo->stages[0].oid, null_oid(),
                                       sizeof(oldinfo->stages[0].oid));
                                oldinfo->stages[0].mode = 0;
                                oldinfo->filemask &= 0x06;
@@ -2762,7 +2762,7 @@ static void process_entry(struct merge_options *opt,
                        if (ci->filemask & (1 << i))
                                continue;
                        ci->stages[i].mode = 0;
-                       oidcpy(&ci->stages[i].oid, &null_oid);
+                       oidcpy(&ci->stages[i].oid, null_oid());
                }
        } else if (ci->df_conflict && ci->merged.result.mode != 0) {
                /*
@@ -2808,7 +2808,7 @@ static void process_entry(struct merge_options *opt,
                                continue;
                        /* zero out any entries related to directories */
                        new_ci->stages[i].mode = 0;
-                       oidcpy(&new_ci->stages[i].oid, &null_oid);
+                       oidcpy(&new_ci->stages[i].oid, null_oid());
                }
 
                /*
@@ -2909,11 +2909,11 @@ static void process_entry(struct merge_options *opt,
                        new_ci->merged.result.mode = ci->stages[2].mode;
                        oidcpy(&new_ci->merged.result.oid, &ci->stages[2].oid);
                        new_ci->stages[1].mode = 0;
-                       oidcpy(&new_ci->stages[1].oid, &null_oid);
+                       oidcpy(&new_ci->stages[1].oid, null_oid());
                        new_ci->filemask = 5;
                        if ((S_IFMT & b_mode) != (S_IFMT & o_mode)) {
                                new_ci->stages[0].mode = 0;
-                               oidcpy(&new_ci->stages[0].oid, &null_oid);
+                               oidcpy(&new_ci->stages[0].oid, null_oid());
                                new_ci->filemask = 4;
                        }
 
@@ -2921,11 +2921,11 @@ static void process_entry(struct merge_options *opt,
                        ci->merged.result.mode = ci->stages[1].mode;
                        oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
                        ci->stages[2].mode = 0;
-                       oidcpy(&ci->stages[2].oid, &null_oid);
+                       oidcpy(&ci->stages[2].oid, null_oid());
                        ci->filemask = 3;
                        if ((S_IFMT & a_mode) != (S_IFMT & o_mode)) {
                                ci->stages[0].mode = 0;
-                               oidcpy(&ci->stages[0].oid, &null_oid);
+                               oidcpy(&ci->stages[0].oid, null_oid());
                                ci->filemask = 2;
                        }
 
@@ -3042,7 +3042,7 @@ static void process_entry(struct merge_options *opt,
                /* Deleted on both sides */
                ci->merged.is_null = 1;
                ci->merged.result.mode = 0;
-               oidcpy(&ci->merged.result.oid, &null_oid);
+               oidcpy(&ci->merged.result.oid, null_oid());
                ci->merged.clean = !ci->path_conflict;
        }
 
index ed31f9496cbcb2e71f41fde922075dc2684c70f2..03f5c0769ecffc280fa8b407d46b3ac482dd3bd5 100644 (file)
@@ -486,7 +486,7 @@ static int get_tree_entry_if_blob(struct repository *r,
 
        ret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode);
        if (S_ISDIR(dfs->mode)) {
-               oidcpy(&dfs->oid, &null_oid);
+               oidcpy(&dfs->oid, null_oid());
                dfs->mode = 0;
        }
        return ret;
@@ -1604,7 +1604,7 @@ static int handle_file_collision(struct merge_options *opt,
 
        /* Store things in diff_filespecs for functions that need it */
        null.path = (char *)collide_path;
-       oidcpy(&null.oid, &null_oid);
+       oidcpy(&null.oid, null_oid());
        null.mode = 0;
 
        if (merge_mode_and_contents(opt, &null, a, b, collide_path,
@@ -2789,11 +2789,11 @@ static int process_renames(struct merge_options *opt,
                        dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
                        try_merge = 0;
 
-                       if (oideq(&src_other.oid, &null_oid) &&
+                       if (oideq(&src_other.oid, null_oid()) &&
                            ren1->dir_rename_original_type == 'A') {
                                setup_rename_conflict_info(RENAME_VIA_DIR,
                                                           opt, ren1, NULL);
-                       } else if (oideq(&src_other.oid, &null_oid)) {
+                       } else if (oideq(&src_other.oid, null_oid())) {
                                setup_rename_conflict_info(RENAME_DELETE,
                                                           opt, ren1, NULL);
                        } else if ((dst_other.mode == ren1->pair->two->mode) &&
@@ -2812,7 +2812,7 @@ static int process_renames(struct merge_options *opt,
                                                      1, /* update_cache */
                                                      0  /* update_wd    */))
                                        clean_merge = -1;
-                       } else if (!oideq(&dst_other.oid, &null_oid)) {
+                       } else if (!oideq(&dst_other.oid, null_oid())) {
                                /*
                                 * Probably not a clean merge, but it's
                                 * premature to set clean_merge to 0 here,
index d2771fa3d43ced4980a9c94af2ee8d5f92caa168..53c587f7505226790683f52b1eff585e2664eb8b 100644 (file)
@@ -600,7 +600,7 @@ int notes_merge(struct notes_merge_options *o,
        /* Find merge bases */
        bases = get_merge_bases(local, remote);
        if (!bases) {
-               base_oid = &null_oid;
+               base_oid = null_oid();
                base_tree_oid = the_hash_algo->empty_tree;
                if (o->verbosity >= 4)
                        printf("No merge base found; doing history-less merge\n");
diff --git a/notes.c b/notes.c
index 135ea13ba142ee657795e27f7e1db6e4d697eecf..f87dac40684030a70566a618ee3dbcedd97bc641 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1327,7 +1327,7 @@ int copy_note(struct notes_tree *t,
        if (note)
                return add_note(t, to_obj, note, combine_notes);
        else if (existing_note)
-               return add_note(t, to_obj, &null_oid, combine_notes);
+               return add_note(t, to_obj, null_oid(), combine_notes);
 
        return 0;
 }
index d4ba0c4a4fed244405c6aa9ce31bc9ac3a137c9b..884855b9df46be2b0551204948508a95d480b185 100644 (file)
@@ -55,7 +55,6 @@
        "\x6f\xe1\x41\xf7\x74\x91\x20\xa3\x03\x72" \
        "\x18\x13"
 
-const struct object_id null_oid;
 static const struct object_id empty_tree_oid = {
        .hash = EMPTY_TREE_SHA1_BIN_LITERAL,
        .algo = GIT_HASH_SHA1,
@@ -64,6 +63,10 @@ static const struct object_id empty_blob_oid = {
        .hash = EMPTY_BLOB_SHA1_BIN_LITERAL,
        .algo = GIT_HASH_SHA1,
 };
+static const struct object_id null_oid_sha1 = {
+       .hash = {0},
+       .algo = GIT_HASH_SHA1,
+};
 static const struct object_id empty_tree_oid_sha256 = {
        .hash = EMPTY_TREE_SHA256_BIN_LITERAL,
        .algo = GIT_HASH_SHA256,
@@ -72,6 +75,10 @@ static const struct object_id empty_blob_oid_sha256 = {
        .hash = EMPTY_BLOB_SHA256_BIN_LITERAL,
        .algo = GIT_HASH_SHA256,
 };
+static const struct object_id null_oid_sha256 = {
+       .hash = {0},
+       .algo = GIT_HASH_SHA256,
+};
 
 static void git_hash_sha1_init(git_hash_ctx *ctx)
 {
@@ -172,6 +179,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
                git_hash_unknown_final_oid,
                NULL,
                NULL,
+               NULL,
        },
        {
                "sha1",
@@ -187,6 +195,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
                git_hash_sha1_final_oid,
                &empty_tree_oid,
                &empty_blob_oid,
+               &null_oid_sha1,
        },
        {
                "sha256",
@@ -202,9 +211,15 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
                git_hash_sha256_final_oid,
                &empty_tree_oid_sha256,
                &empty_blob_oid_sha256,
+               &null_oid_sha256,
        }
 };
 
+const struct object_id *null_oid(void)
+{
+       return the_hash_algo->null_oid;
+}
+
 const char *empty_tree_oid_hex(void)
 {
        static char buf[GIT_MAX_HEXSZ + 1];
index 4542d4d3f929f51ce242e6463362307df3ec8d2d..3c811e1e4a7e135cb302b807d15725816730f3b3 100644 (file)
@@ -140,7 +140,7 @@ int parse_opt_object_id(const struct option *opt, const char *arg, int unset)
        struct object_id *target = opt->value;
 
        if (unset) {
-               *target = null_oid;
+               oidcpy(target, null_oid());
                return 0;
        }
        if (!arg)
index 116fb0735c6f4908b126d8471c9a8a52be9ccc21..1a4471fe4ccabf7cf8f6179955895c2d2387cfb9 100644 (file)
@@ -445,7 +445,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
 {
        struct diff_filespec *spec = alloc_filespec(name);
 
-       fill_filespec(spec, &null_oid, 0, 0100644);
+       fill_filespec(spec, null_oid(), 0, 0100644);
        spec->data = (char *)p;
        spec->size = strlen(p);
        spec->should_munmap = 0;
diff --git a/refs.c b/refs.c
index 261fd82beb98fdfcfc641fa7605d37b86aac2184..996063fdf48c6eb1114fab5c99c27503ddd1fb37 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1107,7 +1107,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
        if (!new_oid || is_null_oid(new_oid))
                BUG("create called without valid new_oid");
        return ref_transaction_update(transaction, refname, new_oid,
-                                     &null_oid, flags, msg, err);
+                                     null_oid(), flags, msg, err);
 }
 
 int ref_transaction_delete(struct ref_transaction *transaction,
@@ -1119,7 +1119,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
        if (old_oid && is_null_oid(old_oid))
                BUG("delete called with old_oid set to zeros");
        return ref_transaction_update(transaction, refname,
-                                     &null_oid, old_oid,
+                                     null_oid(), old_oid,
                                      flags, msg, err);
 }
 
index 922e64fa6ad91bef44aa714e479c9281dce4b6c9..2665f943095c93171cc3bf7db80e6e345a9ba681 100644 (file)
@@ -243,7 +243,7 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
        struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
        int res = 0;
 
-       oidcpy(oid, &null_oid);
+       oidcpy(oid, null_oid());
        res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,
                                            type);
 
index 119972ee16f89f629e96b552e520f0b8190e54a7..3f29f8c1435c94c63f18007c7fbcdc78b600856b 100644 (file)
@@ -1084,7 +1084,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
        ref_transaction_add_update(
                        transaction, r->name,
                        REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING,
-                       &null_oid, &r->oid, NULL);
+                       null_oid(), &r->oid, NULL);
        if (ref_transaction_commit(transaction, &err))
                goto cleanup;
 
diff --git a/reset.c b/reset.c
index 2f4fbd07c54b59f71c92391a601d1ec9fe05ce7d..4bea758053bbea3cb68aba7662d3ad92ac81ca43 100644 (file)
--- a/reset.c
+++ b/reset.c
@@ -128,7 +128,7 @@ reset_head_refs:
        }
        if (run_hook)
                run_hook_le(NULL, "post-checkout",
-                           oid_to_hex(orig ? orig : &null_oid),
+                           oid_to_hex(orig ? orig : null_oid()),
                            oid_to_hex(oid), "1", NULL);
 
 leave_reset_head:
index fd183b5593bcc1c3558350d9e9d12118afdf6417..dbee779243ed437fa0064c0312c1088c7b2260e2 100644 (file)
@@ -524,7 +524,7 @@ static int fast_forward_to(struct repository *r,
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD",
                                   to, unborn && !is_rebase_i(opts) ?
-                                  &null_oid : from,
+                                  null_oid() : from,
                                   0, sb.buf, &err) ||
            ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
@@ -1131,7 +1131,7 @@ int update_head_with_reflog(const struct commit *old_head,
        transaction = ref_transaction_begin(err);
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD", new_head,
-                                  old_head ? &old_head->object.oid : &null_oid,
+                                  old_head ? &old_head->object.oid : null_oid(),
                                   0, sb.buf, err) ||
            ref_transaction_commit(transaction, err)) {
                ret = -1;
index f50250556698231762092f4e4b6be68800c2089c..2026120fb3891ba53a8bb676e2da5a6248984cf7 100644 (file)
@@ -671,7 +671,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
 
        parameter.cache = repo->submodule_cache;
        parameter.treeish_name = NULL;
-       parameter.gitmodules_oid = &null_oid;
+       parameter.gitmodules_oid = null_oid();
        parameter.overwrite = 1;
 
        return parse_config(var, value, &parameter);
index 9767ba9893cc98a538182a82ec8e9929ce8b2db4..7eeaf7d20309cc775d170aaa45bb3ec8fc64bbfb 100644 (file)
@@ -113,7 +113,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
        if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
-       submodule = submodule_from_path(the_repository, &null_oid, oldpath);
+       submodule = submodule_from_path(the_repository, null_oid(), oldpath);
        if (!submodule || !submodule->name) {
                warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
                return -1;
@@ -142,7 +142,7 @@ int remove_path_from_gitmodules(const char *path)
        if (is_gitmodules_unmerged(the_repository->index))
                die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
-       submodule = submodule_from_path(the_repository, &null_oid, path);
+       submodule = submodule_from_path(the_repository, null_oid(), path);
        if (!submodule || !submodule->name) {
                warning(_("Could not find section in .gitmodules where path=%s"), path);
                return -1;
@@ -188,7 +188,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
                                             const char *path)
 {
        const struct submodule *submodule = submodule_from_path(the_repository,
-                                                               &null_oid, path);
+                                                               null_oid(),
+                                                               path);
        if (submodule) {
                const char *ignore;
                char *key;
@@ -244,7 +245,7 @@ int is_submodule_active(struct repository *repo, const char *path)
        const struct string_list *sl;
        const struct submodule *module;
 
-       module = submodule_from_path(repo, &null_oid, path);
+       module = submodule_from_path(repo, null_oid(), path);
 
        /* early return if there isn't a path->module mapping */
        if (!module)
@@ -745,7 +746,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
        if (!should_update_submodules())
                return NULL;
 
-       return submodule_from_path(the_repository, &null_oid, ce->name);
+       return submodule_from_path(the_repository, null_oid(), ce->name);
 }
 
 static struct oid_array *submodule_commits(struct string_list *submodules,
@@ -1037,7 +1038,7 @@ int find_unpushed_submodules(struct repository *r,
                const struct submodule *submodule;
                const char *path = NULL;
 
-               submodule = submodule_from_name(r, &null_oid, name->string);
+               submodule = submodule_from_name(r, null_oid(), name->string);
                if (submodule)
                        path = submodule->path;
                else
@@ -1224,7 +1225,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
                const struct submodule *submodule;
                const char *path = NULL;
 
-               submodule = submodule_from_name(r, &null_oid, name->string);
+               submodule = submodule_from_name(r, null_oid(), name->string);
                if (submodule)
                        path = submodule->path;
                else
@@ -1361,7 +1362,7 @@ static struct fetch_task *fetch_task_create(struct repository *r,
        struct fetch_task *task = xmalloc(sizeof(*task));
        memset(task, 0, sizeof(*task));
 
-       task->sub = submodule_from_path(r, &null_oid, path);
+       task->sub = submodule_from_path(r, null_oid(), path);
        if (!task->sub) {
                /*
                 * No entry in .gitmodules? Technically not a submodule,
@@ -1917,7 +1918,7 @@ int submodule_move_head(const char *path,
        if (old_head && !is_submodule_populated_gently(path, error_code_ptr))
                return 0;
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
 
        if (!sub)
                BUG("could not get submodule information for '%s'", path);
@@ -2076,7 +2077,7 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 
        real_old_git_dir = real_pathdup(old_git_dir, 1);
 
-       sub = submodule_from_path(the_repository, &null_oid, path);
+       sub = submodule_from_path(the_repository, null_oid(), path);
        if (!sub)
                die(_("could not lookup name for submodule '%s'"), path);
 
@@ -2135,7 +2136,7 @@ void absorb_git_dir_into_superproject(const char *path,
                * superproject did not rewrite the git file links yet,
                * fix it now.
                */
-               sub = submodule_from_path(the_repository, &null_oid, path);
+               sub = submodule_from_path(the_repository, null_oid(), path);
                if (!sub)
                        die(_("could not lookup name for submodule '%s'"), path);
                connect_work_tree_and_git_dir(path,
@@ -2283,7 +2284,8 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
                strbuf_addstr(buf, git_dir);
        }
        if (!is_git_directory(buf->buf)) {
-               sub = submodule_from_path(the_repository, &null_oid, submodule);
+               sub = submodule_from_path(the_repository, null_oid(),
+                                         submodule);
                if (!sub) {
                        ret = -1;
                        goto cleanup;
index c5fd4527dccba2803d40e440bf7db1b331f5a0c2..e3f11ff5a78fc15b36b22efe05c90ebdac8920f0 100644 (file)
@@ -18,7 +18,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
 
        setup_git_directory();
 
-       sub = submodule_from_path(the_repository, &null_oid, argv[1]);
+       sub = submodule_from_path(the_repository, null_oid(), argv[1]);
        if (repo_submodule_init(&subrepo, the_repository, sub)) {
                die_usage(argv, "Submodule not found.");
        }
index 7cebbb327e273aadd5106ddf2140637d39f1d4a4..1572615bd9a7eeac84aef5a41f0e2443cae6417a 100644 (file)
@@ -161,7 +161,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
        memcpy(p->path + base->len, path, pathlen);
        p->path[len] = 0;
        p->mode = mode;
-       oidcpy(&p->oid, oid ? oid : &null_oid);
+       oidcpy(&p->oid, oid ? oid : null_oid());
 
        return p;
 }
@@ -243,7 +243,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
                                mode_i = tp[i].entry.mode;
                        }
                        else {
-                               oid_i = &null_oid;
+                               oid_i = null_oid();
                                mode_i = 0;
                        }
 
index 1aed68c43c264c360de8282485c6c93a5dc43d08..7603c1b198e76ca59fccd9d3ddaf0c219bee2fc4 100644 (file)
@@ -1687,10 +1687,10 @@ void wt_status_get_state(struct repository *r,
        if (!sequencer_get_last_command(r, &action)) {
                if (action == REPLAY_PICK) {
                        state->cherry_pick_in_progress = 1;
-                       oidcpy(&state->cherry_pick_head_oid, &null_oid);
+                       oidcpy(&state->cherry_pick_head_oid, null_oid());
                } else {
                        state->revert_in_progress = 1;
-                       oidcpy(&state->revert_head_oid, &null_oid);
+                       oidcpy(&state->revert_head_oid, null_oid());
                }
        }
        if (get_detached_from)
index 4d20069302b25a133869380bd685e921ddc0bacc..609615db2cd68f49524eea191e4e755bea80783d 100644 (file)
@@ -172,7 +172,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
        unsigned long size;
        enum object_type type;
 
-       if (oideq(oid, &null_oid)) {
+       if (oideq(oid, null_oid())) {
                ptr->ptr = xstrdup("");
                ptr->size = 0;
                return;