Skip to content

Commit 9da95bd

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f483657 commit 9da95bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+163
-140
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3680,7 +3680,7 @@ static int try_threeway(struct apply_state *state,
36803680
if (status) {
36813681
patch->conflicted_threeway = 1;
36823682
if (patch->is_new)
3683-
oidclr(&patch->threeway_stage[0]);
3683+
oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
36843684
else
36853685
oidcpy(&patch->threeway_stage[0], &pre_oid);
36863686
oidcpy(&patch->threeway_stage[1], &our_oid);

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
12461246
goto error_out;
12471247
return 0;
12481248
error_out:
1249-
oidclr(&origin->blob_oid);
1249+
oidclr(&origin->blob_oid, the_repository->hash_algo);
12501250
origin->mode = S_IFINVALID;
12511251
return -1;
12521252
}

builtin/am.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
408408
read_commit_msg(state);
409409

410410
if (read_state_file(&sb, state, "original-commit", 1) < 0)
411-
oidclr(&state->orig_commit);
411+
oidclr(&state->orig_commit, the_repository->hash_algo);
412412
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
413413
die(_("could not parse %s"), am_path(state, "original-commit"));
414414

@@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
11211121
unlink(am_path(state, "author-script"));
11221122
unlink(am_path(state, "final-commit"));
11231123

1124-
oidclr(&state->orig_commit);
1124+
oidclr(&state->orig_commit, the_repository->hash_algo);
11251125
unlink(am_path(state, "original-commit"));
11261126
refs_delete_ref(get_main_ref_store(the_repository), NULL,
11271127
"REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
21512151
if (get_oid_hex(sb.buf, &abort_safety))
21522152
die(_("could not parse %s"), am_path(state, "abort-safety"));
21532153
} else
2154-
oidclr(&abort_safety);
2154+
oidclr(&abort_safety, the_repository->hash_algo);
21552155
strbuf_release(&sb);
21562156

21572157
if (repo_get_oid(the_repository, "HEAD", &head))
2158-
oidclr(&head);
2158+
oidclr(&head, the_repository->hash_algo);
21592159

21602160
if (oideq(&head, &abort_safety))
21612161
return 1;

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
415415
struct object_id oid;
416416
char *hex = xmallocz(GIT_MAX_HEXSZ);
417417

418-
oidclr(&oid);
418+
oidclr(&oid, the_repository->hash_algo);
419419
put_be32(oid.hash + hashsz - 4, counter++);
420420
return oid_to_hex_r(hex, &oid);
421421
}

