Skip to content

Commit c5c84f3

Browse files
derrickstoleegitster
authored andcommitted
repo-settings: use index.version=4 by default
If a repo is large, it likely has many paths in its working directory. This means the index could be compressed using version 4. Set this as a default when core.featureAdoptionRate is at least three. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a01e97 commit c5c84f3

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

Documentation/config/core.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,6 @@ not modify the user-facing output of porcelain commands.
620620
+
621621
* `gc.writeCommitGraph=true` eneables writing commit-graph files during
622622
`git gc`.
623+
+
624+
* `index.version=4` uses prefix-compression to reduce the size of the
625+
.git/index file.

Documentation/config/index.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ index.threads::
2424
index.version::
2525
Specify the version with which new index files should be
2626
initialized. This does not affect existing repositories.
27+
If `core.featureAdoptionRate` is at least three, then the
28+
default value is 4.

read-cache.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "fsmonitor.h"
2626
#include "thread-utils.h"
2727
#include "progress.h"
28+
#include "repo-settings.h"
2829

2930
/* Mask for the name length in ce_flags in the on-disk index */
3031

@@ -1599,16 +1600,17 @@ struct cache_entry *refresh_cache_entry(struct index_state *istate,
15991600

16001601
#define INDEX_FORMAT_DEFAULT 3
16011602

1602-
static unsigned int get_index_format_default(void)
1603+
static unsigned int get_index_format_default(struct repository *r)
16031604
{
16041605
char *envversion = getenv("GIT_INDEX_VERSION");
16051606
char *endp;
1606-
int value;
16071607
unsigned int version = INDEX_FORMAT_DEFAULT;
16081608

16091609
if (!envversion) {
1610-
if (!git_config_get_int("index.version", &value))
1611-
version = value;
1610+
prepare_repo_settings(r);
1611+
1612+
if (r->settings->index_version >= 0)
1613+
version = r->settings->index_version;
16121614
if (version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) {
16131615
warning(_("index.version set, but the value is invalid.\n"
16141616
"Using version %i"), INDEX_FORMAT_DEFAULT);
@@ -2765,7 +2767,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
27652767
}
27662768

27672769
if (!istate->version) {
2768-
istate->version = get_index_format_default();
2770+
istate->version = get_index_format_default(the_repository);
27692771
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
27702772
init_split_index(istate);
27712773
}

repo-settings.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ static int git_repo_config(const char *key, const char *value, void *cb)
1414
if (rate >= 3) {
1515
UPDATE_DEFAULT(rs->core_commit_graph, 1);
1616
UPDATE_DEFAULT(rs->gc_write_commit_graph, 1);
17+
UPDATE_DEFAULT(rs->index_version, 4);
1718
}
1819
return 0;
1920
}
@@ -25,6 +26,10 @@ static int git_repo_config(const char *key, const char *value, void *cb)
2526
rs->gc_write_commit_graph = git_config_bool(key, value);
2627
return 0;
2728
}
29+
if (!strcmp(key, "index.version")) {
30+
rs->index_version = git_config_int(key, value);
31+
return 0;
32+
}
2833

2934
return 1;
3035
}
@@ -39,6 +44,7 @@ void prepare_repo_settings(struct repository *r)
3944
/* Defaults */
4045
r->settings->core_commit_graph = -1;
4146
r->settings->gc_write_commit_graph = -1;
47+
r->settings->index_version = -1;
4248

4349
repo_config(r, git_repo_config, r->settings);
4450
}

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+
int index_version;
78
};
89

910
struct repository;

0 commit comments

Comments
 (0)