]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: require hash algorithm in `oidread()` and `oidclr()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 14 Jun 2024 06:49:54 +0000 (08:49 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2024 17:26:32 +0000 (10:26 -0700)
Both `oidread()` and `oidclr()` 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>
48 files changed:
apply.c
blame.c
builtin/am.c
builtin/fast-export.c
builtin/fast-import.c
builtin/fetch-pack.c
builtin/index-pack.c
builtin/log.c
builtin/merge.c
builtin/notes.c
builtin/pack-objects.c
builtin/pack-redundant.c
builtin/patch-id.c
builtin/pull.c
builtin/receive-pack.c
builtin/replace.c
builtin/rm.c
builtin/tag.c
builtin/unpack-objects.c
builtin/update-ref.c
cache-tree.c
commit-graph.c
diff-lib.c
diff.c
dir.c
hash-ll.h
hash.h
http-push.c
http-walker.c
match-trees.c
midx.c
notes-merge.c
notes.c
object-file-convert.c
object-file.c
packfile.c
read-cache.c
refs.c
refs/files-backend.c
refs/packed-backend.c
refs/reftable-backend.c
remote.c
resolve-undo.c
sequencer.c
split-index.c
submodule-config.c
t/helper/test-submodule-config.c
tree-walk.c

diff --git a/apply.c b/apply.c
index 901b67e6255af4174a1e5a00cf01de4d2545d659..528939abb6d6054495cc7ad5c75a2bc39772feb2 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
        if (status) {
                patch->conflicted_threeway = 1;
                if (patch->is_new)
-                       oidclr(&patch->threeway_stage[0]);
+                       oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
                else
                        oidcpy(&patch->threeway_stage[0], &pre_oid);
                oidcpy(&patch->threeway_stage[1], &our_oid);
diff --git a/blame.c b/blame.c
index 33586b97772c2b699ea0aa555a4d6501c1681b70..a80f5e2e61f57cb7ce09c10c40728fe8fb3332cb 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
                goto error_out;
        return 0;
  error_out:
-       oidclr(&origin->blob_oid);
+       oidclr(&origin->blob_oid, the_repository->hash_algo);
        origin->mode = S_IFINVALID;
        return -1;
 }
index 36839029d201c382e3bc878ace99bcd73ff17e28..45c305ec86e17739956ff11ccdfe54fdd618cbd8 100644 (file)
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
        read_commit_msg(state);
 
        if (read_state_file(&sb, state, "original-commit", 1) < 0)
-               oidclr(&state->orig_commit);
+               oidclr(&state->orig_commit, the_repository->hash_algo);
        else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
                die(_("could not parse %s"), am_path(state, "original-commit"));
 
@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
        unlink(am_path(state, "author-script"));
        unlink(am_path(state, "final-commit"));
 
-       oidclr(&state->orig_commit);
+       oidclr(&state->orig_commit, the_repository->hash_algo);
        unlink(am_path(state, "original-commit"));
        refs_delete_ref(get_main_ref_store(the_repository), NULL,
                        "REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
                if (get_oid_hex(sb.buf, &abort_safety))
                        die(_("could not parse %s"), am_path(state, "abort-safety"));
        } else
-               oidclr(&abort_safety);
+               oidclr(&abort_safety, the_repository->hash_algo);
        strbuf_release(&sb);
 
        if (repo_get_oid(the_repository, "HEAD", &head))
-               oidclr(&head);
+               oidclr(&head, the_repository->hash_algo);
 
        if (oideq(&head, &abort_safety))
                return 1;
index 4693d18cc94f09ecf760c4662753583052ebc4c6..4b6e8c6832b84123003322995dcff1452a25bd17 100644 (file)
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
        struct object_id oid;
        char *hex = xmallocz(GIT_MAX_HEXSZ);
 
-       oidclr(&oid);
+       oidclr(&oid, the_repository->hash_algo);
        put_be32(oid.hash + hashsz - 4, counter++);
        return oid_to_hex_r(hex, &oid);
 }
index d1c0243d04ecb05c4c618c997ac0cb76f8514823..12543488f3d48d69bffd8babfecb6a2dc227e9db 100644 (file)
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
                e->versions[0].mode = e->versions[1].mode;
                e->name = to_atom(c, strlen(c));
                c += e->name->str_len + 1;
-               oidread(&e->versions[0].oid, (unsigned char *)c);
-               oidread(&e->versions[1].oid, (unsigned char *)c);
+               oidread(&e->versions[0].oid, (unsigned char *)c,
+                       the_repository->hash_algo);
+               oidread(&e->versions[1].oid, (unsigned char *)c,
+                       the_repository->hash_algo);
                c += the_hash_algo->rawsz;
        }
        free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
 {
        if (!S_ISDIR(mode))
                die("Root cannot be a non-directory");
-       oidclr(&root->versions[0].oid);
+       oidclr(&root->versions[0].oid, the_repository->hash_algo);
        oidcpy(&root->versions[1].oid, oid);
        if (root->tree)
                release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
                                if (S_ISDIR(e->versions[0].mode))
                                        e->versions[0].mode |= NO_DELTA;
 
-                               oidclr(&root->versions[1].oid);
+                               oidclr(&root->versions[1].oid, the_repository->hash_algo);
                                return 1;
                        }
                        if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
                        if (!e->tree)
                                load_tree(e);
                        if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
-                               oidclr(&root->versions[1].oid);
+                               oidclr(&root->versions[1].oid, the_repository->hash_algo);
                                return 1;
                        }
                        return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
        e = new_tree_entry();
        e->name = to_atom(p, n);
        e->versions[0].mode = 0;
-       oidclr(&e->versions[0].oid);
+       oidclr(&e->versions[0].oid, the_repository->hash_algo);
        t->entries[t->entry_count++] = e;
        if (*slash1) {
                e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
                e->versions[1].mode = mode;
                oidcpy(&e->versions[1].oid, oid);
        }
-       oidclr(&root->versions[1].oid);
+       oidclr(&root->versions[1].oid, the_repository->hash_algo);
        return 1;
 }
 
@@ -1523,7 +1525,8 @@ static int tree_content_remove(
                        if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
                                for (n = 0; n < e->tree->entry_count; n++) {
                                        if (e->tree->entries[n]->versions[1].mode) {
-                                               oidclr(&root->versions[1].oid);
+                                               oidclr(&root->versions[1].oid,
+                                                      the_repository->hash_algo);
                                                return 1;
                                        }
                                }
@@ -1542,8 +1545,8 @@ del_entry:
                release_tree_content_recursive(e->tree);
        e->tree = NULL;
        e->versions[1].mode = 0;
-       oidclr(&e->versions[1].oid);
-       oidclr(&root->versions[1].oid);
+       oidclr(&e->versions[1].oid, the_repository->hash_algo);
+       oidclr(&root->versions[1].oid, the_repository->hash_algo);
        return 1;
 }
 
@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
                return 0;
        }
        if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
-               oidclr(&old_oid);
+               oidclr(&old_oid, the_repository->hash_algo);
        if (!force_update && !is_null_oid(&old_oid)) {
                struct commit *old_cmit, *new_cmit;
                int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
 static void file_change_deleteall(struct branch *b)
 {
        release_tree_content_recursive(b->branch_tree.tree);
-       oidclr(&b->branch_tree.versions[0].oid);
-       oidclr(&b->branch_tree.versions[1].oid);
+       oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+       oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
        load_tree(&b->branch_tree);
        b->num_notes = 0;
 }
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
 static void parse_from_existing(struct branch *b)
 {
        if (is_null_oid(&b->oid)) {
-               oidclr(&b->branch_tree.versions[0].oid);
-               oidclr(&b->branch_tree.versions[1].oid);
+               oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+               oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
        } else {
                unsigned long size;
                char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
 
        b = lookup_branch(arg);
        if (b) {
-               oidclr(&b->oid);
-               oidclr(&b->branch_tree.versions[0].oid);
-               oidclr(&b->branch_tree.versions[1].oid);
+               oidclr(&b->oid, the_repository->hash_algo);
+               oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
+               oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
                if (b->branch_tree.tree) {
                        release_tree_content_recursive(b->branch_tree.tree);
                        b->branch_tree.tree = NULL;
index 44c05ee86cc7048e72e455f4c2a28a1d42a1f7fa..af329e8d5cf6519a5d583f746f6e9d1e71186c6e 100644 (file)
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
                        ; /* <oid>, leave oid as name */
                } else {
                        /* <ref>, clear cruft from oid */
-                       oidclr(&oid);
+                       oidclr(&oid, the_repository->hash_algo);
                }
        } else {
                /* <ref>, clear cruft from get_oid_hex */
-               oidclr(&oid);
+               oidclr(&oid, the_repository->hash_algo);
        }
 
        ref = alloc_ref(name);
index ea727fba165540c1ef60e3901a54101b55c8dbda..fd968d673d22d8593e0d18c32b41ad3760d0ba3e 100644 (file)
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
 
        switch (obj->type) {
        case OBJ_REF_DELTA:
-               oidread(ref_oid, fill(the_hash_algo->rawsz));
+               oidread(ref_oid, fill(the_hash_algo->rawsz),
+                       the_repository->hash_algo);
                use(the_hash_algo->rawsz);
                break;
        case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
        obj[1].idx.offset += write_compressed(f, buf, size);
        obj[0].idx.crc32 = crc32_end(f);
        hashflush(f);
-       oidread(&obj->idx.oid, sha1);
+       oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
        return obj;
 }
 
index 78a247d8a94d077a4bd829b65228afb64e03e6dc..ccbda8a0052e555da1a712cee31628918e7cff47 100644 (file)
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
        free(bases->patch_id);
        bases->nr_patch_id = 0;
        bases->alloc_patch_id = 0;
-       oidclr(&bases->base_commit);
+       oidclr(&bases->base_commit, the_repository->hash_algo);
 }
 
 static const char *diff_title(struct strbuf *sb,
index daed2d4e1e2beb5da58f4d418c2b10e63d5ad36b..abe66311c705187f77aaf6f62f8f033d08b6e543 100644 (file)
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
        strbuf_branchname(&bname, remote, 0);
        remote = bname.buf;
 
-       oidclr(&branch_head);
+       oidclr(&branch_head, the_repository->hash_algo);
        remote_head = get_merge_parent(remote);
        if (!remote_head)
                die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * index and working tree polluted.
         */
        if (save_state(&stash))
-               oidclr(&stash);
+               oidclr(&stash, the_repository->hash_algo);
 
        for (i = 0; i < use_strategies_nr; i++) {
                int ret, cnt;
index 7f80b3449bd3633601b22ab776f5e7173a3ba897..d9c356e3543fecadfdbd29fd2fe27062b1a2baa9 100644 (file)
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
        if (partial->parents)
                oidcpy(&parent_oid, &partial->parents->item->object.oid);
        else
-               oidclr(&parent_oid);
+               oidclr(&parent_oid, the_repository->hash_algo);
 
        CALLOC_ARRAY(t, 1);
        init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
index 638f5c57f0d2cd9ae95d2abf4c4287b604717611..2b00983a990c43e327dc5d7417b69c1d8b2a4035 100644 (file)
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
                                oidread(&base_ref,
                                        use_pack(p, &w_curs,
                                                 entry->in_pack_offset + used,
-                                                NULL));
+                                                NULL),
+                                       the_repository->hash_algo);
                                have_base = 1;
                        }
                        entry->in_pack_header_size = used + the_hash_algo->rawsz;
index 103c11b9d3047275fb30e4c89f5494ec03b36ffb..dd9bf35f5b8c087ef286ac4f080a3ba8bbbf0ba8 100644 (file)
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
                                              const unsigned char *oid)
 {
        struct llist_item *new_item = llist_item_get();
-       oidread(&new_item->oid, oid);
+       oidread(&new_item->oid, oid, the_repository->hash_algo);
        new_item->next = NULL;
 
        if (after) {
index 583099cacff009494158d146074646894670dd04..d790ae6354b415a1101b8b1de3d3fe5d7bbf27c5 100644 (file)
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
        git_hash_ctx ctx;
 
        the_hash_algo->init_fn(&ctx);
-       oidclr(result);
+       oidclr(result, the_repository->hash_algo);
 
        while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
                char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
        }
 
        if (!found_next)
-               oidclr(next_oid);
+               oidclr(next_oid, the_repository->hash_algo);
 
        flush_one_hunk(result, &ctx);
 
@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
        int patchlen;
        struct strbuf line_buf = STRBUF_INIT;
 
-       oidclr(&oid);
+       oidclr(&oid, the_repository->hash_algo);
        while (!feof(stdin)) {
                patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
                flush_current_id(patchlen, &oid, &result);
index d622202bcecad62be2eec1f1917733bedccaa525..2a73e673f3cab958805769544f0bcd18debff0fb 100644 (file)
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                die_conclude_merge();
 
        if (repo_get_oid(the_repository, "HEAD", &orig_head))
-               oidclr(&orig_head);
+               oidclr(&orig_head, the_repository->hash_algo);
 
        if (opt_rebase) {
                if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                                _("Please commit or stash them."), 1, 0);
 
                if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
-                       oidclr(&rebase_fork_point);
+                       oidclr(&rebase_fork_point, the_repository->hash_algo);
        }
 
        if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                return 0;
 
        if (repo_get_oid(the_repository, "HEAD", &curr_head))
-               oidclr(&curr_head);
+               oidclr(&curr_head, the_repository->hash_algo);
 
        if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
                        !oideq(&orig_head, &curr_head)) {
index 01c1f04ece386b2441c1a7c9b995050b16d00617..aa5ba27d175835eee6e4b715117f15df54577167 100644 (file)
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
                already_done = 1;
                if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
                                      &push_cert_oid))
-                       oidclr(&push_cert_oid);
+                       oidclr(&push_cert_oid, the_repository->hash_algo);
 
                memset(&sigcheck, '\0', sizeof(sigcheck));
 
index ce9f6974d26bd3ef2135324a86b34ecbdb8a6711..1ef833c07f5211cfc51291b950e8f73cd6b04fa8 100644 (file)
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
                return error(_("'%s' is not a valid ref name"), ref->buf);
 
        if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
-               oidclr(prev);
+               oidclr(prev, the_repository->hash_algo);
        else if (!force)
                return error(_("replace ref '%s' already exists"), ref->buf);
        return 0;
index d195c16e749102ccdc63c38eebc0b6f3ca8f03c0..0e79cbab62b86a999bd758afc3b52e79eb59241f 100644 (file)
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        if (!force) {
                struct object_id oid;
                if (repo_get_oid(the_repository, "HEAD", &oid))
-                       oidclr(&oid);
+                       oidclr(&oid, the_repository->hash_algo);
                if (check_local_mod(&oid, index_only))
                        exit(1);
        }
index 6e2c0cf3420156f37d927ab1cd162edf1a2813a1..a1fb218512cc1a072682a33411a6da29313e2446 100644 (file)
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                die(_("'%s' is not a valid tag name."), tag);
 
        if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
-               oidclr(&prev);
+               oidclr(&prev, the_repository->hash_algo);
        else if (!force)
                die(_("tag '%s' already exists"), tag);
 
index 0855572c2750ff950379cc883520a19dd33afca1..08fa2a7a743dc91f8aa83cfc8021fce471a36791 100644 (file)
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
        struct object_id base_oid;
 
        if (type == OBJ_REF_DELTA) {
-               oidread(&base_oid, fill(the_hash_algo->rawsz));
+               oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
                use(the_hash_algo->rawsz);
                delta_data = get_data(delta_size);
                if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
                        return; /* we are done */
                else {
                        /* cannot resolve yet --- queue it */
-                       oidclr(&obj_list[nr].oid);
+                       oidclr(&obj_list[nr].oid, the_repository->hash_algo);
                        add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
                        return;
                }
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
                         * The delta base object is itself a delta that
                         * has not been resolved yet.
                         */
-                       oidclr(&obj_list[nr].oid);
+                       oidclr(&obj_list[nr].oid, the_repository->hash_algo);
                        add_delta_to_list(nr, null_oid(), base_offset,
                                          delta_data, delta_size);
                        return;
index 6cda1c08aa7b8b1cf009fc1be87033245f9fa463..f8a5b087f8f454259f51cd86c5f58604407144fb 100644 (file)
@@ -122,7 +122,7 @@ static int parse_next_oid(const char **next, const char *end,
                                goto invalid;
                } else {
                        /* Without -z, an empty value means all zeros: */
-                       oidclr(oid);
+                       oidclr(oid, the_repository->hash_algo);
                }
        } else {
                /* With -z, read the next NUL-terminated line */
@@ -142,7 +142,7 @@ static int parse_next_oid(const char **next, const char *end,
                        /* With -z, treat an empty value as all zeros: */
                        warning("%s %s: missing <new-oid>, treating as zero",
                                command, refname);
-                       oidclr(oid);
+                       oidclr(oid, the_repository->hash_algo);
                } else {
                        /*
                         * With -z, an empty non-required value means
@@ -291,7 +291,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
 
        if (parse_next_oid(&next, end, &old_oid, "verify", refname,
                           PARSE_SHA1_OLD))
-               oidclr(&old_oid);
+               oidclr(&old_oid, the_repository->hash_algo);
 
        if (*next != line_termination)
                die("verify %s: extra input: %s", refname, next);
@@ -564,7 +564,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                         * The empty string implies that the reference
                         * must not already exist:
                         */
-                       oidclr(&oldoid);
+                       oidclr(&oldoid, the_repository->hash_algo);
                else if (repo_get_oid(the_repository, oldval, &oldoid))
                        die("%s: not a valid old SHA1", oldval);
        }
index 387c0a3e5b7b8bfc895f380e8c3976fcf9b777d8..e4255c4d022da326a40448050bbce52ace7e0073 100644 (file)
@@ -578,7 +578,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
        if (0 <= it->entry_count) {
                if (size < rawsz)
                        goto free_return;
-               oidread(&it->oid, (const unsigned char *)buf);
+               oidread(&it->oid, (const unsigned char *)buf,
+                       the_repository->hash_algo);
                buf += rawsz;
                size -= rawsz;
        }
index 3429156b28d377341cf927dfeb7dedff79428bb0..98cbd53eeac5c67fbce0e70ee0c486046b4c997c 100644 (file)
@@ -475,7 +475,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
                FREE_AND_NULL(graph->bloom_filter_settings);
        }
 
-       oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
+       oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
+               the_repository->hash_algo);
 
        free_chunkfile(cf);
        return graph;
@@ -838,7 +839,8 @@ static void load_oid_from_graph(struct commit_graph *g,
 
        lex_index = pos - g->num_commits_in_base;
 
-       oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
+       oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
+               the_repository->hash_algo);
 }
 
 static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -1080,7 +1082,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
        commit_data = g->chunk_commit_data +
                        st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
 
-       oidread(&oid, commit_data);
+       oidread(&oid, commit_data, the_repository->hash_algo);
        set_commit_tree(c, lookup_tree(r, &oid));
 
        return c->maybe_tree;
@@ -2556,7 +2558,8 @@ int write_commit_graph(struct object_directory *odb,
                struct commit_graph *g = ctx->r->objects->commit_graph;
                for (i = 0; i < g->num_commits; i++) {
                        struct object_id oid;
-                       oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+                       oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+                               the_repository->hash_algo);
                        oid_array_append(&ctx->oids, &oid);
                }
        }
@@ -2675,7 +2678,8 @@ static int verify_one_commit_graph(struct repository *r,
        for (i = 0; i < g->num_commits; i++) {
                struct commit *graph_commit;
 
-               oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+               oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+                       the_repository->hash_algo);
 
                if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
                        graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2719,7 +2723,8 @@ static int verify_one_commit_graph(struct repository *r,
                timestamp_t generation;
 
                display_progress(progress, ++(*seen));
-               oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
+               oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
+                       the_repository->hash_algo);
 
                graph_commit = lookup_commit(r, &cur_oid);
                odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
index 5a5a50c5a15a9e449aa0c41b4c0770330cc1aa19..3fb8d79fefd6db1ce1f26be56bb83d1d2e73cd4d 100644 (file)
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
                        dpath->next = NULL;
                        memcpy(dpath->path, ce->name, path_len);
                        dpath->path[path_len] = '\0';
-                       oidclr(&dpath->oid);
+                       oidclr(&dpath->oid, the_repository->hash_algo);
                        memset(&(dpath->parent[0]), 0,
                               sizeof(struct combine_diff_parent)*5);
 
@@ -412,7 +412,7 @@ static int show_modified(struct rev_info *revs,
                memcpy(p->path, new_entry->name, pathlen);
                p->path[pathlen] = 0;
                p->mode = mode;
-               oidclr(&p->oid);
+               oidclr(&p->oid, the_repository->hash_algo);
                memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
                p->parent[0].status = DIFF_STATUS_MODIFIED;
                p->parent[0].mode = new_entry->ce_mode;
diff --git a/diff.c b/diff.c
index e70301df76743ab196d8f046748d4cb1ca0a5434..60d1f7be81d9c65bcbddbae478c49dcecdf16898 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4567,7 +4567,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
                if (!one->oid_valid) {
                        struct stat st;
                        if (one->is_stdin) {
-                               oidclr(&one->oid);
+                               oidclr(&one->oid, the_repository->hash_algo);
                                return;
                        }
                        if (lstat(one->path, &st) < 0)
@@ -4577,7 +4577,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
                }
        }
        else
-               oidclr(&one->oid);
+               oidclr(&one->oid, the_repository->hash_algo);
 }
 
 static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@@ -6404,7 +6404,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
        the_hash_algo->init_fn(&ctx);
        memset(&data, 0, sizeof(struct patch_id_t));
        data.ctx = &ctx;
-       oidclr(oid);
+       oidclr(oid, the_repository->hash_algo);
 
        for (i = 0; i < q->nr; i++) {
                xpparam_t xpp;
diff --git a/dir.c b/dir.c
index 45be4ad2615a4dff0439c9df77f63a70c34ba7b5..5de421c29c72ead667f43ae6820dbcaf3fc1de9d 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1687,7 +1687,7 @@ static void prep_exclude(struct dir_struct *dir,
                }
 
                /* Try to read per-directory file */
-               oidclr(&oid_stat.oid);
+               oidclr(&oid_stat.oid, the_repository->hash_algo);
                oid_stat.valid = 0;
                if (dir->exclude_per_dir &&
                    /*
@@ -3794,7 +3794,7 @@ static void read_oid(size_t pos, void *cb)
                rd->data = rd->end + 1;
                return;
        }
-       oidread(&ud->exclude_oid, rd->data);
+       oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
        rd->data += the_hash_algo->rawsz;
 }
 
@@ -3802,7 +3802,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
                          const unsigned char *sha1)
 {
        stat_data_from_disk(&oid_stat->stat, data);
-       oidread(&oid_stat->oid, sha1);
+       oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
        oid_stat->valid = 1;
 }
 
index fabdd8ecc7635bbbd9a244d0f117a760d7e7a21d..dbb96369fc88c67e8781cbff84a54c0186cc0b62 100644 (file)
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -284,6 +284,20 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
        dst->algo = src->algo;
 }
 
+static inline void oidread(struct object_id *oid, const unsigned char *hash,
+                          const struct git_hash_algo *algop)
+{
+       memcpy(oid->hash, hash, algop->rawsz);
+       oid->algo = hash_algo_by_ptr(algop);
+}
+
+static inline void oidclr(struct object_id *oid,
+                         const struct git_hash_algo *algop)
+{
+       memset(oid->hash, 0, GIT_MAX_RAWSZ);
+       oid->algo = hash_algo_by_ptr(algop);
+}
+
 static inline struct object_id *oiddup(const struct object_id *src)
 {
        struct object_id *dst = xmalloc(sizeof(struct object_id));
diff --git a/hash.h b/hash.h
index 714938e2eb9b21160e995289cf9491aaa2c27527..43623a0c8670c18c0457ceac158170a8ffc1bc58 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
        dst->algo = src->algo;
 }
 
-static inline void oidclr(struct object_id *oid)
-{
-       memset(oid->hash, 0, GIT_MAX_RAWSZ);
-       oid->algo = hash_algo_by_ptr(the_hash_algo);
-}
-
-static inline void oidread_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
-{
-       memcpy(oid->hash, hash, algop->rawsz);
-       oid->algo = hash_algo_by_ptr(algop);
-}
-
-static inline void oidread(struct object_id *oid, const unsigned char *hash)
-{
-       oidread_algop(oid, hash, the_hash_algo);
-}
-
 static inline int is_empty_blob_oid(const struct object_id *oid)
 {
        return oideq(oid, the_hash_algo->empty_blob);
index 1fe51226fd28a84fefe621cd2cf0a593afa1105f..86de238b84fa5b13dd10e6eb145b05cfcc8a7bb8 100644 (file)
@@ -1552,7 +1552,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
        free(url);
 
        FREE_AND_NULL(*symref);
-       oidclr(oid);
+       oidclr(oid, the_repository->hash_algo);
 
        if (buffer.len == 0)
                return;
index cf7f8c82bc7eabafa4541c104540358833d59094..b7110b6f82803b0bbce9b279d4f0d9b2a3e84131 100644 (file)
@@ -152,7 +152,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
 
        newreq = xmalloc(sizeof(*newreq));
        newreq->walker = walker;
-       oidread(&newreq->oid, sha1);
+       oidread(&newreq->oid, sha1, the_repository->hash_algo);
        newreq->repo = data->alt;
        newreq->state = WAITING;
        newreq->req = NULL;
index 849b391d3da67f862141fdda8ab42df0901181ce..50c42e206164b407c14fffa36bc629f81df7eb1c 100644 (file)
@@ -229,7 +229,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
                    oid_to_hex(oid1));
        if (*subpath) {
                struct object_id tree_oid;
-               oidread(&tree_oid, rewrite_here);
+               oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
                status = splice_tree(&tree_oid, subpath, oid2, &subtree);
                if (status)
                        return status;
diff --git a/midx.c b/midx.c
index bc4797196f02e60f566668867d6896b79ff952e4..1e75f1a7eb11fd1a2416f7cee277aa896bd399ec 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -304,7 +304,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
        if (n >= m->num_objects)
                return NULL;
 
-       oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
+       oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
+               the_repository->hash_algo);
        return oid;
 }
 
index 6a9a139b123f23e9c331fc1bbcad75cbb1f97adb..801941c2d1c365801b94a6d35a77da44d20664d7 100644 (file)
@@ -240,7 +240,7 @@ static void diff_tree_local(struct notes_merge_options *o,
                         *     (will be overwritten by following addition)
                         */
                        if (oideq(&mp->local, &uninitialized))
-                               oidclr(&mp->local);
+                               oidclr(&mp->local, the_repository->hash_algo);
                } else if (is_null_oid(&p->one->oid)) { /* addition */
                        /*
                         * Either this is a true addition (1), or it is part
@@ -556,7 +556,7 @@ int notes_merge(struct notes_merge_options *o,
 
        assert(o->local_ref && o->remote_ref);
        assert(!strcmp(o->local_ref, local_tree->ref));
-       oidclr(result_oid);
+       oidclr(result_oid, the_repository->hash_algo);
 
        trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
               o->local_ref, o->remote_ref);
@@ -579,7 +579,7 @@ int notes_merge(struct notes_merge_options *o,
                 * unborn ref, perform the merge using an empty notes tree.
                 */
                if (!check_refname_format(o->remote_ref, 0)) {
-                       oidclr(&remote_oid);
+                       oidclr(&remote_oid, the_repository->hash_algo);
                        remote = NULL;
                } else {
                        die("Failed to resolve remote notes ref '%s'",
diff --git a/notes.c b/notes.c
index 5296fd863fbf528b8d1ea50770cd9917c205a80e..3a8da92fb9c5d19b1ae3221730a501855f6164c0 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -353,7 +353,7 @@ static void add_non_note(struct notes_tree *t, char *path,
        n->next = NULL;
        n->path = path;
        n->mode = mode;
-       oidread(&n->oid, sha1);
+       oidread(&n->oid, sha1, the_repository->hash_algo);
        t->prev_non_note = n;
 
        if (!t->first_non_note) {
@@ -1036,7 +1036,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
                die("Failed to read notes tree referenced by %s (%s)",
                    notes_ref, oid_to_hex(&object_oid));
 
-       oidclr(&root_tree.key_oid);
+       oidclr(&root_tree.key_oid, the_repository->hash_algo);
        oidcpy(&root_tree.val_oid, &oid);
        load_subtree(t, &root_tree, t->root, 0);
 }
@@ -1146,8 +1146,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
        if (!t)
                t = &default_notes_tree;
        assert(t->initialized);
-       oidread(&l.key_oid, object_sha1);
-       oidclr(&l.val_oid);
+       oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
+       oidclr(&l.val_oid, the_repository->hash_algo);
        note_tree_remove(t, t->root, 0, &l);
        if (is_null_oid(&l.val_oid)) /* no note was removed */
                return 1;
index 4f6189095be83ce95da87364f474e8d664810cca..f684038f7f328ac5bb4df7c4b80f15808b0b4e73 100644 (file)
@@ -56,7 +56,7 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
                return -1;
        *len = strlen(*path) + 1;
 
-       oidread_algop(oid, (const unsigned char *)*path + *len, algo);
+       oidread(oid, (const unsigned char *)*path + *len, algo);
        return 0;
 }
 
index a40300ce4acc0c25c44e837518ca2702acf92a77..c161e3e2a52d3b0133d91166bddc1563f839974d 100644 (file)
@@ -1446,7 +1446,7 @@ static int loose_object_info(struct repository *r,
        int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
 
        if (oi->delta_base_oid)
-               oidclr(oi->delta_base_oid);
+               oidclr(oi->delta_base_oid, the_repository->hash_algo);
 
        /*
         * If we don't care about type or size, then we don't
@@ -1580,7 +1580,7 @@ static int do_oid_object_info_extended(struct repository *r,
                if (oi->disk_sizep)
                        *(oi->disk_sizep) = 0;
                if (oi->delta_base_oid)
-                       oidclr(oi->delta_base_oid);
+                       oidclr(oi->delta_base_oid, the_repository->hash_algo);
                if (oi->type_name)
                        strbuf_addstr(oi->type_name, type_name(co->type));
                if (oi->contentp)
index 9156e9122c5c4a57f61d4f50171514577c2f110f..ec7312cd20aeb6bc3d4da25cd4ba085362b0347d 100644 (file)
@@ -1251,7 +1251,7 @@ static int get_delta_base_oid(struct packed_git *p,
 {
        if (type == OBJ_REF_DELTA) {
                unsigned char *base = use_pack(p, w_curs, curpos, NULL);
-               oidread(oid, base);
+               oidread(oid, base, the_repository->hash_algo);
                return 0;
        } else if (type == OBJ_OFS_DELTA) {
                uint32_t base_pos;
@@ -1593,7 +1593,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
                                goto out;
                        }
                } else
-                       oidclr(oi->delta_base_oid);
+                       oidclr(oi->delta_base_oid, the_repository->hash_algo);
        }
 
        oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
@@ -1917,10 +1917,12 @@ int nth_packed_object_id(struct object_id *oid,
                return -1;
        index += 4 * 256;
        if (p->index_version == 1) {
-               oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
+               oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),
+                       the_repository->hash_algo);
        } else {
                index += 8;
-               oidread(oid, index + st_mult(hashsz, n));
+               oidread(oid, index + st_mult(hashsz, n),
+                       the_repository->hash_algo);
        }
        return 0;
 }
index 2642ac955889ba63e0b2dfede94d367eb1f2dc48..836f1db721f5094b3e33b10d3baa1c466ff544b3 100644 (file)
@@ -1728,7 +1728,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
 
        end = (unsigned char *)hdr + size;
        start = end - the_hash_algo->rawsz;
-       oidread(&oid, start);
+       oidread(&oid, start, the_repository->hash_algo);
        if (oideq(&oid, null_oid()))
                return 0;
 
@@ -1876,7 +1876,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
        ce->ce_flags = flags & ~CE_NAMEMASK;
        ce->ce_namelen = len;
        ce->index = 0;
-       oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data));
+       oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data),
+               the_repository->hash_algo);
 
        if (expand_name_field) {
                if (copy_len)
@@ -2249,7 +2250,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        if (verify_hdr(hdr, mmap_size) < 0)
                goto unmap;
 
-       oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
+       oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz,
+               the_repository->hash_algo);
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
diff --git a/refs.c b/refs.c
index 1304d3dd87f63ab71395100e9b4d9e56e51e8b46..6e7caefdcfd8eded5dabccaa511f8baf463ba3cb 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1822,7 +1822,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
                            failure_errno != ENOTDIR)
                                return NULL;
 
-                       oidclr(oid);
+                       oidclr(oid, the_repository->hash_algo);
                        if (*flags & REF_BAD_NAME)
                                *flags |= REF_ISBROKEN;
                        return refname;
@@ -1832,7 +1832,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
                if (!(read_flags & REF_ISSYMREF)) {
                        if (*flags & REF_BAD_NAME) {
-                               oidclr(oid);
+                               oidclr(oid, the_repository->hash_algo);
                                *flags |= REF_ISBROKEN;
                        }
                        return refname;
@@ -1840,7 +1840,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
                refname = sb_refname.buf;
                if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
-                       oidclr(oid);
+                       oidclr(oid, the_repository->hash_algo);
                        return refname;
                }
                if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
index 4519b4617110bd8ffe875d1b1d545ae155b9c88a..b484b5880d61c6db25d18385935bf875d3108803 100644 (file)
@@ -246,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
 
        if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
                                     &oid, &flag)) {
-               oidclr(&oid);
+               oidclr(&oid, the_repository->hash_algo);
                flag |= REF_ISBROKEN;
        } else if (is_null_oid(&oid)) {
                /*
@@ -263,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
        if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
                if (!refname_is_safe(refname))
                        die("loose refname is dangerous: %s", refname);
-               oidclr(&oid);
+               oidclr(&oid, the_repository->hash_algo);
                flag |= REF_BAD_NAME | REF_ISBROKEN;
        }
        add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
@@ -1150,7 +1150,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
 
        if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
                                     &lock->old_oid, NULL))
-               oidclr(&lock->old_oid);
+               oidclr(&lock->old_oid, the_repository->hash_algo);
        goto out;
 
  error_return:
index c4c1e36aa29c0f83bf640c6d58444971f58d7246..5ab1b21d10f826402d9b1ecf895df540e881bffb 100644 (file)
@@ -894,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
                if (!refname_is_safe(iter->base.refname))
                        die("packed refname is dangerous: %s",
                            iter->base.refname);
-               oidclr(&iter->oid);
+               oidclr(&iter->oid, the_repository->hash_algo);
                iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
        }
        if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -919,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
                 * we suppress it if the reference is broken:
                 */
                if ((iter->base.flags & REF_ISBROKEN)) {
-                       oidclr(&iter->peeled);
+                       oidclr(&iter->peeled, the_repository->hash_algo);
                        iter->base.flags &= ~REF_KNOWS_PEELED;
                } else {
                        iter->base.flags |= REF_KNOWS_PEELED;
                }
        } else {
-               oidclr(&iter->peeled);
+               oidclr(&iter->peeled, the_repository->hash_algo);
        }
 
        return ITER_OK;
index 9886fc67a47877bb3d89f188553d5f1d17943be8..57df2aba6613ccd380e3818f085ffc54a64ca920 100644 (file)
@@ -217,7 +217,8 @@ static int read_ref_without_reload(struct reftable_stack *stack,
                strbuf_addstr(referent, ref.value.symref);
                *type |= REF_ISSYMREF;
        } else if (reftable_ref_record_val1(&ref)) {
-               oidread(oid, reftable_ref_record_val1(&ref));
+               oidread(oid, reftable_ref_record_val1(&ref),
+                       the_repository->hash_algo);
        } else {
                /* We got a tombstone, which should not happen. */
                BUG("unhandled reference value type %d", ref.value_type);
@@ -483,15 +484,17 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
 
                switch (iter->ref.value_type) {
                case REFTABLE_REF_VAL1:
-                       oidread(&iter->oid, iter->ref.value.val1);
+                       oidread(&iter->oid, iter->ref.value.val1,
+                               the_repository->hash_algo);
                        break;
                case REFTABLE_REF_VAL2:
-                       oidread(&iter->oid, iter->ref.value.val2.value);
+                       oidread(&iter->oid, iter->ref.value.val2.value,
+                               the_repository->hash_algo);
                        break;
                case REFTABLE_REF_SYMREF:
                        if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
                                                     RESOLVE_REF_READING, &iter->oid, &flags))
-                               oidclr(&iter->oid);
+                               oidclr(&iter->oid, the_repository->hash_algo);
                        break;
                default:
                        BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -503,7 +506,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
                if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
                        if (!refname_is_safe(iter->ref.refname))
                                die(_("refname is dangerous: %s"), iter->ref.refname);
-                       oidclr(&iter->oid);
+                       oidclr(&iter->oid, the_repository->hash_algo);
                        flags |= REF_BAD_NAME | REF_ISBROKEN;
                }
 
@@ -545,7 +548,8 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
                (struct reftable_ref_iterator *)ref_iterator;
 
        if (iter->ref.value_type == REFTABLE_REF_VAL2) {
-               oidread(peeled, iter->ref.value.val2.target_value);
+               oidread(peeled, iter->ref.value.val2.target_value,
+                       the_repository->hash_algo);
                return 0;
        }
 
@@ -1776,8 +1780,8 @@ static int yield_log_record(struct reftable_log_record *log,
        struct object_id old_oid, new_oid;
        const char *full_committer;
 
-       oidread(&old_oid, log->value.update.old_hash);
-       oidread(&new_oid, log->value.update.new_hash);
+       oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
+       oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
 
        /*
         * When both the old object ID and the new object ID are null
@@ -2178,7 +2182,8 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
        if (ret < 0)
                goto done;
        if (reftable_ref_record_val1(&ref_record))
-               oidread(&oid, reftable_ref_record_val1(&ref_record));
+               oidread(&oid, reftable_ref_record_val1(&ref_record),
+                       the_repository->hash_algo);
        prepare_fn(refname, &oid, policy_cb_data);
 
        while (1) {
@@ -2193,8 +2198,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
                        break;
                }
 
-               oidread(&old_oid, log.value.update.old_hash);
-               oidread(&new_oid, log.value.update.new_hash);
+               oidread(&old_oid, log.value.update.old_hash,
+                       the_repository->hash_algo);
+               oidread(&new_oid, log.value.update.new_hash,
+                       the_repository->hash_algo);
 
                /*
                 * Skip over the reflog existence marker. We will add it back
@@ -2225,8 +2232,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
                struct object_id old_oid, new_oid;
 
                *dest = logs[i];
-               oidread(&old_oid, logs[i].value.update.old_hash);
-               oidread(&new_oid, logs[i].value.update.new_hash);
+               oidread(&old_oid, logs[i].value.update.old_hash,
+                       the_repository->hash_algo);
+               oidread(&new_oid, logs[i].value.update.new_hash,
+                       the_repository->hash_algo);
 
                if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
                                    (timestamp_t)logs[i].value.update.time,
@@ -2243,7 +2252,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
 
        if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
            reftable_ref_record_val1(&ref_record))
-               oidread(&arg.update_oid, last_hash);
+               oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
 
        arg.refs = refs;
        arg.records = rewritten;
index dcb5492c85ed33d6d2736726e54e7c3598e47d08..10641710851a9739cb9d108a496ab2d7aba50f04 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1164,7 +1164,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
 static struct ref *alloc_delete_ref(void)
 {
        struct ref *ref = alloc_ref("(delete)");
-       oidclr(&ref->new_oid);
+       oidclr(&ref->new_oid, the_repository->hash_algo);
        return ref;
 }
 
@@ -2531,7 +2531,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
        if (!*colon)
                entry->use_tracking = 1;
        else if (!colon[1])
-               oidclr(&entry->expect);
+               oidclr(&entry->expect, the_repository->hash_algo);
        else if (repo_get_oid(the_repository, colon + 1, &entry->expect))
                return error(_("cannot parse expected object name '%s'"),
                             colon + 1);
@@ -2733,7 +2733,7 @@ static void apply_cas(struct push_cas_option *cas,
                else if (remote_tracking(remote, ref->name,
                                         &ref->old_oid_expect,
                                         &ref->tracking_ref))
-                       oidclr(&ref->old_oid_expect);
+                       oidclr(&ref->old_oid_expect, the_repository->hash_algo);
                else
                        ref->check_reachable = cas->use_force_if_includes;
                return;
@@ -2747,7 +2747,7 @@ static void apply_cas(struct push_cas_option *cas,
        if (remote_tracking(remote, ref->name,
                            &ref->old_oid_expect,
                            &ref->tracking_ref))
-               oidclr(&ref->old_oid_expect);
+               oidclr(&ref->old_oid_expect, the_repository->hash_algo);
        else
                ref->check_reachable = cas->use_force_if_includes;
 }
index cd02dc99289997e5bf3ac57da3a0c5d482a8301d..4e6f0e46769a9b4610663a295123d0308a73b478 100644 (file)
@@ -93,7 +93,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
                                continue;
                        if (size < rawsz)
                                goto error;
-                       oidread(&ui->oid[i], (const unsigned char *)data);
+                       oidread(&ui->oid[i], (const unsigned char *)data,
+                               the_repository->hash_algo);
                        size -= rawsz;
                        data += rawsz;
                }
index 30513e87bfb9e6c07e61b0b8d36896a5637e72db..68d62a12ff69bc78e0cfcf06a49b7004c6d5bffa 100644 (file)
@@ -3334,12 +3334,12 @@ static int rollback_is_safe(void)
                strbuf_release(&sb);
        }
        else if (errno == ENOENT)
-               oidclr(&expected_head);
+               oidclr(&expected_head, the_repository->hash_algo);
        else
                die_errno(_("could not read '%s'"), git_path_abort_safety_file());
 
        if (repo_get_oid(the_repository, "HEAD", &actual_head))
-               oidclr(&actual_head);
+               oidclr(&actual_head, the_repository->hash_algo);
 
        return oideq(&actual_head, &expected_head);
 }
index 8c38687c04b81ceaa57746a96daf670874e31643..058a8f448efd6e73315b39da92796b0af0598cc4 100644 (file)
@@ -29,7 +29,7 @@ int read_link_extension(struct index_state *istate,
        if (sz < the_hash_algo->rawsz)
                return error("corrupt link extension (too short)");
        si = init_split_index(istate);
-       oidread(&si->base_oid, data);
+       oidread(&si->base_oid, data, the_repository->hash_algo);
        data += the_hash_algo->rawsz;
        sz -= the_hash_algo->rawsz;
        if (!sz)
index ec45ea67b95618d4ec626e80af145a5282e0ac0d..ad43a282da65c8422650257e88832edb4bc74a29 100644 (file)
@@ -682,7 +682,7 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
        int ret = 0;
 
        if (is_null_oid(treeish_name)) {
-               oidclr(gitmodules_oid);
+               oidclr(gitmodules_oid, the_repository->hash_algo);
                return 1;
        }
 
index 9df2f03ac80de2b9cf977b0d7e252eb904c903f3..4b809d9dcac3ec99d85c41c6b5efe4e574c7b255 100644 (file)
@@ -44,7 +44,7 @@ int cmd__submodule_config(int argc, const char **argv)
                path_or_name = arg[1];
 
                if (commit[0] == '\0')
-                       oidclr(&commit_oid);
+                       oidclr(&commit_oid, the_repository->hash_algo);
                else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
                        die_usage(argc, argv, "Commit not found.");
 
index 6565d9ad993bd830446277cc35a2aa54567cd18f..535a3a25399aebbac55c2a9097877e2b08601ec9 100644 (file)
@@ -38,8 +38,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
        desc->entry.path = path;
        desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode);
        desc->entry.pathlen = len - 1;
-       oidread_algop(&desc->entry.oid, (const unsigned char *)path + len,
-                     desc->algo);
+       oidread(&desc->entry.oid, (const unsigned char *)path + len,
+               desc->algo);
 
        return 0;
 }