builtin/fast-import.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
12791279
e->versions[0].mode = e->versions[1].mode;
12801280
e->name = to_atom(c, strlen(c));
12811281
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);
12841286
c += the_hash_algo->rawsz;
12851287
}
12861288
free(buf);
@@ -1386,7 +1388,7 @@ static void tree_content_replace(
13861388
{
13871389
if (!S_ISDIR(mode))
13881390
die("Root cannot be a non-directory");
1389-
oidclr(&root->versions[0].oid);
1391+
oidclr(&root->versions[0].oid, the_repository->hash_algo);
13901392
oidcpy(&root->versions[1].oid, oid);
13911393
if (root->tree)
13921394
release_tree_content_recursive(root->tree);
@@ -1445,7 +1447,7 @@ static int tree_content_set(
14451447
if (S_ISDIR(e->versions[0].mode))
14461448
e->versions[0].mode |= NO_DELTA;
14471449

1448-
oidclr(&root->versions[1].oid);
1450+
oidclr(&root->versions[1].oid, the_repository->hash_algo);
14491451
return 1;
14501452
}
14511453
if (!S_ISDIR(e->versions[1].mode)) {
@@ -1455,7 +1457,7 @@ static int tree_content_set(
14551457
if (!e->tree)
14561458
load_tree(e);
14571459
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);
14591461
return 1;
14601462
}
14611463
return 0;
@@ -1467,7 +1469,7 @@ static int tree_content_set(
14671469
e = new_tree_entry();
14681470
e->name = to_atom(p, n);
14691471
e->versions[0].mode = 0;
1470-
oidclr(&e->versions[0].oid);
1472+
oidclr(&e->versions[0].oid, the_repository->hash_algo);
14711473
t->entries[t->entry_count++] = e;
14721474
if (*slash1) {
14731475
e->tree = new_tree_content(8);
@@ -1478,7 +1480,7 @@ static int tree_content_set(
14781480
e->versions[1].mode = mode;
14791481
oidcpy(&e->versions[1].oid, oid);
14801482
}
1481-
oidclr(&root->versions[1].oid);
1483+
oidclr(&root->versions[1].oid, the_repository->hash_algo);
14821484
return 1;
14831485
}
14841486

@@ -1523,7 +1525,8 @@ static int tree_content_remove(
15231525
if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
15241526
for (n = 0; n < e->tree->entry_count; n++) {
15251527
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);
15271530
return 1;
15281531
}
15291532
}
@@ -1542,8 +1545,8 @@ static int tree_content_remove(
15421545
release_tree_content_recursive(e->tree);
15431546
e->tree = NULL;
15441547
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);
15471550
return 1;
15481551
}
15491552

@@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
16091612
return 0;
16101613
}
16111614
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);
16131616
if (!force_update && !is_null_oid(&old_oid)) {
16141617
struct commit *old_cmit, *new_cmit;
16151618
int ret;
@@ -2550,8 +2553,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
25502553
static void file_change_deleteall(struct branch *b)
25512554
{
25522555
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);
25552558
load_tree(&b->branch_tree);
25562559
b->num_notes = 0;
25572560
}
@@ -2570,8 +2573,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
25702573
static void parse_from_existing(struct branch *b)
25712574
{
25722575
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);
25752578
} else {
25762579
unsigned long size;
25772580
char *buf;
@@ -2894,9 +2897,9 @@ static void parse_reset_branch(const char *arg)
28942897

28952898
b = lookup_branch(arg);
28962899
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);
29002903
if (b->branch_tree.tree) {
29012904
release_tree_content_recursive(b->branch_tree.tree);
29022905
b->branch_tree.tree = NULL;

builtin/fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
2929
; /* <oid>, leave oid as name */
3030
} else {
3131
/* <ref>, clear cruft from oid */
32-
oidclr(&oid);
32+
oidclr(&oid, the_repository->hash_algo);
3333
}
3434
} else {
3535
/* <ref>, clear cruft from get_oid_hex */
36-
oidclr(&oid);
36+
oidclr(&oid, the_repository->hash_algo);
3737
}
3838

3939
ref = alloc_ref(name);

builtin/index-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
528528

529529
switch (obj->type) {
530530
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);
532533
use(the_hash_algo->rawsz);
533534
break;
534535
case OBJ_OFS_DELTA:
@@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
13721373
obj[1].idx.offset += write_compressed(f, buf, size);
13731374
obj[0].idx.crc32 = crc32_end(f);
13741375
hashflush(f);
1375-
oidread(&obj->idx.oid, sha1);
1376+
oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
13761377
return obj;
13771378
}
13781379

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
19381938
free(bases->patch_id);
19391939
bases->nr_patch_id = 0;
19401940
bases->alloc_patch_id = 0;
1941-
oidclr(&bases->base_commit);
1941+
oidclr(&bases->base_commit, the_repository->hash_algo);
19421942
}
19431943

19441944
static const char *diff_title(struct strbuf *sb,

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
494494
strbuf_branchname(&bname, remote, 0);
495495
remote = bname.buf;
496496

497-
oidclr(&branch_head);
497+
oidclr(&branch_head, the_repository->hash_algo);
498498
remote_head = get_merge_parent(remote);
499499
if (!remote_head)
500500
die(_("'%s' does not point to a commit"), remote);
@@ -1690,7 +1690,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16901690
* index and working tree polluted.
16911691
*/
16921692
if (save_state(&stash))
1693-
oidclr(&stash);
1693+
oidclr(&stash, the_repository->hash_algo);
16941694

16951695
for (i = 0; i < use_strategies_nr; i++) {
16961696
int ret, cnt;

builtin/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
828828
if (partial->parents)
829829
oidcpy(&parent_oid, &partial->parents->item->object.oid);
830830
else
831-
oidclr(&parent_oid);
831+
oidclr(&parent_oid, the_repository->hash_algo);
832832

833833
CALLOC_ARRAY(t, 1);
834834
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
20782078
oidread(&base_ref,
20792079
use_pack(p, &w_curs,
20802080
entry->in_pack_offset + used,
2081-
NULL));
2081+
NULL),
2082+
the_repository->hash_algo);
20822083
have_base = 1;
20832084
}
20842085
entry->in_pack_header_size = used + the_hash_algo->rawsz;

