Skip to content

Commit 03b8eed

Browse files
peffttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 63aca3f commit 03b8eed

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

http.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,15 +2420,17 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
24202420
static int fetch_and_setup_pack_index(struct packed_git **packs_head,
24212421
unsigned char *sha1, const char *base_url)
24222422
{
2423-
struct packed_git *new_pack;
2423+
struct packed_git *new_pack, *p;
24242424
char *tmp_idx = NULL;
24252425
int ret;
24262426

2427-
if (has_pack_index(sha1)) {
2428-
new_pack = parse_pack_index(sha1, sha1_pack_index_name(sha1));
2429-
if (!new_pack)
2430-
return -1; /* parse_pack_index() already issued error message */
2431-
goto add_pack;
2427+
/*
2428+
* If we already have the pack locally, no need to fetch its index or
2429+
* even add it to list; we already have all of its objects.
2430+
*/
2431+
for (p = get_all_packs(the_repository); p; p = p->next) {
2432+
if (hasheq(p->hash, sha1, the_repository->hash_algo))
2433+
return 0;
24322434
}
24332435

24342436
tmp_idx = fetch_pack_index(sha1, base_url);
@@ -2450,7 +2452,6 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
24502452
if (ret)
24512453
return -1;
24522454

2453-
add_pack:
24542455
new_pack->next = *packs_head;
24552456
*packs_head = new_pack;
24562457
return 0;

packfile.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,6 @@ int has_object_kept_pack(const struct object_id *oid, unsigned flags)
21602160
return find_kept_pack_entry(the_repository, oid, flags, &e);
21612161
}
21622162

2163-
int has_pack_index(const unsigned char *sha1)
2164-
{
2165-
struct stat st;
2166-
if (stat(sha1_pack_index_name(sha1), &st))
2167-
return 0;
2168-
return 1;
2169-
}
2170-
21712163
int for_each_object_in_pack(struct packed_git *p,
21722164
each_packed_object_fn cb, void *data,
21732165
enum for_each_object_flags flags)

packfile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsi
193193
int has_object_pack(const struct object_id *oid);
194194
int has_object_kept_pack(const struct object_id *oid, unsigned flags);
195195

196-
int has_pack_index(const unsigned char *sha1);
197-
198196
/*
199197
* Return 1 if an object in a promisor packfile is or refers to the given
200198
* object, 0 otherwise.

0 commit comments

Comments
 (0)