Skip to content

Commit 1a1e5d4

Browse files
jonathantanmygitster
authored andcommitted
pack: move find_pack_entry() and make it global
This function needs to be global as it is used by sha1_file.c and will be used by packfile.c. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6fe003 commit 1a1e5d4

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

packfile.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,3 +1787,56 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
17871787
return NULL;
17881788

17891789
}
1790+
1791+
static int fill_pack_entry(const unsigned char *sha1,
1792+
struct pack_entry *e,
1793+
struct packed_git *p)
1794+
{
1795+
off_t offset;
1796+
1797+
if (p->num_bad_objects) {
1798+
unsigned i;
1799+
for (i = 0; i < p->num_bad_objects; i++)
1800+
if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
1801+
return 0;
1802+
}
1803+
1804+
offset = find_pack_entry_one(sha1, p);
1805+
if (!offset)
1806+
return 0;
1807+
1808+
/*
1809+
* We are about to tell the caller where they can locate the
1810+
* requested object. We better make sure the packfile is
1811+
* still here and can be accessed before supplying that
1812+
* answer, as it may have been deleted since the index was
1813+
* loaded!
1814+
*/
1815+
if (!is_pack_valid(p))
1816+
return 0;
1817+
e->offset = offset;
1818+
e->p = p;
1819+
hashcpy(e->sha1, sha1);
1820+
return 1;
1821+
}
1822+
1823+
/*
1824+
* Iff a pack file contains the object named by sha1, return true and
1825+
* store its location to e.
1826+
*/
1827+
int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1828+
{
1829+
struct mru_entry *p;
1830+
1831+
prepare_packed_git();
1832+
if (!packed_git)
1833+
return 0;
1834+
1835+
for (p = packed_git_mru->head; p; p = p->next) {
1836+
if (fill_pack_entry(sha1, e, p->item)) {
1837+
mru_mark(packed_git_mru, p);
1838+
return 1;
1839+
}
1840+
}
1841+
return 0;
1842+
}

packfile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,6 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
118118
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
119119
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
120120

121+
extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);
122+
121123
#endif

sha1_file.c

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

1078-
static int fill_pack_entry(const unsigned char *sha1,
1079-
struct pack_entry *e,
1080-
struct packed_git *p)
1081-
{
1082-
off_t offset;
1083-
1084-
if (p->num_bad_objects) {
1085-
unsigned i;
1086-
for (i = 0; i < p->num_bad_objects; i++)
1087-
if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
1088-
return 0;
1089-
}
1090-
1091-
offset = find_pack_entry_one(sha1, p);
1092-
if (!offset)
1093-
return 0;
1094-
1095-
/*
1096-
* We are about to tell the caller where they can locate the
1097-
* requested object. We better make sure the packfile is
1098-
* still here and can be accessed before supplying that
1099-
* answer, as it may have been deleted since the index was
1100-
* loaded!
1101-
*/
1102-
if (!is_pack_valid(p))
1103-
return 0;
1104-
e->offset = offset;
1105-
e->p = p;
1106-
hashcpy(e->sha1, sha1);
1107-
return 1;
1108-
}
1109-
1110-
/*
1111-
* Iff a pack file contains the object named by sha1, return true and
1112-
* store its location to e.
1113-
*/
1114-
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1115-
{
1116-
struct mru_entry *p;
1117-
1118-
prepare_packed_git();
1119-
if (!packed_git)
1120-
return 0;
1121-
1122-
for (p = packed_git_mru->head; p; p = p->next) {
1123-
if (fill_pack_entry(sha1, e, p->item)) {
1124-
mru_mark(packed_git_mru, p);
1125-
return 1;
1126-
}
1127-
}
1128-
return 0;
1129-
}
1130-
11311078
static int sha1_loose_object_info(const unsigned char *sha1,
11321079
struct object_info *oi,
11331080
int flags)

0 commit comments

Comments
 (0)