hash: require hash algorithm in `oidread()` and `oidclr()`

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>

Patrick Steinhardt committed Jun 14, 2024 at 08:49 UTC 9da95bda74cf10e1475384a71fd20914c3b99784
48 files changed +163 -140
apply.c
+1 -1
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
3680 if (status) {
3681 patch->conflicted_threeway = 1;
3682 if (patch->is_new)
3683 - oidclr(&patch->threeway_stage[0]);
3683 + oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
3684 else
3685 oidcpy(&patch->threeway_stage[0], &pre_oid);
3686 oidcpy(&patch->threeway_stage[1], &our_oid);
blame.c
+1 -1
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
1246 goto error_out;
1247 return 0;
1248 error_out:
1249 - oidclr(&origin->blob_oid);
1249 + oidclr(&origin->blob_oid, the_repository->hash_algo);
1250 origin->mode = S_IFINVALID;
1251 return -1;
1252 }
builtin/am.c
+4 -4
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
408 read_commit_msg(state);
409
410 if (read_state_file(&sb, state, "original-commit", 1) < 0)
411 - oidclr(&state->orig_commit);
411 + oidclr(&state->orig_commit, the_repository->hash_algo);
412 else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
413 die(_("could not parse %s"), am_path(state, "original-commit"));
414
@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
1121 unlink(am_path(state, "author-script"));
1122 unlink(am_path(state, "final-commit"));
1123
1124 - oidclr(&state->orig_commit);
1124 + oidclr(&state->orig_commit, the_repository->hash_algo);
1125 unlink(am_path(state, "original-commit"));
1126 refs_delete_ref(get_main_ref_store(the_repository), NULL,
1127 "REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
2151 if (get_oid_hex(sb.buf, &abort_safety))
2152 die(_("could not parse %s"), am_path(state, "abort-safety"));
2153 } else
2154 - oidclr(&abort_safety);
2154 + oidclr(&abort_safety, the_repository->hash_algo);
2155 strbuf_release(&sb);
2156
2157 if (repo_get_oid(the_repository, "HEAD", &head))
2158 - oidclr(&head);
2158 + oidclr(&head, the_repository->hash_algo);
2159
2160 if (oideq(&head, &abort_safety))
2161 return 1;
builtin/fast-export.c
+1 -1
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
415 struct object_id oid;
416 char *hex = xmallocz(GIT_MAX_HEXSZ);
417
418 - oidclr(&oid);
418 + oidclr(&oid, the_repository->hash_algo);
419 put_be32(oid.hash + hashsz - 4, counter++);
420 return oid_to_hex_r(hex, &oid);
421 }
builtin/fast-import.c
+21 -18
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
1279 e->versions[0].mode = e->versions[1].mode;
1280 e->name = to_atom(c, strlen(c));
1281 c += e->name->str_len + 1;
1282 - oidread(&e->versions[0].oid, (unsigned char *)c);
1283 - oidread(&e->versions[1].oid, (unsigned char *)c);
1282 + oidread(&e->versions[0].oid, (unsigned char *)c,
1283 + the_repository->hash_algo);
1284 + oidread(&e->versions[1].oid, (unsigned char *)c,
1285 + the_repository->hash_algo);
1286 c += the_hash_algo->rawsz;
1287 }
1288 free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
1388 {
1389 if (!S_ISDIR(mode))
1390 die("Root cannot be a non-directory");
1389 - oidclr(&root->versions[0].oid);
1391 + oidclr(&root->versions[0].oid, the_repository->hash_algo);
1392 oidcpy(&root->versions[1].oid, oid);
1393 if (root->tree)
1394 release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
1447 if (S_ISDIR(e->versions[0].mode))
1448 e->versions[0].mode |= NO_DELTA;
1449
1448 - oidclr(&root->versions[1].oid);
1450 + oidclr(&root->versions[1].oid, the_repository->hash_algo);
1451 return 1;
1452 }
1453 if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
1457 if (!e->tree)
1458 load_tree(e);
1459 if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
1458 - oidclr(&root->versions[1].oid);
1460 + oidclr(&root->versions[1].oid, the_repository->hash_algo);
1461 return 1;
1462 }
1463 return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
1469 e = new_tree_entry();
1470 e->name = to_atom(p, n);
1471 e->versions[0].mode = 0;
1470 - oidclr(&e->versions[0].oid);
1472 + oidclr(&e->versions[0].oid, the_repository->hash_algo);
1473 t->entries[t->entry_count++] = e;
1474 if (*slash1) {
1475 e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
1480 e->versions[1].mode = mode;
1481 oidcpy(&e->versions[1].oid, oid);
1482 }
1481 - oidclr(&root->versions[1].oid);
1483 + oidclr(&root->versions[1].oid, the_repository->hash_algo);
1484 return 1;
1485 }
1486
@@ -1523,7 +1525,8 @@ static int tree_content_remove(
1525 if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
1526 for (n = 0; n < e->tree->entry_count; n++) {
1527 if (e->tree->entries[n]->versions[1].mode) {
1526 - oidclr(&root->versions[1].oid);
1528 + oidclr(&root->versions[1].oid,
1529 + the_repository->hash_algo);
1530 return 1;
1531 }
1532 }
@@ -1542,8 +1545,8 @@ del_entry:
1545 release_tree_content_recursive(e->tree);
1546 e->tree = NULL;
1547 e->versions[1].mode = 0;
1545 - oidclr(&e->versions[1].oid);
1546 - oidclr(&root->versions[1].oid);
1548 + oidclr(&e->versions[1].oid, the_repository->hash_algo);
1549 + oidclr(&root->versions[1].oid, the_repository->hash_algo);
1550 return 1;
1551 }
1552
@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
1612 return 0;
1613 }
1614 if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
1612 - oidclr(&old_oid);
1615 + oidclr(&old_oid, the_repository->hash_algo);
1616 if (!force_update && !is_null_oid(&old_oid)) {
1617 struct commit *old_cmit, *new_cmit;
1618 int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2553 static void file_change_deleteall(struct branch *b)
2554 {
2555 release_tree_content_recursive(b->branch_tree.tree);
2553 - oidclr(&b->branch_tree.versions[0].oid);
2554 - oidclr(&b->branch_tree.versions[1].oid);
2556 + oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
2557 + oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
2558 load_tree(&b->branch_tree);
2559 b->num_notes = 0;
2560 }
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
2573 static void parse_from_existing(struct branch *b)
2574 {
2575 if (is_null_oid(&b->oid)) {
2573 - oidclr(&b->branch_tree.versions[0].oid);
2574 - oidclr(&b->branch_tree.versions[1].oid);
2576 + oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
2577 + oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
2578 } else {
2579 unsigned long size;
2580 char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
2897
2898 b = lookup_branch(arg);
2899 if (b) {
2897 - oidclr(&b->oid);
2898 - oidclr(&b->branch_tree.versions[0].oid);
2899 - oidclr(&b->branch_tree.versions[1].oid);
2900 + oidclr(&b->oid, the_repository->hash_algo);
2901 + oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
2902 + oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
2903 if (b->branch_tree.tree) {
2904 release_tree_content_recursive(b->branch_tree.tree);
2905 b->branch_tree.tree = NULL;
builtin/fetch-pack.c
+2 -2
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
29 ; /* <oid>, leave oid as name */
30 } else {
31 /* <ref>, clear cruft from oid */
32 - oidclr(&oid);
32 + oidclr(&oid, the_repository->hash_algo);
33 }
34 } else {
35 /* <ref>, clear cruft from get_oid_hex */
36 - oidclr(&oid);
36 + oidclr(&oid, the_repository->hash_algo);
37 }
38
39 ref = alloc_ref(name);
builtin/index-pack.c
+3 -2
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
528
529 switch (obj->type) {
530 case OBJ_REF_DELTA:
531 - oidread(ref_oid, fill(the_hash_algo->rawsz));
531 + oidread(ref_oid, fill(the_hash_algo->rawsz),
532 + the_repository->hash_algo);
533 use(the_hash_algo->rawsz);
534 break;
535 case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
1373 obj[1].idx.offset += write_compressed(f, buf, size);
1374 obj[0].idx.crc32 = crc32_end(f);
1375 hashflush(f);
1375 - oidread(&obj->idx.oid, sha1);
1376 + oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
1377 return obj;
1378 }
1379
builtin/log.c
+1 -1
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
1938 free(bases->patch_id);
1939 bases->nr_patch_id = 0;
1940 bases->alloc_patch_id = 0;
1941 - oidclr(&bases->base_commit);
1941 + oidclr(&bases->base_commit, the_repository->hash_algo);
1942 }
1943
1944 static const char *diff_title(struct strbuf *sb,
builtin/merge.c
+2 -2
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
494 strbuf_branchname(&bname, remote, 0);
495 remote = bname.buf;
496
497 - oidclr(&branch_head);
497 + oidclr(&branch_head, the_repository->hash_algo);
498 remote_head = get_merge_parent(remote);
499 if (!remote_head)
500 die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1690 * index and working tree polluted.
1691 */
1692 if (save_state(&stash))
1693 - oidclr(&stash);
1693 + oidclr(&stash, the_repository->hash_algo);
1694
1695 for (i = 0; i < use_strategies_nr; i++) {
1696 int ret, cnt;
builtin/notes.c
+1 -1
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
828 if (partial->parents)
829 oidcpy(&parent_oid, &partial->parents->item->object.oid);
830 else
831 - oidclr(&parent_oid);
831 + oidclr(&parent_oid, the_repository->hash_algo);
832
833 CALLOC_ARRAY(t, 1);
834 init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
builtin/pack-objects.c
+2 -1
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
2078 oidread(&base_ref,
2079 use_pack(p, &w_curs,
2080 entry->in_pack_offset + used,
2081 - NULL));
2081 + NULL),
2082 + the_repository->hash_algo);
2083 have_base = 1;
2084 }
2085 entry->in_pack_header_size = used + the_hash_algo->rawsz;
builtin/pack-redundant.c
+1 -1
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
100 const unsigned char *oid)
101 {
102 struct llist_item *new_item = llist_item_get();
103 - oidread(&new_item->oid, oid);
103 + oidread(&new_item->oid, oid, the_repository->hash_algo);
104 new_item->next = NULL;
105
106 if (after) {
builtin/patch-id.c
+3 -3
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
70 git_hash_ctx ctx;
71
72 the_hash_algo->init_fn(&ctx);
73 - oidclr(result);
73 + oidclr(result, the_repository->hash_algo);
74
75 while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
76 char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
166 }
167
168 if (!found_next)
169 - oidclr(next_oid);
169 + oidclr(next_oid, the_repository->hash_algo);
170
171 flush_one_hunk(result, &ctx);
172
@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
179 int patchlen;
180 struct strbuf line_buf = STRBUF_INIT;
181
182 - oidclr(&oid);
182 + oidclr(&oid, the_repository->hash_algo);
183 while (!feof(stdin)) {
184 patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
185 flush_current_id(patchlen, &oid, &result);
builtin/pull.c
+3 -3
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1038 die_conclude_merge();
1039
1040 if (repo_get_oid(the_repository, "HEAD", &orig_head))
1041 - oidclr(&orig_head);
1041 + oidclr(&orig_head, the_repository->hash_algo);
1042
1043 if (opt_rebase) {
1044 if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1053 _("Please commit or stash them."), 1, 0);
1054
1055 if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
1056 - oidclr(&rebase_fork_point);
1056 + oidclr(&rebase_fork_point, the_repository->hash_algo);
1057 }
1058
1059 if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1063 return 0;
1064
1065 if (repo_get_oid(the_repository, "HEAD", &curr_head))
1066 - oidclr(&curr_head);
1066 + oidclr(&curr_head, the_repository->hash_algo);
1067
1068 if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
1069 !oideq(&orig_head, &curr_head)) {
builtin/receive-pack.c
+1 -1
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
741 already_done = 1;
742 if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
743 &push_cert_oid))
744 - oidclr(&push_cert_oid);
744 + oidclr(&push_cert_oid, the_repository->hash_algo);
745
746 memset(&sigcheck, '\0', sizeof(sigcheck));
747
builtin/replace.c
+1 -1
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
167 return error(_("'%s' is not a valid ref name"), ref->buf);
168
169 if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
170 - oidclr(prev);
170 + oidclr(prev, the_repository->hash_algo);
171 else if (!force)
172 return error(_("replace ref '%s' already exists"), ref->buf);
173 return 0;
builtin/rm.c
+1 -1
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
377 if (!force) {
378 struct object_id oid;
379 if (repo_get_oid(the_repository, "HEAD", &oid))
380 - oidclr(&oid);
380 + oidclr(&oid, the_repository->hash_algo);
381 if (check_local_mod(&oid, index_only))
382 exit(1);
383 }
builtin/tag.c
+1 -1
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
650 die(_("'%s' is not a valid tag name."), tag);
651
652 if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
653 - oidclr(&prev);
653 + oidclr(&prev, the_repository->hash_algo);
654 else if (!force)
655 die(_("tag '%s' already exists"), tag);
656
builtin/unpack-objects.c
+3 -3
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
439 struct object_id base_oid;
440
441 if (type == OBJ_REF_DELTA) {
442 - oidread(&base_oid, fill(the_hash_algo->rawsz));
442 + oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
443 use(the_hash_algo->rawsz);
444 delta_data = get_data(delta_size);
445 if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
451 return; /* we are done */
452 else {
453 /* cannot resolve yet --- queue it */
454 - oidclr(&obj_list[nr].oid);
454 + oidclr(&obj_list[nr].oid, the_repository->hash_algo);
455 add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
456 return;
457 }
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
500 * The delta base object is itself a delta that
501 * has not been resolved yet.
502 */
503 - oidclr(&obj_list[nr].oid);
503 + oidclr(&obj_list[nr].oid, the_repository->hash_algo);
504 add_delta_to_list(nr, null_oid(), base_offset,
505 delta_data, delta_size);
506 return;
builtin/update-ref.c
+4 -4
@@ -122,7 +122,7 @@ static int parse_next_oid(const char **next, const char *end,
122 goto invalid;
123 } else {
124 /* Without -z, an empty value means all zeros: */
125 - oidclr(oid);
125 + oidclr(oid, the_repository->hash_algo);
126 }
127 } else {
128 /* With -z, read the next NUL-terminated line */
@@ -142,7 +142,7 @@ static int parse_next_oid(const char **next, const char *end,
142 /* With -z, treat an empty value as all zeros: */
143 warning("%s %s: missing <new-oid>, treating as zero",
144 command, refname);
145 - oidclr(oid);
145 + oidclr(oid, the_repository->hash_algo);
146 } else {
147 /*
148 * With -z, an empty non-required value means
@@ -291,7 +291,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
291
292 if (parse_next_oid(&next, end, &old_oid, "verify", refname,
293 PARSE_SHA1_OLD))
294 - oidclr(&old_oid);
294 + oidclr(&old_oid, the_repository->hash_algo);
295
296 if (*next != line_termination)
297 die("verify %s: extra input: %s", refname, next);
@@ -564,7 +564,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
564 * The empty string implies that the reference
565 * must not already exist:
566 */
567 - oidclr(&oldoid);
567 + oidclr(&oldoid, the_repository->hash_algo);
568 else if (repo_get_oid(the_repository, oldval, &oldoid))
569 die("%s: not a valid old SHA1", oldval);
570 }
cache-tree.c
+2 -1
@@ -578,7 +578,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
578 if (0 <= it->entry_count) {
579 if (size < rawsz)
580 goto free_return;
581 - oidread(&it->oid, (const unsigned char *)buf);
581 + oidread(&it->oid, (const unsigned char *)buf,
582 + the_repository->hash_algo);
583 buf += rawsz;
584 size -= rawsz;
585 }
commit-graph.c
+11 -6
@@ -475,7 +475,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
475 FREE_AND_NULL(graph->bloom_filter_settings);
476 }
477
478 - oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
478 + oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
479 + the_repository->hash_algo);
480
481 free_chunkfile(cf);
482 return graph;
@@ -838,7 +839,8 @@ static void load_oid_from_graph(struct commit_graph *g,
839
840 lex_index = pos - g->num_commits_in_base;
841
841 - oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
842 + oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
843 + the_repository->hash_algo);
844 }
845
846 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,
1082 commit_data = g->chunk_commit_data +
1083 st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
1084
1083 - oidread(&oid, commit_data);
1085 + oidread(&oid, commit_data, the_repository->hash_algo);
1086 set_commit_tree(c, lookup_tree(r, &oid));
1087
1088 return c->maybe_tree;
@@ -2556,7 +2558,8 @@ int write_commit_graph(struct object_directory *odb,
2558 struct commit_graph *g = ctx->r->objects->commit_graph;
2559 for (i = 0; i < g->num_commits; i++) {
2560 struct object_id oid;
2559 - oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
2561 + oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2562 + the_repository->hash_algo);
2563 oid_array_append(&ctx->oids, &oid);
2564 }
2565 }
@@ -2675,7 +2678,8 @@ static int verify_one_commit_graph(struct repository *r,
2678 for (i = 0; i < g->num_commits; i++) {
2679 struct commit *graph_commit;
2680
2678 - oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
2681 + oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2682 + the_repository->hash_algo);
2683
2684 if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
2685 graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2719,7 +2723,8 @@ static int verify_one_commit_graph(struct repository *r,
2723 timestamp_t generation;
2724
2725 display_progress(progress, ++(*seen));
2722 - oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
2726 + oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2727 + the_repository->hash_algo);
2728
2729 graph_commit = lookup_commit(r, &cur_oid);
2730 odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
diff-lib.c
+2 -2
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
160 dpath->next = NULL;
161 memcpy(dpath->path, ce->name, path_len);
162 dpath->path[path_len] = '\0';
163 - oidclr(&dpath->oid);
163 + oidclr(&dpath->oid, the_repository->hash_algo);
164 memset(&(dpath->parent[0]), 0,
165 sizeof(struct combine_diff_parent)*5);
166
@@ -412,7 +412,7 @@ static int show_modified(struct rev_info *revs,
412 memcpy(p->path, new_entry->name, pathlen);
413 p->path[pathlen] = 0;
414 p->mode = mode;
415 - oidclr(&p->oid);
415 + oidclr(&p->oid, the_repository->hash_algo);
416 memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
417 p->parent[0].status = DIFF_STATUS_MODIFIED;
418 p->parent[0].mode = new_entry->ce_mode;
diff.c
+3 -3
@@ -4567,7 +4567,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
4567 if (!one->oid_valid) {
4568 struct stat st;
4569 if (one->is_stdin) {
4570 - oidclr(&one->oid);
4570 + oidclr(&one->oid, the_repository->hash_algo);
4571 return;
4572 }
4573 if (lstat(one->path, &st) < 0)
@@ -4577,7 +4577,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
4577 }
4578 }
4579 else
4580 - oidclr(&one->oid);
4580 + oidclr(&one->oid, the_repository->hash_algo);
4581 }
4582
4583 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
6404 the_hash_algo->init_fn(&ctx);
6405 memset(&data, 0, sizeof(struct patch_id_t));
6406 data.ctx = &ctx;
6407 - oidclr(oid);
6407 + oidclr(oid, the_repository->hash_algo);
6408
6409 for (i = 0; i < q->nr; i++) {
6410 xpparam_t xpp;
dir.c
+3 -3
@@ -1687,7 +1687,7 @@ static void prep_exclude(struct dir_struct *dir,
1687 }
1688
1689 /* Try to read per-directory file */
1690 - oidclr(&oid_stat.oid);
1690 + oidclr(&oid_stat.oid, the_repository->hash_algo);
1691 oid_stat.valid = 0;
1692 if (dir->exclude_per_dir &&
1693 /*
@@ -3794,7 +3794,7 @@ static void read_oid(size_t pos, void *cb)
3794 rd->data = rd->end + 1;
3795 return;
3796 }
3797 - oidread(&ud->exclude_oid, rd->data);
3797 + oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
3798 rd->data += the_hash_algo->rawsz;
3799 }
3800
@@ -3802,7 +3802,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
3802 const unsigned char *sha1)
3803 {
3804 stat_data_from_disk(&oid_stat->stat, data);
3805 - oidread(&oid_stat->oid, sha1);
3805 + oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
3806 oid_stat->valid = 1;
3807 }
3808
hash-ll.h
+14
@@ -284,6 +284,20 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
284 dst->algo = src->algo;
285 }
286
287 +static inline void oidread(struct object_id *oid, const unsigned char *hash,
288 + const struct git_hash_algo *algop)
289 +{
290 + memcpy(oid->hash, hash, algop->rawsz);
291 + oid->algo = hash_algo_by_ptr(algop);
292 +}
293 +
294 +static inline void oidclr(struct object_id *oid,
295 + const struct git_hash_algo *algop)
296 +{
297 + memset(oid->hash, 0, GIT_MAX_RAWSZ);
298 + oid->algo = hash_algo_by_ptr(algop);
299 +}
300 +
301 static inline struct object_id *oiddup(const struct object_id *src)
302 {
303 struct object_id *dst = xmalloc(sizeof(struct object_id));
hash.h
-17
@@ -47,23 +47,6 @@ static inline void oidcpy_with_padding(struct object_id *dst,
47 dst->algo = src->algo;
48 }
49
50 -static inline void oidclr(struct object_id *oid)
51 -{
52 - memset(oid->hash, 0, GIT_MAX_RAWSZ);
53 - oid->algo = hash_algo_by_ptr(the_hash_algo);
54 -}
55 -
56 -static inline void oidread_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
57 -{
58 - memcpy(oid->hash, hash, algop->rawsz);
59 - oid->algo = hash_algo_by_ptr(algop);
60 -}
61 -
62 -static inline void oidread(struct object_id *oid, const unsigned char *hash)
63 -{
64 - oidread_algop(oid, hash, the_hash_algo);
65 -}
66 -
50 static inline int is_empty_blob_oid(const struct object_id *oid)
51 {
52 return oideq(oid, the_hash_algo->empty_blob);
http-push.c
+1 -1
@@ -1552,7 +1552,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
1552 free(url);
1553
1554 FREE_AND_NULL(*symref);
1555 - oidclr(oid);
1555 + oidclr(oid, the_repository->hash_algo);
1556
1557 if (buffer.len == 0)
1558 return;
http-walker.c
+1 -1
@@ -152,7 +152,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
152
153 newreq = xmalloc(sizeof(*newreq));
154 newreq->walker = walker;
155 - oidread(&newreq->oid, sha1);
155 + oidread(&newreq->oid, sha1, the_repository->hash_algo);
156 newreq->repo = data->alt;
157 newreq->state = WAITING;
158 newreq->req = NULL;
match-trees.c
+1 -1
@@ -229,7 +229,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
229 oid_to_hex(oid1));
230 if (*subpath) {
231 struct object_id tree_oid;
232 - oidread(&tree_oid, rewrite_here);
232 + oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
233 status = splice_tree(&tree_oid, subpath, oid2, &subtree);
234 if (status)
235 return status;
midx.c
+2 -1
@@ -304,7 +304,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
304 if (n >= m->num_objects)
305 return NULL;
306
307 - oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
307 + oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
308 + the_repository->hash_algo);
309 return oid;
310 }
311
notes-merge.c
+3 -3
@@ -240,7 +240,7 @@ static void diff_tree_local(struct notes_merge_options *o,
240 * (will be overwritten by following addition)
241 */
242 if (oideq(&mp->local, &uninitialized))
243 - oidclr(&mp->local);
243 + oidclr(&mp->local, the_repository->hash_algo);
244 } else if (is_null_oid(&p->one->oid)) { /* addition */
245 /*
246 * Either this is a true addition (1), or it is part
@@ -556,7 +556,7 @@ int notes_merge(struct notes_merge_options *o,
556
557 assert(o->local_ref && o->remote_ref);
558 assert(!strcmp(o->local_ref, local_tree->ref));
559 - oidclr(result_oid);
559 + oidclr(result_oid, the_repository->hash_algo);
560
561 trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
562 o->local_ref, o->remote_ref);
@@ -579,7 +579,7 @@ int notes_merge(struct notes_merge_options *o,
579 * unborn ref, perform the merge using an empty notes tree.
580 */
581 if (!check_refname_format(o->remote_ref, 0)) {
582 - oidclr(&remote_oid);
582 + oidclr(&remote_oid, the_repository->hash_algo);
583 remote = NULL;
584 } else {
585 die("Failed to resolve remote notes ref '%s'",
notes.c
+4 -4
@@ -353,7 +353,7 @@ static void add_non_note(struct notes_tree *t, char *path,
353 n->next = NULL;
354 n->path = path;
355 n->mode = mode;
356 - oidread(&n->oid, sha1);
356 + oidread(&n->oid, sha1, the_repository->hash_algo);
357 t->prev_non_note = n;
358
359 if (!t->first_non_note) {
@@ -1036,7 +1036,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1036 die("Failed to read notes tree referenced by %s (%s)",
1037 notes_ref, oid_to_hex(&object_oid));
1038
1039 - oidclr(&root_tree.key_oid);
1039 + oidclr(&root_tree.key_oid, the_repository->hash_algo);
1040 oidcpy(&root_tree.val_oid, &oid);
1041 load_subtree(t, &root_tree, t->root, 0);
1042 }
@@ -1146,8 +1146,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
1146 if (!t)
1147 t = &default_notes_tree;
1148 assert(t->initialized);
1149 - oidread(&l.key_oid, object_sha1);
1150 - oidclr(&l.val_oid);
1149 + oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
1150 + oidclr(&l.val_oid, the_repository->hash_algo);
1151 note_tree_remove(t, t->root, 0, &l);
1152 if (is_null_oid(&l.val_oid)) /* no note was removed */
1153 return 1;
object-file-convert.c
+1 -1
@@ -56,7 +56,7 @@ static int decode_tree_entry_raw(struct object_id *oid, const char **path,
56 return -1;
57 *len = strlen(*path) + 1;
58
59 - oidread_algop(oid, (const unsigned char *)*path + *len, algo);
59 + oidread(oid, (const unsigned char *)*path + *len, algo);
60 return 0;
61 }
62
object-file.c
+2 -2
@@ -1446,7 +1446,7 @@ static int loose_object_info(struct repository *r,
1446 int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
1447
1448 if (oi->delta_base_oid)
1449 - oidclr(oi->delta_base_oid);
1449 + oidclr(oi->delta_base_oid, the_repository->hash_algo);
1450
1451 /*
1452 * 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,
1580 if (oi->disk_sizep)
1581 *(oi->disk_sizep) = 0;
1582 if (oi->delta_base_oid)
1583 - oidclr(oi->delta_base_oid);
1583 + oidclr(oi->delta_base_oid, the_repository->hash_algo);
1584 if (oi->type_name)
1585 strbuf_addstr(oi->type_name, type_name(co->type));
1586 if (oi->contentp)
packfile.c
+6 -4
@@ -1251,7 +1251,7 @@ static int get_delta_base_oid(struct packed_git *p,
1251 {
1252 if (type == OBJ_REF_DELTA) {
1253 unsigned char *base = use_pack(p, w_curs, curpos, NULL);
1254 - oidread(oid, base);
1254 + oidread(oid, base, the_repository->hash_algo);
1255 return 0;
1256 } else if (type == OBJ_OFS_DELTA) {
1257 uint32_t base_pos;
@@ -1593,7 +1593,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
1593 goto out;
1594 }
1595 } else
1596 - oidclr(oi->delta_base_oid);
1596 + oidclr(oi->delta_base_oid, the_repository->hash_algo);
1597 }
1598
1599 oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
@@ -1917,10 +1917,12 @@ int nth_packed_object_id(struct object_id *oid,
1917 return -1;
1918 index += 4 * 256;
1919 if (p->index_version == 1) {
1920 - oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
1920 + oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),
1921 + the_repository->hash_algo);
1922 } else {
1923 index += 8;
1923 - oidread(oid, index + st_mult(hashsz, n));
1924 + oidread(oid, index + st_mult(hashsz, n),
1925 + the_repository->hash_algo);
1926 }
1927 return 0;
1928 }
read-cache.c
+5 -3
@@ -1728,7 +1728,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
1728
1729 end = (unsigned char *)hdr + size;
1730 start = end - the_hash_algo->rawsz;
1731 - oidread(&oid, start);
1731 + oidread(&oid, start, the_repository->hash_algo);
1732 if (oideq(&oid, null_oid()))
1733 return 0;
1734
@@ -1876,7 +1876,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
1876 ce->ce_flags = flags & ~CE_NAMEMASK;
1877 ce->ce_namelen = len;
1878 ce->index = 0;
1879 - oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data));
1879 + oidread(&ce->oid, (const unsigned char *)ondisk + offsetof(struct ondisk_cache_entry, data),
1880 + the_repository->hash_algo);
1881
1882 if (expand_name_field) {
1883 if (copy_len)
@@ -2249,7 +2250,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2250 if (verify_hdr(hdr, mmap_size) < 0)
2251 goto unmap;
2252
2252 - oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
2253 + oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz,
2254 + the_repository->hash_algo);
2255 istate->version = ntohl(hdr->hdr_version);
2256 istate->cache_nr = ntohl(hdr->hdr_entries);
2257 istate->cache_alloc = alloc_nr(istate->cache_nr);
refs.c
+3 -3
@@ -1822,7 +1822,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1822 failure_errno != ENOTDIR)
1823 return NULL;
1824
1825 - oidclr(oid);
1825 + oidclr(oid, the_repository->hash_algo);
1826 if (*flags & REF_BAD_NAME)
1827 *flags |= REF_ISBROKEN;
1828 return refname;
@@ -1832,7 +1832,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1832
1833 if (!(read_flags & REF_ISSYMREF)) {
1834 if (*flags & REF_BAD_NAME) {
1835 - oidclr(oid);
1835 + oidclr(oid, the_repository->hash_algo);
1836 *flags |= REF_ISBROKEN;
1837 }
1838 return refname;
@@ -1840,7 +1840,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1840
1841 refname = sb_refname.buf;
1842 if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
1843 - oidclr(oid);
1843 + oidclr(oid, the_repository->hash_algo);
1844 return refname;
1845 }
1846 if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
refs/files-backend.c
+3 -3
@@ -246,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
246
247 if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
248 &oid, &flag)) {
249 - oidclr(&oid);
249 + oidclr(&oid, the_repository->hash_algo);
250 flag |= REF_ISBROKEN;
251 } else if (is_null_oid(&oid)) {
252 /*
@@ -263,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
263 if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
264 if (!refname_is_safe(refname))
265 die("loose refname is dangerous: %s", refname);
266 - oidclr(&oid);
266 + oidclr(&oid, the_repository->hash_algo);
267 flag |= REF_BAD_NAME | REF_ISBROKEN;
268 }
269 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,
1150
1151 if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
1152 &lock->old_oid, NULL))
1153 - oidclr(&lock->old_oid);
1153 + oidclr(&lock->old_oid, the_repository->hash_algo);
1154 goto out;
1155
1156 error_return:
refs/packed-backend.c
+3 -3
@@ -894,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
894 if (!refname_is_safe(iter->base.refname))
895 die("packed refname is dangerous: %s",
896 iter->base.refname);
897 - oidclr(&iter->oid);
897 + oidclr(&iter->oid, the_repository->hash_algo);
898 iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
899 }
900 if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -919,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
919 * we suppress it if the reference is broken:
920 */
921 if ((iter->base.flags & REF_ISBROKEN)) {
922 - oidclr(&iter->peeled);
922 + oidclr(&iter->peeled, the_repository->hash_algo);
923 iter->base.flags &= ~REF_KNOWS_PEELED;
924 } else {
925 iter->base.flags |= REF_KNOWS_PEELED;
926 }
927 } else {
928 - oidclr(&iter->peeled);
928 + oidclr(&iter->peeled, the_repository->hash_algo);
929 }
930
931 return ITER_OK;
refs/reftable-backend.c
+23 -14
@@ -217,7 +217,8 @@ static int read_ref_without_reload(struct reftable_stack *stack,
217 strbuf_addstr(referent, ref.value.symref);
218 *type |= REF_ISSYMREF;
219 } else if (reftable_ref_record_val1(&ref)) {
220 - oidread(oid, reftable_ref_record_val1(&ref));
220 + oidread(oid, reftable_ref_record_val1(&ref),
221 + the_repository->hash_algo);
222 } else {
223 /* We got a tombstone, which should not happen. */
224 BUG("unhandled reference value type %d", ref.value_type);
@@ -483,15 +484,17 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
484
485 switch (iter->ref.value_type) {
486 case REFTABLE_REF_VAL1:
486 - oidread(&iter->oid, iter->ref.value.val1);
487 + oidread(&iter->oid, iter->ref.value.val1,
488 + the_repository->hash_algo);
489 break;
490 case REFTABLE_REF_VAL2:
489 - oidread(&iter->oid, iter->ref.value.val2.value);
491 + oidread(&iter->oid, iter->ref.value.val2.value,
492 + the_repository->hash_algo);
493 break;
494 case REFTABLE_REF_SYMREF:
495 if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
496 RESOLVE_REF_READING, &iter->oid, &flags))
494 - oidclr(&iter->oid);
497 + oidclr(&iter->oid, the_repository->hash_algo);
498 break;
499 default:
500 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)
506 if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
507 if (!refname_is_safe(iter->ref.refname))
508 die(_("refname is dangerous: %s"), iter->ref.refname);
506 - oidclr(&iter->oid);
509 + oidclr(&iter->oid, the_repository->hash_algo);
510 flags |= REF_BAD_NAME | REF_ISBROKEN;
511 }
512
@@ -545,7 +548,8 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
548 (struct reftable_ref_iterator *)ref_iterator;
549
550 if (iter->ref.value_type == REFTABLE_REF_VAL2) {
548 - oidread(peeled, iter->ref.value.val2.target_value);
551 + oidread(peeled, iter->ref.value.val2.target_value,
552 + the_repository->hash_algo);
553 return 0;
554 }
555
@@ -1776,8 +1780,8 @@ static int yield_log_record(struct reftable_log_record *log,
1780 struct object_id old_oid, new_oid;
1781 const char *full_committer;
1782
1779 - oidread(&old_oid, log->value.update.old_hash);
1780 - oidread(&new_oid, log->value.update.new_hash);
1783 + oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
1784 + oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
1785
1786 /*
1787 * 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,
2182 if (ret < 0)
2183 goto done;
2184 if (reftable_ref_record_val1(&ref_record))
2181 - oidread(&oid, reftable_ref_record_val1(&ref_record));
2185 + oidread(&oid, reftable_ref_record_val1(&ref_record),
2186 + the_repository->hash_algo);
2187 prepare_fn(refname, &oid, policy_cb_data);
2188
2189 while (1) {
@@ -2193,8 +2198,10 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2198 break;
2199 }
2200
2196 - oidread(&old_oid, log.value.update.old_hash);
2197 - oidread(&new_oid, log.value.update.new_hash);
2201 + oidread(&old_oid, log.value.update.old_hash,
2202 + the_repository->hash_algo);
2203 + oidread(&new_oid, log.value.update.new_hash,
2204 + the_repository->hash_algo);
2205
2206 /*
2207 * 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,
2232 struct object_id old_oid, new_oid;
2233
2234 *dest = logs[i];
2228 - oidread(&old_oid, logs[i].value.update.old_hash);
2229 - oidread(&new_oid, logs[i].value.update.new_hash);
2235 + oidread(&old_oid, logs[i].value.update.old_hash,
2236 + the_repository->hash_algo);
2237 + oidread(&new_oid, logs[i].value.update.new_hash,
2238 + the_repository->hash_algo);
2239
2240 if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
2241 (timestamp_t)logs[i].value.update.time,
@@ -2243,7 +2252,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2252
2253 if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
2254 reftable_ref_record_val1(&ref_record))
2246 - oidread(&arg.update_oid, last_hash);
2255 + oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
2256
2257 arg.refs = refs;
2258 arg.records = rewritten;
remote.c
+4 -4
@@ -1164,7 +1164,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
1164 static struct ref *alloc_delete_ref(void)
1165 {
1166 struct ref *ref = alloc_ref("(delete)");
1167 - oidclr(&ref->new_oid);
1167 + oidclr(&ref->new_oid, the_repository->hash_algo);
1168 return ref;
1169 }
1170
@@ -2531,7 +2531,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
2531 if (!*colon)
2532 entry->use_tracking = 1;
2533 else if (!colon[1])
2534 - oidclr(&entry->expect);
2534 + oidclr(&entry->expect, the_repository->hash_algo);
2535 else if (repo_get_oid(the_repository, colon + 1, &entry->expect))
2536 return error(_("cannot parse expected object name '%s'"),
2537 colon + 1);
@@ -2733,7 +2733,7 @@ static void apply_cas(struct push_cas_option *cas,
2733 else if (remote_tracking(remote, ref->name,
2734 &ref->old_oid_expect,
2735 &ref->tracking_ref))
2736 - oidclr(&ref->old_oid_expect);
2736 + oidclr(&ref->old_oid_expect, the_repository->hash_algo);
2737 else
2738 ref->check_reachable = cas->use_force_if_includes;
2739 return;
@@ -2747,7 +2747,7 @@ static void apply_cas(struct push_cas_option *cas,
2747 if (remote_tracking(remote, ref->name,
2748 &ref->old_oid_expect,
2749 &ref->tracking_ref))
2750 - oidclr(&ref->old_oid_expect);
2750 + oidclr(&ref->old_oid_expect, the_repository->hash_algo);
2751 else
2752 ref->check_reachable = cas->use_force_if_includes;
2753 }
resolve-undo.c
+2 -1
@@ -93,7 +93,8 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
93 continue;
94 if (size < rawsz)
95 goto error;
96 - oidread(&ui->oid[i], (const unsigned char *)data);
96 + oidread(&ui->oid[i], (const unsigned char *)data,
97 + the_repository->hash_algo);
98 size -= rawsz;
99 data += rawsz;
100 }
sequencer.c
+2 -2
@@ -3334,12 +3334,12 @@ static int rollback_is_safe(void)
3334 strbuf_release(&sb);
3335 }
3336 else if (errno == ENOENT)
3337 - oidclr(&expected_head);
3337 + oidclr(&expected_head, the_repository->hash_algo);
3338 else
3339 die_errno(_("could not read '%s'"), git_path_abort_safety_file());
3340
3341 if (repo_get_oid(the_repository, "HEAD", &actual_head))
3342 - oidclr(&actual_head);
3342 + oidclr(&actual_head, the_repository->hash_algo);
3343
3344 return oideq(&actual_head, &expected_head);
3345 }
split-index.c
+1 -1
@@ -29,7 +29,7 @@ int read_link_extension(struct index_state *istate,
29 if (sz < the_hash_algo->rawsz)
30 return error("corrupt link extension (too short)");
31 si = init_split_index(istate);
32 - oidread(&si->base_oid, data);
32 + oidread(&si->base_oid, data, the_repository->hash_algo);
33 data += the_hash_algo->rawsz;
34 sz -= the_hash_algo->rawsz;
35 if (!sz)
submodule-config.c
+1 -1
@@ -682,7 +682,7 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
682 int ret = 0;
683
684 if (is_null_oid(treeish_name)) {
685 - oidclr(gitmodules_oid);
685 + oidclr(gitmodules_oid, the_repository->hash_algo);
686 return 1;
687 }
688
t/helper/test-submodule-config.c
+1 -1
@@ -44,7 +44,7 @@ int cmd__submodule_config(int argc, const char **argv)
44 path_or_name = arg[1];
45
46 if (commit[0] == '\0')
47 - oidclr(&commit_oid);
47 + oidclr(&commit_oid, the_repository->hash_algo);
48 else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
49 die_usage(argc, argv, "Commit not found.");
50
tree-walk.c
+2 -2
@@ -38,8 +38,8 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
38 desc->entry.path = path;
39 desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode);
40 desc->entry.pathlen = len - 1;
41 - oidread_algop(&desc->entry.oid, (const unsigned char *)path + len,
42 - desc->algo);
41 + oidread(&desc->entry.oid, (const unsigned char *)path + len,
42 + desc->algo);
43
44 return 0;
45 }