packfile: drop has_pack_index()
The has_pack_index() function has several oddities that may make it surprising if you are trying to find out if we have a pack with some $hash: - it is not looking for a valid pack that we found while searching object directories. It just looks for any pack-$hash.idx file in the pack directory. - it only looks in the local directory, not any alternates - it takes a bare "unsigned char" hash, which we try to avoid these days The only caller it has is in the dumb http code; it wants to know if we already have the pack idx in question. This can happen if we downloaded the pack (and generated its index) during a previous fetch. Before the previous patch ("dumb-http: store downloaded pack idx as tempfile"), it could also happen if we downloaded the .idx from the remote but didn't get the matching .pack. But since that patch, we don't hold on to those .idx files. So there's no need to look for the .idx file in the filesystem; we can just scan through the packed_git list to see if we have it. That lets us simplify the dumb http code a bit, as we know that if we have the .idx we have the matching .pack already. And it lets us get rid of this odd function that is unlikely to be needed again. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
15
http.c
15
http.c
@ -2420,15 +2420,17 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
|
||||
static int fetch_and_setup_pack_index(struct packed_git **packs_head,
|
||||
unsigned char *sha1, const char *base_url)
|
||||
{
|
||||
struct packed_git *new_pack;
|
||||
struct packed_git *new_pack, *p;
|
||||
char *tmp_idx = NULL;
|
||||
int ret;
|
||||
|
||||
if (has_pack_index(sha1)) {
|
||||
new_pack = parse_pack_index(sha1, sha1_pack_index_name(sha1));
|
||||
if (!new_pack)
|
||||
return -1; /* parse_pack_index() already issued error message */
|
||||
goto add_pack;
|
||||
/*
|
||||
* If we already have the pack locally, no need to fetch its index or
|
||||
* even add it to list; we already have all of its objects.
|
||||
*/
|
||||
for (p = get_all_packs(the_repository); p; p = p->next) {
|
||||
if (hasheq(p->hash, sha1, the_repository->hash_algo))
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmp_idx = fetch_pack_index(sha1, base_url);
|
||||
@ -2450,7 +2452,6 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
add_pack:
|
||||
new_pack->next = *packs_head;
|
||||
*packs_head = new_pack;
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user