sha1_file: convert read_loose_object to use struct object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
af8caf33d5
commit
d61d87bd15
@ -513,7 +513,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
|
|||||||
unsigned long size;
|
unsigned long size;
|
||||||
int eaten;
|
int eaten;
|
||||||
|
|
||||||
if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
|
if (read_loose_object(path, oid, &type, &size, &contents) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!contents && type != OBJ_BLOB)
|
if (!contents && type != OBJ_BLOB)
|
||||||
|
4
cache.h
4
cache.h
@ -1241,14 +1241,14 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
|
|||||||
extern int finalize_object_file(const char *tmpfile, const char *filename);
|
extern int finalize_object_file(const char *tmpfile, const char *filename);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the loose object at path, check its sha1, and return the contents,
|
* Open the loose object at path, check its hash, and return the contents,
|
||||||
* type, and size. If the object is a blob, then "contents" may return NULL,
|
* type, and size. If the object is a blob, then "contents" may return NULL,
|
||||||
* to allow streaming of large blobs.
|
* to allow streaming of large blobs.
|
||||||
*
|
*
|
||||||
* Returns 0 on success, negative on error (details may be written to stderr).
|
* Returns 0 on success, negative on error (details may be written to stderr).
|
||||||
*/
|
*/
|
||||||
int read_loose_object(const char *path,
|
int read_loose_object(const char *path,
|
||||||
const unsigned char *expected_sha1,
|
const struct object_id *expected_oid,
|
||||||
enum object_type *type,
|
enum object_type *type,
|
||||||
unsigned long *size,
|
unsigned long *size,
|
||||||
void **contents);
|
void **contents);
|
||||||
|
10
sha1_file.c
10
sha1_file.c
@ -2176,7 +2176,7 @@ static int check_stream_sha1(git_zstream *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int read_loose_object(const char *path,
|
int read_loose_object(const char *path,
|
||||||
const unsigned char *expected_sha1,
|
const struct object_id *expected_oid,
|
||||||
enum object_type *type,
|
enum object_type *type,
|
||||||
unsigned long *size,
|
unsigned long *size,
|
||||||
void **contents)
|
void **contents)
|
||||||
@ -2208,19 +2208,19 @@ int read_loose_object(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*type == OBJ_BLOB) {
|
if (*type == OBJ_BLOB) {
|
||||||
if (check_stream_sha1(&stream, hdr, *size, path, expected_sha1) < 0)
|
if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
*contents = unpack_sha1_rest(&stream, hdr, *size, expected_sha1);
|
*contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
|
||||||
if (!*contents) {
|
if (!*contents) {
|
||||||
error("unable to unpack contents of %s", path);
|
error("unable to unpack contents of %s", path);
|
||||||
git_inflate_end(&stream);
|
git_inflate_end(&stream);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (check_sha1_signature(expected_sha1, *contents,
|
if (check_sha1_signature(expected_oid->hash, *contents,
|
||||||
*size, type_name(*type))) {
|
*size, type_name(*type))) {
|
||||||
error("sha1 mismatch for %s (expected %s)", path,
|
error("sha1 mismatch for %s (expected %s)", path,
|
||||||
sha1_to_hex(expected_sha1));
|
oid_to_hex(expected_oid));
|
||||||
free(*contents);
|
free(*contents);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user