summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorLibravatar Matheus Tavares <matheus.bernardino@usp.br>2020-01-30 17:32:23 -0300
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-01-31 10:45:39 -0800
commitb98d18858187eb926912d5199533a6d2a14d5007 (patch)
tree11390f92d70b5c1f1b185004e4c394203768a712 /sha1-file.c
parentsha1-file: pass git_hash_algo to hash_object_file() (diff)
downloadtgif-b98d18858187eb926912d5199533a6d2a14d5007.tar.xz
sha1-file: allow check_object_signature() to handle any repo
Some callers of check_object_signature() can work on arbitrary repositories, but the repo does not get passed to this function. Instead, the_repository is always used internally. To fix possible inconsistencies, allow the function to receive a struct repository and make those callers pass on the repo being handled. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 46a79e7614..fcedef97d4 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -971,8 +971,8 @@ void *xmmap(void *start, size_t length,
* With "map" == NULL, try reading the object named with "oid" using
* the streaming interface and rehash it to do the same.
*/
-int check_object_signature(const struct object_id *oid, void *map,
- unsigned long size, const char *type)
+int check_object_signature(struct repository *r, const struct object_id *oid,
+ void *map, unsigned long size, const char *type)
{
struct object_id real_oid;
enum object_type obj_type;
@@ -982,11 +982,11 @@ int check_object_signature(const struct object_id *oid, void *map,
int hdrlen;
if (map) {
- hash_object_file(the_hash_algo, map, size, type, &real_oid);
+ hash_object_file(r->hash_algo, map, size, type, &real_oid);
return !oideq(oid, &real_oid) ? -1 : 0;
}
- st = open_istream(the_repository, oid, &obj_type, &size, NULL);
+ st = open_istream(r, oid, &obj_type, &size, NULL);
if (!st)
return -1;
@@ -994,8 +994,8 @@ int check_object_signature(const struct object_id *oid, void *map,
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1;
/* Sha1.. */
- the_hash_algo->init_fn(&c);
- the_hash_algo->update_fn(&c, hdr, hdrlen);
+ r->hash_algo->init_fn(&c);
+ r->hash_algo->update_fn(&c, hdr, hdrlen);
for (;;) {
char buf[1024 * 16];
ssize_t readlen = read_istream(st, buf, sizeof(buf));
@@ -1006,9 +1006,9 @@ int check_object_signature(const struct object_id *oid, void *map,
}
if (!readlen)
break;
- the_hash_algo->update_fn(&c, buf, readlen);
+ r->hash_algo->update_fn(&c, buf, readlen);
}
- the_hash_algo->final_fn(real_oid.hash, &c);
+ r->hash_algo->final_fn(real_oid.hash, &c);
close_istream(st);
return !oideq(oid, &real_oid) ? -1 : 0;
}
@@ -2456,8 +2456,9 @@ int read_loose_object(const char *path,
git_inflate_end(&stream);
goto out;
}
- if (check_object_signature(expected_oid, *contents,
- *size, type_name(*type))) {
+ if (check_object_signature(the_repository, expected_oid,
+ *contents, *size,
+ type_name(*type))) {
error(_("hash mismatch for %s (expected %s)"), path,
oid_to_hex(expected_oid));
free(*contents);