Skip to content

Commit 5a53509

Browse files
committed
Merge branch 'ds/commit-graph-on-fetch'
A configuration variable tells "git fetch" to write the commit graph after finishing. * ds/commit-graph-on-fetch: fetch: add fetch.writeCommitGraph config setting
2 parents 974bdb0 + 50f26bd commit 5a53509

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
@@ -25,6 +25,7 @@
2525
#include "commit-reach.h"
2626
#include "branch.h"
2727
#include "promisor-remote.h"
28+
#include "commit-graph.h"
2829

2930
#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
3031

@@ -1759,6 +1760,20 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
17591760

17601761
string_list_clear(&list, 0);
17611762

1763+
prepare_repo_settings(the_repository);
1764+
if (the_repository->settings.fetch_write_commit_graph) {
1765+
int commit_graph_flags = COMMIT_GRAPH_WRITE_SPLIT;
1766+
struct split_commit_graph_opts split_opts;
1767+
memset(&split_opts, 0, sizeof(struct split_commit_graph_opts));
1768+
1769+
if (progress)
1770+
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
1771+
1772+
write_commit_graph_reachable(get_object_directory(),
1773+
commit_graph_flags,
1774+
&split_opts);
1775+
}
1776+
17621777
close_object_store(the_repository->objects);
17631778

17641779
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)