summaryrefslogtreecommitdiff
path: root/builtin/repack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2023-04-14 06:02:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-04-14 17:27:52 (GMT)
commit932c16c04b5e41ee1c76d5640ec3ae67e1900c07 (patch)
treed56c922bdd27dd752066292b505d8b6087eecba2 /builtin/repack.c
parent19a3a7bde9164c86353c944e939a1dcb537993f9 (diff)
downloadgit-932c16c04b5e41ee1c76d5640ec3ae67e1900c07.zip
git-932c16c04b5e41ee1c76d5640ec3ae67e1900c07.tar.gz
git-932c16c04b5e41ee1c76d5640ec3ae67e1900c07.tar.bz2
repack: honor `-l` when calculating pack geometry
When the user passes `-l` to git-repack(1), then they essentially ask us to only repack objects part of the local object database while ignoring any packfiles part of an alternate object database. And we in fact honor this bit when doing a geometric repack as the resulting packfile will only ever contain local objects. What we're missing though is that we don't take locality of packfiles into account when computing whether the geometric sequence is intact or not. So even though we would only ever roll up local packfiles anyway, we could end up trying to repack because of non-local packfiles. This does not make much sense, and in the worst case it can cause us to try and do the geometric repack over and over again because we're never able to restore the geometric sequence. Fix this bug by honoring whether the user has passed `-l`. If so, we skip adding any non-local packfiles to the pack geometry. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/repack.c')
-rw-r--r--builtin/repack.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/builtin/repack.c b/builtin/repack.c
index a591a4d..165fe1b 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -321,7 +321,8 @@ static int geometry_cmp(const void *va, const void *vb)
}
static void init_pack_geometry(struct pack_geometry **geometry_p,
- struct string_list *existing_kept_packs)
+ struct string_list *existing_kept_packs,
+ const struct pack_objects_args *args)
{
struct packed_git *p;
struct pack_geometry *geometry;
@@ -331,6 +332,14 @@ static void init_pack_geometry(struct pack_geometry **geometry_p,
geometry = *geometry_p;
for (p = get_all_packs(the_repository); p; p = p->next) {
+ if (args->local && !p->pack_local)
+ /*
+ * When asked to only repack local packfiles we skip
+ * over any packfiles that are borrowed from alternate
+ * object directories.
+ */
+ continue;
+
if (!pack_kept_objects) {
/*
* Any pack that has its pack_keep bit set will appear
@@ -898,7 +907,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
if (geometric_factor) {
if (pack_everything)
die(_("options '%s' and '%s' cannot be used together"), "--geometric", "-A/-a");
- init_pack_geometry(&geometry, &existing_kept_packs);
+ init_pack_geometry(&geometry, &existing_kept_packs, &po_args);
split_pack_geometry(geometry, geometric_factor);
}