Skip to content

Commit d5d5d7b

Browse files
derrickstoleegitster
authored andcommitted
gc: automatically write commit-graph files
The commit-graph file is a very helpful feature for speeding up git operations. In order to make it more useful, make it possible to write the commit-graph file during standard garbage collection operations. Add a 'gc.commitGraph' config setting that triggers writing a commit-graph file after any non-trivial 'git gc' command. Defaults to false while the commit-graph feature matures. We specifically do not want to have this on by default until the commit-graph feature is fully integrated with history-modifying features like shallow clones. Helped-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59fb877 commit d5d5d7b

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

Documentation/config.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,12 @@ core.notesRef::
904904
This setting defaults to "refs/notes/commits", and it can be overridden by
905905
the `GIT_NOTES_REF` environment variable. See linkgit:git-notes[1].
906906

907-
core.commitGraph::
908-
Enable git commit graph feature. Allows reading from the
909-
commit-graph file.
907+
gc.commitGraph::
908+
If true, then gc will rewrite the commit-graph file when
909+
linkgit:git-gc[1] is run. When using linkgit:git-gc[1]
910+
'--auto' the commit-graph will be updated if housekeeping is
911+
required. Default is false. See linkgit:git-commit-graph[1]
912+
for details.
910913

911914
core.sparseCheckout::
912915
Enable "sparse checkout" feature. See section "Sparse checkout" in

Documentation/git-gc.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ The optional configuration variable `gc.packRefs` determines if
136136
it within all non-bare repos or it can be set to a boolean value.
137137
This defaults to true.
138138

139+
The optional configuration variable `gc.commitGraph` determines if
140+
'git gc' should run 'git commit-graph write'. This can be set to a
141+
boolean value. This defaults to false.
142+
139143
The optional configuration variable `gc.aggressiveWindow` controls how
140144
much time is spent optimizing the delta compression of the objects in
141145
the repository when the --aggressive option is specified. The larger

builtin/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "sigchain.h"
2121
#include "argv-array.h"
2222
#include "commit.h"
23+
#include "commit-graph.h"
2324
#include "packfile.h"
2425
#include "object-store.h"
2526
#include "pack.h"
@@ -40,6 +41,7 @@ static int aggressive_depth = 50;
4041
static int aggressive_window = 250;
4142
static int gc_auto_threshold = 6700;
4243
static int gc_auto_pack_limit = 50;
44+
static int gc_write_commit_graph;
4345
static int detach_auto = 1;
4446
static timestamp_t gc_log_expire_time;
4547
static const char *gc_log_expire = "1.day.ago";
@@ -129,6 +131,7 @@ static void gc_config(void)
129131
git_config_get_int("gc.aggressivedepth", &aggressive_depth);
130132
git_config_get_int("gc.auto", &gc_auto_threshold);
131133
git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
134+
git_config_get_bool("gc.writecommitgraph", &gc_write_commit_graph);
132135
git_config_get_bool("gc.autodetach", &detach_auto);
133136
git_config_get_expiry("gc.pruneexpire", &prune_expire);
134137
git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire);
@@ -641,6 +644,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
641644
if (pack_garbage.nr > 0)
642645
clean_pack_garbage();
643646

647+
if (gc_write_commit_graph)
648+
write_commit_graph_reachable(get_object_directory(), 0);
649+
644650
if (auto_gc && too_many_loose_objects())
645651
warning(_("There are too many unreachable loose objects; "
646652
"run 'git prune' to remove them."));

t/t5318-commit-graph.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ test_expect_success 'perform fast-forward merge in full repo' '
245245
test_cmp expect output
246246
'
247247

248+
test_expect_success 'check that gc computes commit-graph' '
249+
cd "$TRASH_DIRECTORY/full" &&
250+
git commit --allow-empty -m "blank" &&
251+
git commit-graph write --reachable &&
252+
cp $objdir/info/commit-graph commit-graph-before-gc &&
253+
git reset --hard HEAD~1 &&
254+
git config gc.writeCommitGraph true &&
255+
git gc &&
256+
cp $objdir/info/commit-graph commit-graph-after-gc &&
257+
! test_cmp commit-graph-before-gc commit-graph-after-gc &&
258+
git commit-graph write --reachable &&
259+
test_cmp commit-graph-after-gc $objdir/info/commit-graph
260+
'
261+
248262
# the verify tests below expect the commit-graph to contain
249263
# exactly the commits reachable from the commits/8 branch.
250264
# If the file changes the set of commits in the list, then the

0 commit comments

Comments
 (0)