packfile: allow find_pack_entry to handle arbitrary repositories

Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 23, 2018 at 18:45 UTC 0a0dd632aa9c9bcdb1b79a7fc4cf6dc161760020
2 files changed +6 -8
packfile.c
+5 -6
@@ -1845,19 +1845,18 @@ static int fill_pack_entry(const unsigned char *sha1,
1845 return 1;
1846 }
1847
1848 -int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e)
1848 +int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e)
1849 {
1850 struct list_head *pos;
1851
1852 - prepare_packed_git(the_repository);
1853 - if (!the_repository->objects->packed_git)
1852 + prepare_packed_git(r);
1853 + if (!r->objects->packed_git)
1854 return 0;
1855
1856 - list_for_each(pos, &the_repository->objects->packed_git_mru) {
1856 + list_for_each(pos, &r->objects->packed_git_mru) {
1857 struct packed_git *p = list_entry(pos, struct packed_git, mru);
1858 if (fill_pack_entry(sha1, e, p)) {
1859 - list_move(&p->mru,
1860 - &the_repository->objects->packed_git_mru);
1859 + list_move(&p->mru, &r->objects->packed_git_mru);
1860 return 1;
1861 }
1862 }
packfile.h
+1 -2
@@ -127,8 +127,7 @@ extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
127 * Iff a pack file in the given repository contains the object named by sha1,
128 * return true and store its location to e.
129 */
130 -#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e)
131 -extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e);
130 +extern int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e);
131
132 extern int has_sha1_pack(const unsigned char *sha1);
133