Skip to content

Commit 1eb3440

Browse files
committed
Merge branch 'ps/packed-git-in-object-store' into next
The list of packfiles used in a running Git process is moved from the packed_git structure into the packfile store. * ps/packed-git-in-object-store: packfile: track packs via the MRU list exclusively packfile: always add packfiles to MRU when adding a pack packfile: move list of packs into the packfile store builtin/pack-objects: simplify logic to find kept or nonlocal objects packfile: fix approximation of object counts http: refactor subsystem to use `packfile_list`s packfile: move the MRU list into the packfile store packfile: use a `strmap` to store packs by name
2 parents 41a35c3 + c31bad4 commit 1eb3440

File tree

9 files changed

+223
-172
lines changed

9 files changed

+223
-172
lines changed

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int store_object(
979979
if (e->idx.offset) {
980980
duplicate_count_by_type[type]++;
981981
return 1;
982-
} else if (find_oid_pack(&oid, packfile_store_get_packs(packs))) {
982+
} else if (packfile_list_find_oid(packfile_store_get_packs(packs), &oid)) {
983983
e->type = type;
984984
e->pack_id = MAX_PACK_ID;
985985
e->idx.offset = 1; /* just not zero! */
@@ -1180,7 +1180,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11801180
duplicate_count_by_type[OBJ_BLOB]++;
11811181
truncate_pack(&checkpoint);
11821182

1183-
} else if (find_oid_pack(&oid, packfile_store_get_packs(packs))) {
1183+
} else if (packfile_list_find_oid(packfile_store_get_packs(packs), &oid)) {
11841184
e->type = OBJ_BLOB;
11851185
e->pack_id = MAX_PACK_ID;
11861186
e->idx.offset = 1; /* just not zero! */

builtin/pack-objects.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,8 +1706,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17061706
uint32_t found_mtime)
17071707
{
17081708
int want;
1709+
struct packfile_list_entry *e;
17091710
struct odb_source *source;
1710-
struct list_head *pos;
17111711

17121712
if (!exclude && local) {
17131713
/*
@@ -1748,12 +1748,11 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17481748
}
17491749
}
17501750

1751-
list_for_each(pos, packfile_store_get_packs_mru(the_repository->objects->packfiles)) {
1752-
struct packed_git *p = list_entry(pos, struct packed_git, mru);
1751+
for (e = the_repository->objects->packfiles->packs.head; e; e = e->next) {
1752+
struct packed_git *p = e->pack;
17531753
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
17541754
if (!exclude && want > 0)
1755-
list_move(&p->mru,
1756-
packfile_store_get_packs_mru(the_repository->objects->packfiles));
1755+
packfile_list_prepend(&the_repository->objects->packfiles->packs, p);
17571756
if (want != -1)
17581757
return want;
17591758
}
@@ -4389,27 +4388,27 @@ static void add_unreachable_loose_objects(struct rev_info *revs)
43894388

43904389
static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
43914390
{
4392-
struct packfile_store *packs = the_repository->objects->packfiles;
4393-
static struct packed_git *last_found = (void *)1;
4391+
static struct packed_git *last_found = NULL;
43944392
struct packed_git *p;
43954393

4396-
p = (last_found != (void *)1) ? last_found :
4397-
packfile_store_get_packs(packs);
4394+
if (last_found && find_pack_entry_one(oid, last_found))
4395+
return 1;
43984396

4399-
while (p) {
4400-
if ((!p->pack_local || p->pack_keep ||
4401-
p->pack_keep_in_core) &&
4402-
find_pack_entry_one(oid, p)) {
4397+
repo_for_each_pack(the_repository, p) {
4398+
/*
4399+
* We have already checked `last_found`, so there is no need to
4400+
* re-check here.
4401+
*/
4402+
if (p == last_found)
4403+
continue;
4404+
4405+
if ((!p->pack_local || p->pack_keep || p->pack_keep_in_core) &&
4406+
find_pack_entry_one(oid, p)) {
44034407
last_found = p;
44044408
return 1;
44054409
}
4406-
if (p == last_found)
4407-
p = packfile_store_get_packs(packs);
4408-
else
4409-
p = p->next;
4410-
if (p == last_found)
4411-
p = p->next;
44124410
}
4411+
44134412
return 0;
44144413
}
44154414

http-push.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct repo {
104104
int has_info_refs;
105105
int can_update_info_refs;
106106
int has_info_packs;
107-
struct packed_git *packs;
107+
struct packfile_list packs;
108108
struct remote_lock *locks;
109109
};
110110

@@ -311,7 +311,7 @@ static void start_fetch_packed(struct transfer_request *request)
311311
struct transfer_request *check_request = request_queue_head;
312312
struct http_pack_request *preq;
313313

314-
target = find_oid_pack(&request->obj->oid, repo->packs);
314+
target = packfile_list_find_oid(repo->packs.head, &request->obj->oid);
315315
if (!target) {
316316
fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid));
317317
repo->can_update_info_refs = 0;
@@ -683,7 +683,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
683683
get_remote_object_list(obj->oid.hash[0]);
684684
if (obj->flags & (REMOTE | PUSHING))
685685
return 0;
686-
target = find_oid_pack(&obj->oid, repo->packs);
686+
target = packfile_list_find_oid(repo->packs.head, &obj->oid);
687687
if (target) {
688688
obj->flags |= REMOTE;
689689
return 0;

http-walker.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
struct alt_base {
1616
char *base;
1717
int got_indices;
18-
struct packed_git *packs;
18+
struct packfile_list packs;
1919
struct alt_base *next;
2020
};
2121

@@ -324,11 +324,8 @@ static void process_alternates_response(void *callback_data)
324324
} else if (is_alternate_allowed(target.buf)) {
325325
warning("adding alternate object store: %s",
326326
target.buf);
327-
newalt = xmalloc(sizeof(*newalt));
328-
newalt->next = NULL;
327+
CALLOC_ARRAY(newalt, 1);
329328
newalt->base = strbuf_detach(&target, NULL);
330-
newalt->got_indices = 0;
331-
newalt->packs = NULL;
332329

333330
while (tail->next != NULL)
334331
tail = tail->next;
@@ -435,7 +432,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo,
435432

436433
if (fetch_indices(walker, repo))
437434
return -1;
438-
target = find_oid_pack(oid, repo->packs);
435+
target = packfile_list_find_oid(repo->packs.head, oid);
439436
if (!target)
440437
return -1;
441438
close_pack_index(target);
@@ -584,17 +581,15 @@ static void cleanup(struct walker *walker)
584581
if (data) {
585582
alt = data->alt;
586583
while (alt) {
587-
struct packed_git *pack;
584+
struct packfile_list_entry *e;
588585

589586
alt_next = alt->next;
590587

591-
pack = alt->packs;
592-
while (pack) {
593-
struct packed_git *pack_next = pack->next;
594-
close_pack(pack);
595-
free(pack);
596-
pack = pack_next;
588+
for (e = alt->packs.head; e; e = e->next) {
589+
close_pack(e->pack);
590+
free(e->pack);
597591
}
592+
packfile_list_clear(&alt->packs);
598593

599594
free(alt->base);
600595
free(alt);
@@ -612,14 +607,11 @@ struct walker *get_http_walker(const char *url)
612607
struct walker_data *data = xmalloc(sizeof(struct walker_data));
613608
struct walker *walker = xmalloc(sizeof(struct walker));
614609

615-
data->alt = xmalloc(sizeof(*data->alt));
610+
CALLOC_ARRAY(data->alt, 1);
616611
data->alt->base = xstrdup(url);
617612
for (s = data->alt->base + strlen(data->alt->base) - 1; *s == '/'; --s)
618613
*s = 0;
619614

620-
data->alt->got_indices = 0;
621-
data->alt->packs = NULL;
622-
data->alt->next = NULL;
623615
data->got_alternates = -1;
624616

625617
walker->corrupt_object_found = 0;

http.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,8 +2413,9 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
24132413
return tmp;
24142414
}
24152415

2416-
static int fetch_and_setup_pack_index(struct packed_git **packs_head,
2417-
unsigned char *sha1, const char *base_url)
2416+
static int fetch_and_setup_pack_index(struct packfile_list *packs,
2417+
unsigned char *sha1,
2418+
const char *base_url)
24182419
{
24192420
struct packed_git *new_pack, *p;
24202421
char *tmp_idx = NULL;
@@ -2448,12 +2449,11 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
24482449
if (ret)
24492450
return -1;
24502451

2451-
new_pack->next = *packs_head;
2452-
*packs_head = new_pack;
2452+
packfile_list_prepend(packs, new_pack);
24532453
return 0;
24542454
}
24552455

2456-
int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
2456+
int http_get_info_packs(const char *base_url, struct packfile_list *packs)
24572457
{
24582458
struct http_get_options options = {0};
24592459
int ret = 0;
@@ -2477,7 +2477,7 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
24772477
!parse_oid_hex(data, &oid, &data) &&
24782478
skip_prefix(data, ".pack", &data) &&
24792479
(*data == '\n' || *data == '\0')) {
2480-
fetch_and_setup_pack_index(packs_head, oid.hash, base_url);
2480+
fetch_and_setup_pack_index(packs, oid.hash, base_url);
24812481
} else {
24822482
data = strchrnul(data, '\n');
24832483
}
@@ -2541,14 +2541,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
25412541
}
25422542

25432543
void http_install_packfile(struct packed_git *p,
2544-
struct packed_git **list_to_remove_from)
2544+
struct packfile_list *list_to_remove_from)
25452545
{
2546-
struct packed_git **lst = list_to_remove_from;
2547-
2548-
while (*lst != p)
2549-
lst = &((*lst)->next);
2550-
*lst = (*lst)->next;
2551-
2546+
packfile_list_remove(list_to_remove_from, p);
25522547
packfile_store_add_pack(the_repository->objects->packfiles, p);
25532548
}
25542549

http.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define HTTP_H
33

44
struct packed_git;
5+
struct packfile_list;
56

67
#include "git-zlib.h"
78

@@ -190,7 +191,7 @@ struct curl_slist *http_append_auth_header(const struct credential *c,
190191

191192
/* Helpers for fetching packs */
192193
int http_get_info_packs(const char *base_url,
193-
struct packed_git **packs_head);
194+
struct packfile_list *packs);
194195

195196
/* Helper for getting Accept-Language header */
196197
const char *http_get_accept_language_header(void);
@@ -226,7 +227,7 @@ void release_http_pack_request(struct http_pack_request *preq);
226227
* from http_get_info_packs() and have chosen a specific pack to fetch.
227228
*/
228229
void http_install_packfile(struct packed_git *p,
229-
struct packed_git **list_to_remove_from);
230+
struct packfile_list *list_to_remove_from);
230231

231232
/* Helpers for fetching object */
232233
struct http_object_request {

midx.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ int prepare_midx_pack(struct multi_pack_index *m,
462462
m->pack_names[pack_int_id]);
463463
p = packfile_store_load_pack(r->objects->packfiles,
464464
pack_name.buf, m->source->local);
465-
if (p)
466-
list_add_tail(&p->mru, &r->objects->packfiles->mru);
467465
strbuf_release(&pack_name);
468466

469467
if (!p) {

0 commit comments

Comments
 (0)