commit c46b1605c71bd0ae9d2cfa477c55baa7b08a6a67c4009342fdca91a8ca606d44 from: Stefan Sperling date: Thu Aug 14 16:45:11 2025 UTC improve selection of pack files for pinning in the open pack file cache If two given pack files contain the same amount of requested commits, prefer the pack file which contains the larger amount of total objects to increase our chances of full history traversal. Also, require the first element of the list of requested commits to be present in the pack file since the caller will very likely try to process this commit immediately when we return. This fixes cases where offloading of commit coloring to got-read-pack was ineffective, causing us to take the slow path instead. ok op@ commit - 65f92520952841ce9afbb2068908932c5edaf906229375f74630ada4c758d88e commit + c46b1605c71bd0ae9d2cfa477c55baa7b08a6a67c4009342fdca91a8ca606d44 blob - 4131582a4a1521051e8a847bac311d68ac9aaace975b6fcba2a2e7ffef0ffab3 blob + b3782a72b716bd9b1ad93009e1293ea85370f35d97c65aca9b5b180c956a991a --- lib/pack_create.c +++ lib/pack_create.c @@ -1143,8 +1143,8 @@ got_pack_find_pack_for_commit_painting(struct got_pack *best_packidx = NULL; /* - * Find the largest pack which contains at least some of the - * commits we are interested in. + * Find the largest pack which contains the commit at the head + * of the queue and some other commits we are interested in. */ RB_FOREACH(pe, got_pathlist_head, &repo->packidx_paths) { const char *path_packidx = pe->path; @@ -1157,15 +1157,24 @@ got_pack_find_pack_for_commit_painting(struct got_pack break; nobj = be32toh(packidx->hdr.fanout_table[0xff]); - if (nobj <= nobj_max) + if (nobj < nobj_max) continue; - STAILQ_FOREACH(qid, ids, entry) { + qid = STAILQ_FIRST(ids); + idx = got_packidx_get_object_idx(packidx, &qid->id); + if (idx == -1) + continue; + ncommits++; + + qid = STAILQ_NEXT(qid, entry); + while (qid) { idx = got_packidx_get_object_idx(packidx, &qid->id); if (idx != -1) ncommits++; + qid = STAILQ_NEXT(qid, entry); } - if (ncommits > ncommits_max) { + + if (ncommits >= ncommits_max) { best_packidx_path = path_packidx; nobj_max = nobj; ncommits_max = ncommits; @@ -1280,9 +1289,12 @@ find_pack_for_enumeration(struct got_packidx **best_pa *best_packidx = NULL; + if (nids == 0) + return NULL; + /* - * Find the largest pack which contains at least some of the - * commits and tags we are interested in. + * Find the largest pack which contains the commit at the head + * of the queue and some other commits we are interested in. */ RB_FOREACH(pe, got_pathlist_head, &repo->packidx_paths) { const char *path_packidx = pe->path; @@ -1294,15 +1306,20 @@ find_pack_for_enumeration(struct got_packidx **best_pa break; nobj = be32toh(packidx->hdr.fanout_table[0xff]); - if (nobj <= nobj_max) + if (nobj < nobj_max) continue; - for (i = 0; i < nids; i++) { + idx = got_packidx_get_object_idx(packidx, ids[0]); + if (idx == -1) + continue; + ncommits++; + + for (i = 1; i < nids; i++) { idx = got_packidx_get_object_idx(packidx, ids[i]); if (idx != -1) ncommits++; } - if (ncommits > ncommits_max) { + if (ncommits >= ncommits_max) { best_packidx_path = path_packidx; nobj_max = nobj; ncommits_max = ncommits;