Skip to content

Commit f386f6c

Browse files
committed
pack-objects: create pack.useSparse setting
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 <[email protected]>
1 parent c44172c commit f386f6c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Documentation/config/pack.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ pack.useBitmaps::
105105
true. You should not generally need to turn this off unless
106106
you are debugging pack bitmaps.
107107

108+
pack.useSparse::
109+
When true, git will default to using the '--sparse' option in
110+
'git pack-objects' when the '--revs' option is present. This
111+
algorithm only walks trees that appear in paths that introduce new
112+
objects. This can have significant performance benefits when
113+
computing a pack to send a small change. However, it is possible
114+
that extra objects are added to the pack-file if the included
115+
commits contain certain types of direct renames.
116+
108117
pack.writeBitmaps (deprecated)::
109118
This is a deprecated synonym for `repack.writeBitmaps`.
110119

builtin/pack-objects.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,10 @@ static int git_pack_config(const char *k, const char *v, void *cb)
27112711
use_bitmap_index_default = git_config_bool(k, v);
27122712
return 0;
27132713
}
2714+
if (!strcmp(k, "pack.usesparse")) {
2715+
sparse = git_config_bool(k, v);
2716+
return 0;
2717+
}
27142718
if (!strcmp(k, "pack.threads")) {
27152719
delta_search_threads = git_config_int(k, v);
27162720
if (delta_search_threads < 0)

t/t5322-pack-objects-sparse.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,19 @@ test_expect_success 'sparse pack-objects' '
121121
test_cmp expect_sparse_objects.txt sparse_objects.txt
122122
'
123123

124+
test_expect_success 'pack.useSparse enables algorithm' '
125+
git config pack.useSparse true &&
126+
git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
127+
git index-pack -o sparse.idx sparse.pack &&
128+
git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
129+
test_cmp expect_sparse_objects.txt sparse_objects.txt
130+
'
131+
132+
test_expect_success 'pack.useSparse overridden' '
133+
git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
134+
git index-pack -o sparse.idx sparse.pack &&
135+
git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
136+
test_cmp expect_objects.txt sparse_objects.txt
137+
'
138+
124139
test_done

0 commit comments

Comments
 (0)