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>
This commit is contained in:

committed by
Junio C Hamano

parent
f4836570a7
commit
9da95bda74
@ -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;
|
||||
|
Reference in New Issue
Block a user