sha1-file: pass git_hash_algo to hash_object_file()
Allow hash_object_file() to work on arbitrary repos by introducing a git_hash_algo parameter. Change callers which have a struct repository pointer in their scope to pass on the git_hash_algo from the said repo. For all other callers, pass on the_hash_algo, which was already being used internally at hash_object_file(). This functionality will be used in the following patch to make check_object_signature() be able to work on arbitrary repos (which, in turn, will be used to fix an inconsistency at object.c:parse_object()). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
7ad5c44d9c
commit
2dcde20e1c
@ -407,13 +407,15 @@ static int update_one(struct cache_tree *it,
|
||||
|
||||
if (repair) {
|
||||
struct object_id oid;
|
||||
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
|
||||
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
|
||||
tree_type, &oid);
|
||||
if (has_object_file_with_flags(&oid, OBJECT_INFO_SKIP_FETCH_OBJECT))
|
||||
oidcpy(&it->oid, &oid);
|
||||
else
|
||||
to_invalidate = 1;
|
||||
} else if (dryrun) {
|
||||
hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
|
||||
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
|
||||
tree_type, &it->oid);
|
||||
} else if (write_object_file(buffer.buf, buffer.len, tree_type,
|
||||
&it->oid)) {
|
||||
strbuf_release(&buffer);
|
||||
@ -828,7 +830,8 @@ static void verify_one(struct repository *r,
|
||||
strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '\0');
|
||||
strbuf_add(&tree_buf, oid->hash, r->hash_algo->rawsz);
|
||||
}
|
||||
hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid);
|
||||
hash_object_file(r->hash_algo, tree_buf.buf, tree_buf.len, tree_type,
|
||||
&new_oid);
|
||||
if (!oideq(&new_oid, &it->oid))
|
||||
BUG("cache-tree for path %.*s does not match. "
|
||||
"Expected %s got %s", len, path->buf,
|
||||
|
||||
Reference in New Issue
Block a user