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>
This commit is contained in:
parent
2dcde20e1c
commit
b98d188581
@ -293,7 +293,8 @@ static void export_blob(const struct object_id *oid)
|
|||||||
buf = read_object_file(oid, &type, &size);
|
buf = read_object_file(oid, &type, &size);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
die("could not read blob %s", oid_to_hex(oid));
|
die("could not read blob %s", oid_to_hex(oid));
|
||||||
if (check_object_signature(oid, buf, size, type_name(type)) < 0)
|
if (check_object_signature(the_repository, oid, buf, size,
|
||||||
|
type_name(type)) < 0)
|
||||||
die("oid mismatch in blob %s", oid_to_hex(oid));
|
die("oid mismatch in blob %s", oid_to_hex(oid));
|
||||||
object = parse_object_buffer(the_repository, oid, type,
|
object = parse_object_buffer(the_repository, oid, type,
|
||||||
size, buf, &eaten);
|
size, buf, &eaten);
|
||||||
|
@ -1384,8 +1384,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
|
|||||||
if (!base_obj->data)
|
if (!base_obj->data)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (check_object_signature(&d->oid, base_obj->data,
|
if (check_object_signature(the_repository, &d->oid,
|
||||||
base_obj->size, type_name(type)))
|
base_obj->data, base_obj->size,
|
||||||
|
type_name(type)))
|
||||||
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
|
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
|
||||||
base_obj->obj = append_obj_to_pack(f, d->oid.hash,
|
base_obj->obj = append_obj_to_pack(f, d->oid.hash,
|
||||||
base_obj->data, base_obj->size, type);
|
base_obj->data, base_obj->size, type);
|
||||||
|
@ -29,8 +29,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
|
|||||||
const struct object_id *repl = lookup_replace_object(the_repository, oid);
|
const struct object_id *repl = lookup_replace_object(the_repository, oid);
|
||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
if (type == type_from_string(expected_type))
|
if (type == type_from_string(expected_type)) {
|
||||||
ret = check_object_signature(repl, buffer, size, expected_type);
|
ret = check_object_signature(the_repository, repl,
|
||||||
|
buffer, size,
|
||||||
|
expected_type);
|
||||||
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
3
cache.h
3
cache.h
@ -1363,7 +1363,8 @@ int git_open_cloexec(const char *name, int flags);
|
|||||||
int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
|
int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
|
||||||
int parse_loose_header(const char *hdr, unsigned long *sizep);
|
int parse_loose_header(const char *hdr, unsigned long *sizep);
|
||||||
|
|
||||||
int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
|
int check_object_signature(struct repository *r, const struct object_id *oid,
|
||||||
|
void *buf, unsigned long size, const char *type);
|
||||||
|
|
||||||
int finalize_object_file(const char *tmpfile, const char *filename);
|
int finalize_object_file(const char *tmpfile, const char *filename);
|
||||||
|
|
||||||
|
5
object.c
5
object.c
@ -262,7 +262,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
|
|||||||
if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) ||
|
if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) ||
|
||||||
(!obj && repo_has_object_file(r, oid) &&
|
(!obj && repo_has_object_file(r, oid) &&
|
||||||
oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
|
oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
|
||||||
if (check_object_signature(repl, NULL, 0, NULL) < 0) {
|
if (check_object_signature(r, repl, NULL, 0, NULL) < 0) {
|
||||||
error(_("hash mismatch %s"), oid_to_hex(oid));
|
error(_("hash mismatch %s"), oid_to_hex(oid));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -272,7 +272,8 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
|
|||||||
|
|
||||||
buffer = repo_read_object_file(r, oid, &type, &size);
|
buffer = repo_read_object_file(r, oid, &type, &size);
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
|
if (check_object_signature(r, repl, buffer, size,
|
||||||
|
type_name(type)) < 0) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
error(_("hash mismatch %s"), oid_to_hex(repl));
|
error(_("hash mismatch %s"), oid_to_hex(repl));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -144,7 +144,7 @@ static int verify_packfile(struct repository *r,
|
|||||||
err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
|
err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
|
||||||
oid_to_hex(entries[i].oid.oid), p->pack_name,
|
oid_to_hex(entries[i].oid.oid), p->pack_name,
|
||||||
(uintmax_t)entries[i].offset);
|
(uintmax_t)entries[i].offset);
|
||||||
else if (check_object_signature(entries[i].oid.oid, data, size, type_name(type)))
|
else if (check_object_signature(r, entries[i].oid.oid, data, size, type_name(type)))
|
||||||
err = error("packed %s from %s is corrupt",
|
err = error("packed %s from %s is corrupt",
|
||||||
oid_to_hex(entries[i].oid.oid), p->pack_name);
|
oid_to_hex(entries[i].oid.oid), p->pack_name);
|
||||||
else if (fn) {
|
else if (fn) {
|
||||||
|
21
sha1-file.c
21
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
|
* With "map" == NULL, try reading the object named with "oid" using
|
||||||
* the streaming interface and rehash it to do the same.
|
* the streaming interface and rehash it to do the same.
|
||||||
*/
|
*/
|
||||||
int check_object_signature(const struct object_id *oid, void *map,
|
int check_object_signature(struct repository *r, const struct object_id *oid,
|
||||||
unsigned long size, const char *type)
|
void *map, unsigned long size, const char *type)
|
||||||
{
|
{
|
||||||
struct object_id real_oid;
|
struct object_id real_oid;
|
||||||
enum object_type obj_type;
|
enum object_type obj_type;
|
||||||
@ -982,11 +982,11 @@ int check_object_signature(const struct object_id *oid, void *map,
|
|||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
if (map) {
|
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;
|
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)
|
if (!st)
|
||||||
return -1;
|
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;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1;
|
||||||
|
|
||||||
/* Sha1.. */
|
/* Sha1.. */
|
||||||
the_hash_algo->init_fn(&c);
|
r->hash_algo->init_fn(&c);
|
||||||
the_hash_algo->update_fn(&c, hdr, hdrlen);
|
r->hash_algo->update_fn(&c, hdr, hdrlen);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[1024 * 16];
|
char buf[1024 * 16];
|
||||||
ssize_t readlen = read_istream(st, buf, sizeof(buf));
|
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)
|
if (!readlen)
|
||||||
break;
|
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);
|
close_istream(st);
|
||||||
return !oideq(oid, &real_oid) ? -1 : 0;
|
return !oideq(oid, &real_oid) ? -1 : 0;
|
||||||
}
|
}
|
||||||
@ -2456,8 +2456,9 @@ int read_loose_object(const char *path,
|
|||||||
git_inflate_end(&stream);
|
git_inflate_end(&stream);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (check_object_signature(expected_oid, *contents,
|
if (check_object_signature(the_repository, expected_oid,
|
||||||
*size, type_name(*type))) {
|
*contents, *size,
|
||||||
|
type_name(*type))) {
|
||||||
error(_("hash mismatch for %s (expected %s)"), path,
|
error(_("hash mismatch for %s (expected %s)"), path,
|
||||||
oid_to_hex(expected_oid));
|
oid_to_hex(expected_oid));
|
||||||
free(*contents);
|
free(*contents);
|
||||||
|
Loading…
Reference in New Issue
Block a user