sha1_file: convert read_object_with_reference to object_id
Convert read_object_with_reference to take pointers to struct object_id. Update the internals of the function accordingly. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
916bc35b29
commit
02f0547eaa
20
sha1_file.c
20
sha1_file.c
@ -1399,29 +1399,29 @@ void *read_sha1_file_extended(const unsigned char *sha1,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *read_object_with_reference(const unsigned char *sha1,
|
||||
void *read_object_with_reference(const struct object_id *oid,
|
||||
const char *required_type_name,
|
||||
unsigned long *size,
|
||||
unsigned char *actual_sha1_return)
|
||||
struct object_id *actual_oid_return)
|
||||
{
|
||||
enum object_type type, required_type;
|
||||
void *buffer;
|
||||
unsigned long isize;
|
||||
unsigned char actual_sha1[20];
|
||||
struct object_id actual_oid;
|
||||
|
||||
required_type = type_from_string(required_type_name);
|
||||
hashcpy(actual_sha1, sha1);
|
||||
oidcpy(&actual_oid, oid);
|
||||
while (1) {
|
||||
int ref_length = -1;
|
||||
const char *ref_type = NULL;
|
||||
|
||||
buffer = read_sha1_file(actual_sha1, &type, &isize);
|
||||
buffer = read_sha1_file(actual_oid.hash, &type, &isize);
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
if (type == required_type) {
|
||||
*size = isize;
|
||||
if (actual_sha1_return)
|
||||
hashcpy(actual_sha1_return, actual_sha1);
|
||||
if (actual_oid_return)
|
||||
oidcpy(actual_oid_return, &actual_oid);
|
||||
return buffer;
|
||||
}
|
||||
/* Handle references */
|
||||
@ -1435,15 +1435,15 @@ void *read_object_with_reference(const unsigned char *sha1,
|
||||
}
|
||||
ref_length = strlen(ref_type);
|
||||
|
||||
if (ref_length + 40 > isize ||
|
||||
if (ref_length + GIT_SHA1_HEXSZ > isize ||
|
||||
memcmp(buffer, ref_type, ref_length) ||
|
||||
get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
|
||||
get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
free(buffer);
|
||||
/* Now we have the ID of the referred-to object in
|
||||
* actual_sha1. Check again. */
|
||||
* actual_oid. Check again. */
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user