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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
d6fe0036fd
commit
1a1e5d4f47
53
packfile.c
53
packfile.c
@ -1787,3 +1787,56 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fill_pack_entry(const unsigned char *sha1,
|
||||||
|
struct pack_entry *e,
|
||||||
|
struct packed_git *p)
|
||||||
|
{
|
||||||
|
off_t offset;
|
||||||
|
|
||||||
|
if (p->num_bad_objects) {
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i < p->num_bad_objects; i++)
|
||||||
|
if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = find_pack_entry_one(sha1, p);
|
||||||
|
if (!offset)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We are about to tell the caller where they can locate the
|
||||||
|
* requested object. We better make sure the packfile is
|
||||||
|
* still here and can be accessed before supplying that
|
||||||
|
* answer, as it may have been deleted since the index was
|
||||||
|
* loaded!
|
||||||
|
*/
|
||||||
|
if (!is_pack_valid(p))
|
||||||
|
return 0;
|
||||||
|
e->offset = offset;
|
||||||
|
e->p = p;
|
||||||
|
hashcpy(e->sha1, sha1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Iff a pack file contains the object named by sha1, return true and
|
||||||
|
* store its location to e.
|
||||||
|
*/
|
||||||
|
int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
|
||||||
|
{
|
||||||
|
struct mru_entry *p;
|
||||||
|
|
||||||
|
prepare_packed_git();
|
||||||
|
if (!packed_git)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (p = packed_git_mru->head; p; p = p->next) {
|
||||||
|
if (fill_pack_entry(sha1, e, p->item)) {
|
||||||
|
mru_mark(packed_git_mru, p);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -118,4 +118,6 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
|
|||||||
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
|
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
|
||||||
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
|
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
|
||||||
|
|
||||||
|
extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
53
sha1_file.c
53
sha1_file.c
@ -1075,59 +1075,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
|
|||||||
return parse_sha1_header_extended(hdr, &oi, 0);
|
return parse_sha1_header_extended(hdr, &oi, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fill_pack_entry(const unsigned char *sha1,
|
|
||||||
struct pack_entry *e,
|
|
||||||
struct packed_git *p)
|
|
||||||
{
|
|
||||||
off_t offset;
|
|
||||||
|
|
||||||
if (p->num_bad_objects) {
|
|
||||||
unsigned i;
|
|
||||||
for (i = 0; i < p->num_bad_objects; i++)
|
|
||||||
if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = find_pack_entry_one(sha1, p);
|
|
||||||
if (!offset)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We are about to tell the caller where they can locate the
|
|
||||||
* requested object. We better make sure the packfile is
|
|
||||||
* still here and can be accessed before supplying that
|
|
||||||
* answer, as it may have been deleted since the index was
|
|
||||||
* loaded!
|
|
||||||
*/
|
|
||||||
if (!is_pack_valid(p))
|
|
||||||
return 0;
|
|
||||||
e->offset = offset;
|
|
||||||
e->p = p;
|
|
||||||
hashcpy(e->sha1, sha1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Iff a pack file contains the object named by sha1, return true and
|
|
||||||
* store its location to e.
|
|
||||||
*/
|
|
||||||
static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
|
|
||||||
{
|
|
||||||
struct mru_entry *p;
|
|
||||||
|
|
||||||
prepare_packed_git();
|
|
||||||
if (!packed_git)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (p = packed_git_mru->head; p; p = p->next) {
|
|
||||||
if (fill_pack_entry(sha1, e, p->item)) {
|
|
||||||
mru_mark(packed_git_mru, p);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sha1_loose_object_info(const unsigned char *sha1,
|
static int sha1_loose_object_info(const unsigned char *sha1,
|
||||||
struct object_info *oi,
|
struct object_info *oi,
|
||||||
int flags)
|
int flags)
|
||||||
|
Reference in New Issue
Block a user