Skip to content

Commit 3172404

Browse files
derrickstoleegitster
authored andcommitted
repo-settings: pack.useSparse=true
If a repo is large, then it probably has a very large working directory. In this case, a typical developer's edits usually impact many fewer paths than the full path set. The sparse treewalk algorithm is optimized for this case, speeding up 'git push' calls. Use pack.useSparse=true when core.featureAdoptionRate is at least five. This is the first setting where the feature has only been out for a single major version. This could be moved to the "at least three" category after another major version. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c5c84f3 commit 3172404

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

Documentation/config/core.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,12 @@ not modify the user-facing output of porcelain commands.
623623
+
624624
* `index.version=4` uses prefix-compression to reduce the size of the
625625
.git/index file.
626+
+
627+
If the value is at least 5, then all of the defaults above are included,
628+
plus the defaults below. These represent new features that present
629+
significant performance benefits, but may not have been released for
630+
multiple major versions.
631+
+
632+
* `pack.useSparse=true` uses the sparse tree-walk algorithm, which is
633+
optimized for enumerating objects during linkgit:git-push[1] from a
634+
client machine.

Documentation/config/pack.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pack.useSparse::
112112
objects. This can have significant performance benefits when
113113
computing a pack to send a small change. However, it is possible
114114
that extra objects are added to the pack-file if the included
115-
commits contain certain types of direct renames.
115+
commits contain certain types of direct renames. Defaults to
116+
false, unless `core.featureAdoptionRate` is at least five.
116117

117118
pack.writeBitmaps (deprecated)::
118119
This is a deprecated synonym for `repack.writeBitmaps`.

builtin/pack-objects.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "dir.h"
3535
#include "midx.h"
3636
#include "trace2.h"
37+
#include "repo-settings.h"
3738

3839
#define IN_PACK(obj) oe_in_pack(&to_pack, obj)
3940
#define SIZE(obj) oe_size(&to_pack, obj)
@@ -2707,10 +2708,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
27072708
use_bitmap_index_default = git_config_bool(k, v);
27082709
return 0;
27092710
}
2710-
if (!strcmp(k, "pack.usesparse")) {
2711-
sparse = git_config_bool(k, v);
2712-
return 0;
2713-
}
27142711
if (!strcmp(k, "pack.threads")) {
27152712
delta_search_threads = git_config_int(k, v);
27162713
if (delta_search_threads < 0)
@@ -3330,6 +3327,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
33303327
read_replace_refs = 0;
33313328

33323329
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", 0);
3330+
prepare_repo_settings(the_repository);
3331+
if (!sparse && the_repository->settings->pack_use_sparse != -1)
3332+
sparse = the_repository->settings->pack_use_sparse;
3333+
33333334
reset_pack_idx_option(&pack_idx_opts);
33343335
git_config(git_pack_config, NULL);
33353336

repo-settings.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ static int git_repo_config(const char *key, const char *value, void *cb)
1616
UPDATE_DEFAULT(rs->gc_write_commit_graph, 1);
1717
UPDATE_DEFAULT(rs->index_version, 4);
1818
}
19+
if (rate >= 5) {
20+
UPDATE_DEFAULT(rs->pack_use_sparse, 1);
21+
}
1922
return 0;
2023
}
2124
if (!strcmp(key, "core.commitgraph")) {
@@ -26,6 +29,10 @@ static int git_repo_config(const char *key, const char *value, void *cb)
2629
rs->gc_write_commit_graph = git_config_bool(key, value);
2730
return 0;
2831
}
32+
if (!strcmp(key, "pack.usesparse")) {
33+
rs->pack_use_sparse = git_config_bool(key, value);
34+
return 0;
35+
}
2936
if (!strcmp(key, "index.version")) {
3037
rs->index_version = git_config_int(key, value);
3138
return 0;
@@ -44,6 +51,7 @@ void prepare_repo_settings(struct repository *r)
4451
/* Defaults */
4552
r->settings->core_commit_graph = -1;
4653
r->settings->gc_write_commit_graph = -1;
54+
r->settings->pack_use_sparse = -1;
4755
r->settings->index_version = -1;
4856

4957
repo_config(r, git_repo_config, r->settings);

repo-settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct repo_settings {
55
char core_commit_graph;
66
char gc_write_commit_graph;
7+
char pack_use_sparse;
78
int index_version;
89
};
910

0 commit comments

Comments
 (0)