Skip to content

Commit d5a1676

Browse files
jonathantanmygitster
authored andcommitted
pack: move nth_packed_object_{sha1,oid}
Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1d8130 commit d5a1676

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

cache.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,20 +1630,6 @@ extern int odb_pack_keep(const char *name);
16301630
*/
16311631
extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
16321632

1633-
/*
1634-
* Return the SHA-1 of the nth object within the specified packfile.
1635-
* Open the index if it is not already open. The return value points
1636-
* at the SHA-1 within the mmapped index. Return NULL if there is an
1637-
* error.
1638-
*/
1639-
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
1640-
/*
1641-
* Like nth_packed_object_sha1, but write the data into the object specified by
1642-
* the the first argument. Returns the first argument on success, and NULL on
1643-
* error.
1644-
*/
1645-
extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
1646-
16471633
/*
16481634
* Return the offset of the nth object within the specified packfile.
16491635
* The index must already be opened.

packfile.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,3 +1636,34 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
16361636

16371637
return data;
16381638
}
1639+
1640+
const unsigned char *nth_packed_object_sha1(struct packed_git *p,
1641+
uint32_t n)
1642+
{
1643+
const unsigned char *index = p->index_data;
1644+
if (!index) {
1645+
if (open_pack_index(p))
1646+
return NULL;
1647+
index = p->index_data;
1648+
}
1649+
if (n >= p->num_objects)
1650+
return NULL;
1651+
index += 4 * 256;
1652+
if (p->index_version == 1) {
1653+
return index + 24 * n + 4;
1654+
} else {
1655+
index += 8;
1656+
return index + 20 * n;
1657+
}
1658+
}
1659+
1660+
const struct object_id *nth_packed_object_oid(struct object_id *oid,
1661+
struct packed_git *p,
1662+
uint32_t n)
1663+
{
1664+
const unsigned char *hash = nth_packed_object_sha1(p, n);
1665+
if (!hash)
1666+
return NULL;
1667+
hashcpy(oid->hash, hash);
1668+
return oid;
1669+
}

packfile.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ extern void unuse_pack(struct pack_window **);
6363
extern void clear_delta_base_cache(void);
6464
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
6565

66+
/*
67+
* Return the SHA-1 of the nth object within the specified packfile.
68+
* Open the index if it is not already open. The return value points
69+
* at the SHA-1 within the mmapped index. Return NULL if there is an
70+
* error.
71+
*/
72+
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
73+
/*
74+
* Like nth_packed_object_sha1, but write the data into the object specified by
75+
* the the first argument. Returns the first argument on success, and NULL on
76+
* error.
77+
*/
78+
extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
79+
80+
6681
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
6782
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
6883
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
@@ -79,5 +94,4 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
7994

8095
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
8196
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
82-
8397
#endif

sha1_file.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,37 +1075,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
10751075
return parse_sha1_header_extended(hdr, &oi, 0);
10761076
}
10771077

1078-
const unsigned char *nth_packed_object_sha1(struct packed_git *p,
1079-
uint32_t n)
1080-
{
1081-
const unsigned char *index = p->index_data;
1082-
if (!index) {
1083-
if (open_pack_index(p))
1084-
return NULL;
1085-
index = p->index_data;
1086-
}
1087-
if (n >= p->num_objects)
1088-
return NULL;
1089-
index += 4 * 256;
1090-
if (p->index_version == 1) {
1091-
return index + 24 * n + 4;
1092-
} else {
1093-
index += 8;
1094-
return index + 20 * n;
1095-
}
1096-
}
1097-
1098-
const struct object_id *nth_packed_object_oid(struct object_id *oid,
1099-
struct packed_git *p,
1100-
uint32_t n)
1101-
{
1102-
const unsigned char *hash = nth_packed_object_sha1(p, n);
1103-
if (!hash)
1104-
return NULL;
1105-
hashcpy(oid->hash, hash);
1106-
return oid;
1107-
}
1108-
11091078
void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
11101079
{
11111080
const unsigned char *ptr = vptr;

0 commit comments

Comments
 (0)