summaryrefslogtreecommitdiff
path: root/builtin/repack.c
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2023-07-11 17:32:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-07-11 20:07:50 (GMT)
commit0af067276ee204147e6da933d19ec5ab791aa26d (patch)
treedab2e67b3a98af89dc4a27a0d714866f66f6d00b /builtin/repack.c
parentaa9166bcc0ba654fc21f198a30647ec087f733ed (diff)
downloadgit-0af067276ee204147e6da933d19ec5ab791aa26d.zip
git-0af067276ee204147e6da933d19ec5ab791aa26d.tar.gz
git-0af067276ee204147e6da933d19ec5ab791aa26d.tar.bz2
builtin/repack.c: only repack `.pack`s that exist
In 73320e49add (builtin/repack.c: only collect fully-formed packs, 2023-06-07), we switched the check for which packs to collect by starting at the .idx files and looking for matching .pack files. This avoids trying to repack pack-files that have not had their pack-indexes installed yet. However, it does cause maintenance to halt if we find the (problematic, but not insurmountable) case of a .idx file without a corresponding .pack file. In an environment where packfile maintenance is a critical function, such a hard stop is costly and requires human intervention to resolve (by deleting the .idx file). This was not the case before. We successfully repacked through this scenario until the recent change to scan for .idx files. Further, if we are actually in a case where objects are missing, we detect this at a different point during the reachability walk. In other cases, Git prepares its list of packfiles by scanning .idx files and then only adds it to the packfile list if the corresponding .pack file exists. It even does so without a warning! (See add_packed_git() in packfile.c for details.) This case is much less likely to occur than the failures seen before 73320e49add. Packfiles are "installed" by writing the .pack file before the .idx and that process can be interrupted. Packfiles _should_ be deleted by deleting the .idx first, followed by the .pack file, but unlink_pack_path() does not do this: it deletes the .pack _first_, allowing a window where this process could be interrupted. We leave the consideration of changing this order as a separate concern. Knowing that this condition is possible from interrupted Git processes and not other tools lends some weight that Git should be more flexible around this scenario. Add a check to see if the .pack file exists before adding it to the list for repacking. This will stop a number of maintenance failures seen in production but fixed by deleting the .idx files. This brings us closer to the case before 73320e49add in that 'git repack' will not fail when there is an orphaned .idx file, at least, not due to the way we scan for packfiles. In the case that the .pack file was erroneously deleted without copies of its objects in other installed packfiles, then 'git repack' will fail due to the reachable object walk. This does resolve the case where automated repacks will no longer be halted on this case. The tests in t7700 show both these successful scenarios and the case of failing if the .pack was truly required. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/repack.c')
-rw-r--r--builtin/repack.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/builtin/repack.c b/builtin/repack.c
index 51698e3..724e095 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -125,6 +125,9 @@ static void collect_pack_filenames(struct string_list *fname_nonkept_list,
strbuf_add(&buf, e->d_name, len);
strbuf_addstr(&buf, ".pack");
+ if (!file_exists(mkpath("%s/%s", packdir, buf.buf)))
+ continue;
+
for (i = 0; i < extra_keep->nr; i++)
if (!fspathcmp(buf.buf, extra_keep->items[i].string))
break;