pack-objects: create pack.useSparse setting
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 16 Jan 2019 18:26:00 +0000 (10:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Jan 2019 21:44:43 +0000 (13:44 -0800)
The '--sparse' flag in 'git pack-objects' changes the algorithm
used to enumerate objects to one that is faster for individual
users pushing new objects that change only a small cone of the
working directory. The sparse algorithm is not recommended for a
server, which likely sends new objects that appear across the
entire working directory.

Create a 'pack.useSparse' setting that enables this new algorithm.
This allows 'git push' to use this algorithm without passing a
'--sparse' flag all the way through four levels of run_command()
calls.

If the '--no-sparse' flag is set, then this config setting is
overridden.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/pack.txt
builtin/pack-objects.c
t/t5322-pack-objects-sparse.sh
index edac75c83f471bee7e9f560b1ec2defc13e0482e..425c73aa521a67f87941bd8fc11c69b52432cb00 100644 (file)
@@ -105,6 +105,15 @@ pack.useBitmaps::
        true. You should not generally need to turn this off unless
        you are debugging pack bitmaps.
 
        true. You should not generally need to turn this off unless
        you are debugging pack bitmaps.
 
+pack.useSparse::
+       When true, git will default to using the '--sparse' option in
+       'git pack-objects' when the '--revs' option is present. This
+       algorithm only walks trees that appear in paths that introduce new
+       objects. This can have significant performance benefits when
+       computing a pack to send a small change. However, it is possible
+       that extra objects are added to the pack-file if the included
+       commits contain certain types of direct renames.
+
 pack.writeBitmaps (deprecated)::
        This is a deprecated synonym for `repack.writeBitmaps`.
 
 pack.writeBitmaps (deprecated)::
        This is a deprecated synonym for `repack.writeBitmaps`.
 
index 7d5b0735e396985c82dfa64bdd5d43badb6eb1ce..124b1bafc4b892466d20ec38ac3a2f8a5b81eac0 100644 (file)
@@ -2711,6 +2711,10 @@ static int git_pack_config(const char *k, const char *v, void *cb)
                use_bitmap_index_default = git_config_bool(k, v);
                return 0;
        }
                use_bitmap_index_default = git_config_bool(k, v);
                return 0;
        }
+       if (!strcmp(k, "pack.usesparse")) {
+               sparse = git_config_bool(k, v);
+               return 0;
+       }
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
                if (delta_search_threads < 0)
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
                if (delta_search_threads < 0)
index 9f2a6e5d31e3a53877851e8893da3d1e3e1cf6d2..3233fafc90b02ee5c5578984e28d73ec70af7990 100755 (executable)
@@ -118,4 +118,19 @@ test_expect_success 'sparse pack-objects' '
        test_cmp expect_sparse_objects.txt sparse_objects.txt
 '
 
        test_cmp expect_sparse_objects.txt sparse_objects.txt
 '
 
+test_expect_success 'pack.useSparse enables algorithm' '
+       git config pack.useSparse true &&
+       git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp expect_sparse_objects.txt sparse_objects.txt
+'
+
+test_expect_success 'pack.useSparse overridden' '
+       git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
+       git index-pack -o sparse.idx sparse.pack &&
+       git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
+       test_cmp required_objects.txt sparse_objects.txt
+'
+
 test_done
 test_done