Skip to content

Commit 50f26bd

Browse files
derrickstoleegitster
authored andcommitted
fetch: add fetch.writeCommitGraph config setting
The commit-graph feature is now on by default, and is being written during 'git gc' by default. Typically, Git only writes a commit-graph when a 'git gc --auto' command passes the gc.auto setting to actualy do work. This means that a commit-graph will typically fall behind the commits that are being used every day. To stay updated with the latest commits, add a step to 'git fetch' to write a commit-graph after fetching new objects. The fetch.writeCommitGraph config setting enables writing a split commit-graph, so on average the cost of writing this file is very small. Occasionally, the commit-graph chain will collapse to a single level, and this could be slow for very large repos. For additional use, adjust the default to be true when feature.experimental is enabled. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaf633c commit 50f26bd

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

Documentation/config/feature.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ which can improve `git push` performance in repos with many files.
1717
+
1818
* `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
1919
skipping more commits at a time, reducing the number of round trips.
20+
+
21+
* `fetch.writeCommitGraph=true` writes a commit-graph after every `git fetch`
22+
command that downloads a pack-file from a remote. Using the `--split` option,
23+
most executions will create a very small commit-graph file on top of the
24+
existing commit-graph file(s). Occasionally, these files will merge and the
25+
write may take longer. Having an updated commit-graph file helps performance
26+
of many Git commands, including `git merge-base`, `git push -f`, and
27+
`git log --graph`.
2028

2129
feature.manyFiles::
2230
Enable config options that optimize for repos with many files in the

Documentation/config/fetch.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ fetch.showForcedUpdates::
6969
Set to false to enable `--no-show-forced-updates` in
7070
linkgit:git-fetch[1] and linkgit:git-pull[1] commands.
7171
Defaults to true.
72+
73+
fetch.writeCommitGraph::
74+
Set to true to write a commit-graph after every `git fetch` command
75+
that downloads a pack-file from a remote. Using the `--split` option,
76+
most executions will create a very small commit-graph file on top of
77+
the existing commit-graph file(s). Occasionally, these files will
78+
merge and the write may take longer. Having an updated commit-graph
79+
file helps performance of many Git commands, including `git merge-base`,
80+
`git push -f`, and `git log --graph`. Defaults to false, unless
81+
`feature.experimental` is true.

builtin/fetch.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "packfile.h"
2424
#include "list-objects-filter-options.h"
2525
#include "commit-reach.h"
26+
#include "commit-graph.h"
2627

2728
#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
2829

@@ -1715,6 +1716,20 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
17151716

17161717
string_list_clear(&list, 0);
17171718

1719+
prepare_repo_settings(the_repository);
1720+
if (the_repository->settings.fetch_write_commit_graph) {
1721+
int commit_graph_flags = COMMIT_GRAPH_SPLIT;
1722+
struct split_commit_graph_opts split_opts;
1723+
memset(&split_opts, 0, sizeof(struct split_commit_graph_opts));
1724+
1725+
if (progress)
1726+
commit_graph_flags |= COMMIT_GRAPH_PROGRESS;
1727+
1728+
write_commit_graph_reachable(get_object_directory(),
1729+
commit_graph_flags,
1730+
&split_opts);
1731+
}
1732+
17181733
close_object_store(the_repository->objects);
17191734

17201735
if (enable_auto_gc) {

repo-settings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ void prepare_repo_settings(struct repository *r)
4949
UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
5050
UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
5151
}
52+
if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value))
53+
r->settings.fetch_write_commit_graph = value;
5254
if (!repo_config_get_bool(r, "feature.experimental", &value) && value) {
5355
UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1);
5456
UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
57+
UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 1);
5558
}
59+
UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0);
5660

5761
/* Hack for test programs like test-dump-untracked-cache */
5862
if (ignore_untracked_cache_config)

repository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct repo_settings {
3030

3131
int core_commit_graph;
3232
int gc_write_commit_graph;
33+
int fetch_write_commit_graph;
3334

3435
int index_version;
3536
enum untracked_cache_setting core_untracked_cache;

t/t5510-fetch.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,19 @@ test_expect_success 'LHS of refspec follows ref disambiguation rules' '
570570
)
571571
'
572572

573+
test_expect_success 'fetch.writeCommitGraph' '
574+
git clone three write &&
575+
(
576+
cd three &&
577+
test_commit new
578+
) &&
579+
(
580+
cd write &&
581+
git -c fetch.writeCommitGraph fetch origin &&
582+
test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
583+
)
584+
'
585+
573586
# configured prune tests
574587

575588
set_config_tristate () {

0 commit comments

Comments
 (0)