Merge branch 'ds/commit-graph-on-fetch'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:32 +0000 (13:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:32 +0000 (13:19 +0900)
A configuration variable tells "git fetch" to write the commit
graph after finishing.

* ds/commit-graph-on-fetch:
fetch: add fetch.writeCommitGraph config setting

Documentation/config/feature.txt
Documentation/config/fetch.txt
builtin/fetch.c
repo-settings.c
repository.h
t/t5510-fetch.sh
index 545522f306eb86e10c877208ab6949debda6870a..875f8c8a66f36464314d47decf433a82121a395b 100644 (file)
@@ -17,6 +17,14 @@ which can improve `git push` performance in repos with many files.
 +
 * `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
 skipping more commits at a time, reducing the number of round trips.
++
+* `fetch.writeCommitGraph=true` writes a commit-graph after every `git fetch`
+command that downloads a pack-file from a remote. Using the `--split` option,
+most executions will create a very small commit-graph file on top of the
+existing commit-graph file(s). Occasionally, these files will merge and the
+write may take longer. Having an updated commit-graph file helps performance
+of many Git commands, including `git merge-base`, `git push -f`, and
+`git log --graph`.
 
 feature.manyFiles::
        Enable config options that optimize for repos with many files in the
index d402110638b4e465075bf1a59885563d15f190e1..e8cb20547c5fbbb524932fd4efe09793fd544837 100644 (file)
@@ -69,3 +69,13 @@ fetch.showForcedUpdates::
        Set to false to enable `--no-show-forced-updates` in
        linkgit:git-fetch[1] and linkgit:git-pull[1] commands.
        Defaults to true.
+
+fetch.writeCommitGraph::
+       Set to true to write a commit-graph after every `git fetch` command
+       that downloads a pack-file from a remote. Using the `--split` option,
+       most executions will create a very small commit-graph file on top of
+       the existing commit-graph file(s). Occasionally, these files will
+       merge and the write may take longer. Having an updated commit-graph
+       file helps performance of many Git commands, including `git merge-base`,
+       `git push -f`, and `git log --graph`. Defaults to false, unless
+       `feature.experimental` is true.
index 9b27ae968199a75e62a617b649b56788e501e076..67c0eb88c655ab949845b626367b3f2192e9ccb6 100644 (file)
@@ -25,6 +25,7 @@
 #include "commit-reach.h"
 #include "branch.h"
 #include "promisor-remote.h"
+#include "commit-graph.h"
 
 #define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
 
@@ -1759,6 +1760,20 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 
        string_list_clear(&list, 0);
 
+       prepare_repo_settings(the_repository);
+       if (the_repository->settings.fetch_write_commit_graph) {
+               int commit_graph_flags = COMMIT_GRAPH_WRITE_SPLIT;
+               struct split_commit_graph_opts split_opts;
+               memset(&split_opts, 0, sizeof(struct split_commit_graph_opts));
+
+               if (progress)
+                       commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
+
+               write_commit_graph_reachable(get_object_directory(),
+                                            commit_graph_flags,
+                                            &split_opts);
+       }
+
        close_object_store(the_repository->objects);
 
        if (enable_auto_gc) {
index 3779b85c17532c7f51de0ae6e28208e3ca2c9c8e..05546db98eebb469bfeca854de1c3f4e9cc25b5b 100644 (file)
@@ -49,10 +49,14 @@ void prepare_repo_settings(struct repository *r)
                UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
                UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
        }
+       if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value))
+               r->settings.fetch_write_commit_graph = value;
        if (!repo_config_get_bool(r, "feature.experimental", &value) && value) {
                UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1);
                UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
+               UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 1);
        }
+       UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0);
 
        /* Hack for test programs like test-dump-untracked-cache */
        if (ignore_untracked_cache_config)
index 4da275e73fac1a97c39109b7bf31ae01f20e0730..fe0b5f5dc673ba5c1e8012f049717bb98abdbe52 100644 (file)
@@ -30,6 +30,7 @@ struct repo_settings {
 
        int core_commit_graph;
        int gc_write_commit_graph;
+       int fetch_write_commit_graph;
 
        int index_version;
        enum untracked_cache_setting core_untracked_cache;
index 34b486f1a48b08f483d36c6421e47323977db9d0..ecabbe1616d8a5c597fc32a354b053bc38a40334 100755 (executable)
@@ -570,6 +570,19 @@ test_expect_success 'LHS of refspec follows ref disambiguation rules' '
        )
 '
 
+test_expect_success 'fetch.writeCommitGraph' '
+       git clone three write &&
+       (
+               cd three &&
+               test_commit new
+       ) &&
+       (
+               cd write &&
+               git -c fetch.writeCommitGraph fetch origin &&
+               test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
+       )
+'
+
 # configured prune tests
 
 set_config_tristate () {