builtin/pack-redundant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
100100
const unsigned char *oid)
101101
{
102102
struct llist_item *new_item = llist_item_get();
103-
oidread(&new_item->oid, oid);
103+
oidread(&new_item->oid, oid, the_repository->hash_algo);
104104
new_item->next = NULL;
105105

106106
if (after) {

builtin/patch-id.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
7070
git_hash_ctx ctx;
7171

7272
the_hash_algo->init_fn(&ctx);
73-
oidclr(result);
73+
oidclr(result, the_repository->hash_algo);
7474

7575
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
7676
char *line = line_buf->buf;
@@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
166166
}
167167

168168
if (!found_next)
169-
oidclr(next_oid);
169+
oidclr(next_oid, the_repository->hash_algo);
170170

171171
flush_one_hunk(result, &ctx);
172172

@@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
179179
int patchlen;
180180
struct strbuf line_buf = STRBUF_INIT;
181181

182-
oidclr(&oid);
182+
oidclr(&oid, the_repository->hash_algo);
183183
while (!feof(stdin)) {
184184
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
185185
flush_current_id(patchlen, &oid, &result);

builtin/pull.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10381038
die_conclude_merge();
10391039

10401040
if (repo_get_oid(the_repository, "HEAD", &orig_head))
1041-
oidclr(&orig_head);
1041+
oidclr(&orig_head, the_repository->hash_algo);
10421042

10431043
if (opt_rebase) {
10441044
if (opt_autostash == -1)
@@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10531053
_("Please commit or stash them."), 1, 0);
10541054

10551055
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
1056-
oidclr(&rebase_fork_point);
1056+
oidclr(&rebase_fork_point, the_repository->hash_algo);
10571057
}
10581058

10591059
if (run_fetch(repo, refspecs))
@@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10631063
return 0;
10641064

10651065
if (repo_get_oid(the_repository, "HEAD", &curr_head))
1066-
oidclr(&curr_head);
1066+
oidclr(&curr_head, the_repository->hash_algo);
10671067

10681068
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
10691069
!oideq(&orig_head, &curr_head)) {

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
741741
already_done = 1;
742742
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
743743
&push_cert_oid))
744-
oidclr(&push_cert_oid);
744+
oidclr(&push_cert_oid, the_repository->hash_algo);
745745

746746
memset(&sigcheck, '\0', sizeof(sigcheck));
747747

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
167167
return error(_("'%s' is not a valid ref name"), ref->buf);
168168

169169
if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
170-
oidclr(prev);
170+
oidclr(prev, the_repository->hash_algo);
171171
else if (!force)
172172
return error(_("replace ref '%s' already exists"), ref->buf);
173173
return 0;

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
377377
if (!force) {
378378
struct object_id oid;
379379
if (repo_get_oid(the_repository, "HEAD", &oid))
380-
oidclr(&oid);
380+
oidclr(&oid, the_repository->hash_algo);
381381
if (check_local_mod(&oid, index_only))
382382
exit(1);
383383
}

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
650650
die(_("'%s' is not a valid tag name."), tag);
651651

652652
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
653-
oidclr(&prev);
653+
oidclr(&prev, the_repository->hash_algo);
654654
else if (!force)
655655
die(_("tag '%s' already exists"), tag);
656656

builtin/unpack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
439439
struct object_id base_oid;
440440

441441
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);
443443
use(the_hash_algo->rawsz);
444444
delta_data = get_data(delta_size);
445445
if (!delta_data)
@@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
451451
return; /* we are done */
452452
else {
453453
/* cannot resolve yet --- queue it */
454-
oidclr(&obj_list[nr].oid);
454+
oidclr(&obj_list[nr].oid, the_repository->hash_algo);
455455
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
456456
return;
457457
}
@@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
500500
* The delta base object is itself a delta that
501501
* has not been resolved yet.
502502
*/
503-
oidclr(&obj_list[nr].oid);
503+
oidclr(&obj_list[nr].oid, the_repository->hash_algo);
504504
add_delta_to_list(nr, null_oid(), base_offset,
505505
delta_data, delta_size);
506506
return;

0 commit comments

Comments
 (0)