diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-07-18 14:28:53 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-07-18 14:28:53 (GMT) |
commit | c6a5e1a22e0fcafbcc67a2b098cc13150f8aaf4a (patch) | |
tree | bc61eabe60b46679c47ad57253ae9fd4ca02ff36 /builtin/repack.c | |
parent | 6016ee0a7130d3ad656def12d724d1525d39af9b (diff) | |
parent | def390d5939d97f4bd642684e0554885e716370e (diff) | |
download | git-c6a5e1a22e0fcafbcc67a2b098cc13150f8aaf4a.zip git-c6a5e1a22e0fcafbcc67a2b098cc13150f8aaf4a.tar.gz git-c6a5e1a22e0fcafbcc67a2b098cc13150f8aaf4a.tar.bz2 |
Merge branch 'tb/repack-cleanup'
The recent change to "git repack" made it react less nicely when a
leftover .idx file that no longer has the corresponding .pack file
in the repository, which has been corrected.
* tb/repack-cleanup:
builtin/repack.c: avoid dir traversal in `collect_pack_filenames()`
builtin/repack.c: only repack `.pack`s that exist
Diffstat (limited to 'builtin/repack.c')
-rw-r--r-- | builtin/repack.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/builtin/repack.c b/builtin/repack.c index f913e9a..aea5ca9 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -105,46 +105,38 @@ static void collect_pack_filenames(struct string_list *fname_nonkept_list, struct string_list *fname_kept_list, const struct string_list *extra_keep) { - DIR *dir; - struct dirent *e; - char *fname; + struct packed_git *p; struct strbuf buf = STRBUF_INIT; - if (!(dir = opendir(packdir))) - return; - - while ((e = readdir(dir)) != NULL) { - size_t len; + for (p = get_all_packs(the_repository); p; p = p->next) { int i; + const char *base; - if (!strip_suffix(e->d_name, ".idx", &len)) + if (!p->pack_local) continue; - strbuf_reset(&buf); - strbuf_add(&buf, e->d_name, len); - strbuf_addstr(&buf, ".pack"); + base = pack_basename(p); for (i = 0; i < extra_keep->nr; i++) - if (!fspathcmp(buf.buf, extra_keep->items[i].string)) + if (!fspathcmp(base, extra_keep->items[i].string)) break; - fname = xmemdupz(e->d_name, len); + strbuf_reset(&buf); + strbuf_addstr(&buf, base); + strbuf_strip_suffix(&buf, ".pack"); - if ((extra_keep->nr > 0 && i < extra_keep->nr) || - (file_exists(mkpath("%s/%s.keep", packdir, fname)))) { - string_list_append_nodup(fname_kept_list, fname); - } else { + if ((extra_keep->nr > 0 && i < extra_keep->nr) || p->pack_keep) + string_list_append(fname_kept_list, buf.buf); + else { struct string_list_item *item; - item = string_list_append_nodup(fname_nonkept_list, - fname); - if (file_exists(mkpath("%s/%s.mtimes", packdir, fname))) + item = string_list_append(fname_nonkept_list, buf.buf); + if (p->is_cruft) item->util = (void*)(uintptr_t)CRUFT_PACK; } } - closedir(dir); - strbuf_release(&buf); string_list_sort(fname_kept_list); + strbuf_release(&buf); } static void remove_redundant_pack(const char *dir_name, const char *base_name) |