1671
return type;
1672
}
1673
1674
-static void *read_object(struct repository *r,
1675
- const struct object_id *oid, enum object_type *type,
1676
- unsigned long *size,
1677
- int die_if_corrupt)
1678
-{
1679
- struct object_info oi = OBJECT_INFO_INIT;
1680
- void *content;
1681
- oi.typep = type;
1682
- oi.sizep = size;
1683
- oi.contentp = &content;
1684
-
1685
- if (oid_object_info_extended(r, oid, &oi, die_if_corrupt
1686
- ? OBJECT_INFO_DIE_IF_CORRUPT : 0) < 0)
1687
- return NULL;
1688
- return content;
1689
-}
1690
-
1674
int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1675
struct object_id *oid)
1676
{
1692
1693
/*
1694
* This function dies on corrupt objects; the callers who want to
1712
- * deal with them should arrange to call read_object() and give error
1713
- * messages themselves.
1695
+ * deal with them should arrange to call oid_object_info_extended() and give
1696
+ * error messages themselves.
1697
*/
1698
void *read_object_file_extended(struct repository *r,
1699
const struct object_id *oid,
1701
unsigned long *size,
1702
int lookup_replace)
1703
{
1704
+ struct object_info oi = OBJECT_INFO_INIT;
1705
+ unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT;
1706
void *data;
1722
- const struct object_id *repl = lookup_replace ?
1723
- lookup_replace_object(r, oid) : oid;
1707
1725
- errno = 0;
1726
- data = read_object(r, repl, type, size, 1);
1727
- if (data)
1728
- return data;
1708
+ oi.typep = type;
1709
+ oi.sizep = size;
1710
+ oi.contentp = &data;
1711
+ if (lookup_replace)
1712
+ flags |= OBJECT_INFO_LOOKUP_REPLACE;
1713
+ if (oid_object_info_extended(r, oid, &oi, flags))
1714
+ return NULL;
1715
1730
- return NULL;
1716
+ return data;
1717
}
1718
1719
void *read_object_with_reference(struct repository *r,
2241
{
2242
void *buf;
2243
unsigned long len;
2244
+ struct object_info oi = OBJECT_INFO_INIT;
2245
enum object_type type;
2246
char hdr[MAX_HEADER_LEN];
2247
int hdrlen;
2249
2250
if (has_loose_object(oid))
2251
return 0;
2265
- buf = read_object(the_repository, oid, &type, &len, 0);
2266
- if (!buf)
2252
+ oi.typep = &type;
2253
+ oi.sizep = &len;
2254
+ oi.contentp = &buf;
2255
+ if (oid_object_info_extended(the_repository, oid, &oi, 0))
2256
return error(_("cannot read object for %s"), oid_to_hex(oid));
2257
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
2258
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);