sha1_file: allow read_object to read objects in arbitrary repositories
Allow read_object (a file local functon in sha1_file) to handle arbitrary repositories by passing the repository down to oid_object_info_extended. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c4df23f792
commit
1b9b5c695e
10
sha1-file.c
10
sha1-file.c
@ -1361,7 +1361,9 @@ int oid_object_info(struct repository *r,
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *read_object(const unsigned char *sha1, enum object_type *type,
|
static void *read_object(struct repository *r,
|
||||||
|
const unsigned char *sha1,
|
||||||
|
enum object_type *type,
|
||||||
unsigned long *size)
|
unsigned long *size)
|
||||||
{
|
{
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
@ -1373,7 +1375,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
|
|||||||
|
|
||||||
hashcpy(oid.hash, sha1);
|
hashcpy(oid.hash, sha1);
|
||||||
|
|
||||||
if (oid_object_info_extended(the_repository, &oid, &oi, 0) < 0)
|
if (oid_object_info_extended(r, &oid, &oi, 0) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@ -1414,7 +1416,7 @@ void *read_object_file_extended(const struct object_id *oid,
|
|||||||
lookup_replace_object(the_repository, oid) : oid;
|
lookup_replace_object(the_repository, oid) : oid;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
data = read_object(repl->hash, type, size);
|
data = read_object(the_repository, repl->hash, type, size);
|
||||||
if (data)
|
if (data)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
@ -1755,7 +1757,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
|
|||||||
|
|
||||||
if (has_loose_object(oid))
|
if (has_loose_object(oid))
|
||||||
return 0;
|
return 0;
|
||||||
buf = read_object(oid->hash, &type, &len);
|
buf = read_object(the_repository, oid->hash, &type, &len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
|
return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
|
||||||
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user