]> git.ipfire.org Git - thirdparty/git.git/commitdiff
multi-pack-index: respect repack.packKeptObjects=false
authorDerrick Stolee <dstolee@microsoft.com>
Sun, 10 May 2020 16:07:34 +0000 (16:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 May 2020 16:50:55 +0000 (09:50 -0700)
When selecting a batch of pack-files to repack in the "git
multi-pack-index repack" command, Git should respect the
repack.packKeptObjects config option. When false, this option says that
the pack-files with an associated ".keep" file should not be repacked.
This config value is "false" by default.

There are two cases for selecting a batch of objects. The first is the
case where the input batch-size is zero, which specifies "repack
everything". The second is with a non-zero batch size, which selects
pack-files using a greedy selection criteria. Both of these cases are
updated and tested.

Reported-by: Son Luong Ngoc <sluongng@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-multi-pack-index.txt
midx.c
t/t5319-multi-pack-index.sh

index 642d9ac5b723652f339fa45b03ea67806d44f735..0c6619493c1eddd92323c620e4ae374a7c6a4b91 100644 (file)
@@ -56,6 +56,9 @@ repack::
        file is created, rewrite the multi-pack-index to reference the
        new pack-file. A later run of 'git multi-pack-index expire' will
        delete the pack-files that were part of this batch.
++
+If `repack.packKeptObjects` is `false`, then any pack-files with an
+associated `.keep` file will not be selected for the batch to repack.
 
 
 EXAMPLES
diff --git a/midx.c b/midx.c
index d2a43bd1a38d3e0a4da9db6ed69a8da45afc130a..6d1584ca51d313343bbb65f9baa7c794259c7bf0 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -1293,15 +1293,26 @@ static int compare_by_mtime(const void *a_, const void *b_)
        return 0;
 }
 
-static int fill_included_packs_all(struct multi_pack_index *m,
+static int fill_included_packs_all(struct repository *r,
+                                  struct multi_pack_index *m,
                                   unsigned char *include_pack)
 {
-       uint32_t i;
+       uint32_t i, count = 0;
+       int pack_kept_objects = 0;
+
+       repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
+
+       for (i = 0; i < m->num_packs; i++) {
+               if (prepare_midx_pack(r, m, i))
+                       continue;
+               if (!pack_kept_objects && m->packs[i]->pack_keep)
+                       continue;
 
-       for (i = 0; i < m->num_packs; i++)
                include_pack[i] = 1;
+               count++;
+       }
 
-       return m->num_packs < 2;
+       return count < 2;
 }
 
 static int fill_included_packs_batch(struct repository *r,
@@ -1312,6 +1323,9 @@ static int fill_included_packs_batch(struct repository *r,
        uint32_t i, packs_to_repack;
        size_t total_size;
        struct repack_info *pack_info = xcalloc(m->num_packs, sizeof(struct repack_info));
+       int pack_kept_objects = 0;
+
+       repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
 
        for (i = 0; i < m->num_packs; i++) {
                pack_info[i].pack_int_id = i;
@@ -1338,6 +1352,8 @@ static int fill_included_packs_batch(struct repository *r,
 
                if (!p)
                        continue;
+               if (!pack_kept_objects && p->pack_keep)
+                       continue;
                if (open_pack_index(p) || !p->num_objects)
                        continue;
 
@@ -1386,7 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
        if (batch_size) {
                if (fill_included_packs_batch(r, m, include_pack, batch_size))
                        goto cleanup;
-       } else if (fill_included_packs_all(m, include_pack))
+       } else if (fill_included_packs_all(r, m, include_pack))
                goto cleanup;
 
        repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);
index 030a7222b2aca5e97652194ea9a0d8cdf4ca9ab0..7214cab36c0f74ef4c731a189b2490c14a2fa6e4 100755 (executable)
@@ -538,6 +538,33 @@ test_expect_success 'repack with minimum size does not alter existing packs' '
        )
 '
 
+test_expect_success 'repack respects repack.packKeptObjects=false' '
+       test_when_finished rm -f dup/.git/objects/pack/*keep &&
+       (
+               cd dup &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 5 idx-list &&
+               ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
+               test_line_count = 5 keep-list &&
+               for keep in $(cat keep-list)
+               do
+                       touch $keep || return 1
+               done &&
+               git multi-pack-index repack --batch-size=0 &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 5 idx-list &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 5 midx-list &&
+               THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
+               BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
+               git multi-pack-index repack --batch-size=$BATCH_SIZE &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 5 idx-list &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 5 midx-list
+       )
+'
+
 test_expect_success 'repack creates a new pack' '
        (
                cd dup &&