Skip to content

Commit e8d9043

Browse files
committed
Merge branch 'ds/maintenance' into seen
A "git gc"'s big brother has been introduced to take care of more repository maintenance tasks, not limited to the object database cleaning. * ds/maintenance: maintenance: add trace2 regions for task execution maintenance: add auto condition for commit-graph task maintenance: use pointers to check --auto maintenance: create maintenance.<task>.enabled config maintenance: take a lock on the objects directory maintenance: add --task option maintenance: add commit-graph task maintenance: initialize task array maintenance: replace run_auto_gc() maintenance: add --quiet option maintenance: create basic maintenance runner
2 parents a1ea87a + b53509d commit e8d9043

23 files changed

+584
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
/git-ls-tree
9191
/git-mailinfo
9292
/git-mailsplit
93+
/git-maintenance
9394
/git-merge
9495
/git-merge-base
9596
/git-merge-index

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ include::config/mailinfo.txt[]
398398

399399
include::config/mailmap.txt[]
400400

401+
include::config/maintenance.txt[]
402+
401403
include::config/man.txt[]
402404

403405
include::config/merge.txt[]

Documentation/config/maintenance.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
maintenance.<task>.enabled::
2+
This boolean config option controls whether the maintenance task
3+
with name `<task>` is run when no `--task` option is specified.
4+
By default, only `maintenance.gc.enabled` is true.
5+
6+
maintenance.commit-graph.auto::
7+
This integer config option controls how often the `commit-graph` task
8+
should be run as part of `git maintenance run --auto`. If zero, then
9+
the `commit-graph` task will not run with the `--auto` option. A
10+
negative value will force the task to run every time. Otherwise, a
11+
positive value implies the command should run when the number of
12+
reachable commits that are not in the commit-graph file is at least
13+
the value of `maintenance.commit-graph.auto`. The default value is
14+
100.

Documentation/fetch-options.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ ifndef::git-pull[]
8686
Allow several <repository> and <group> arguments to be
8787
specified. No <refspec>s may be specified.
8888

89+
--[no-]auto-maintenance::
8990
--[no-]auto-gc::
90-
Run `git gc --auto` at the end to perform garbage collection
91-
if needed. This is enabled by default.
91+
Run `git maintenance run --auto` at the end to perform automatic
92+
repository maintenance if needed. (`--[no-]auto-gc` is a synonym.)
93+
This is enabled by default.
9294

9395
--[no-]write-commit-graph::
9496
Write a commit-graph after fetching. This overrides the config

Documentation/git-clone.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ repository using this option and then delete branches (or use any
7878
other Git command that makes any existing commit unreferenced) in the
7979
source repository, some objects may become unreferenced (or dangling).
8080
These objects may be removed by normal Git operations (such as `git commit`)
81-
which automatically call `git gc --auto`. (See linkgit:git-gc[1].)
82-
If these objects are removed and were referenced by the cloned repository,
83-
then the cloned repository will become corrupt.
81+
which automatically call `git maintenance run --auto`. (See
82+
linkgit:git-maintenance[1].) If these objects are removed and were referenced
83+
by the cloned repository, then the cloned repository will become corrupt.
8484
+
8585
Note that running `git repack` without the `--local` option in a repository
8686
cloned with `--shared` will copy objects from the source repository into a pack

Documentation/git-maintenance.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
git-maintenance(1)
2+
==================
3+
4+
NAME
5+
----
6+
git-maintenance - Run tasks to optimize Git repository data
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
'git maintenance' run [<options>]
13+
14+
15+
DESCRIPTION
16+
-----------
17+
Run tasks to optimize Git repository data, speeding up other Git commands
18+
and reducing storage requirements for the repository.
19+
+
20+
Git commands that add repository data, such as `git add` or `git fetch`,
21+
are optimized for a responsive user experience. These commands do not take
22+
time to optimize the Git data, since such optimizations scale with the full
23+
size of the repository while these user commands each perform a relatively
24+
small action.
25+
+
26+
The `git maintenance` command provides flexibility for how to optimize the
27+
Git repository.
28+
29+
SUBCOMMANDS
30+
-----------
31+
32+
run::
33+
Run one or more maintenance tasks. If one or more `--task` options
34+
are specified, then those tasks are run in that order. Otherwise,
35+
the tasks are determined by which `maintenance.<task>.enabled`
36+
config options are true. By default, only `maintenance.gc.enabled`
37+
is true.
38+
39+
TASKS
40+
-----
41+
42+
commit-graph::
43+
The `commit-graph` job updates the `commit-graph` files incrementally,
44+
then verifies that the written data is correct. If the new layer has an
45+
issue, then the chain file is removed and the `commit-graph` is
46+
rewritten from scratch.
47+
+
48+
The verification only checks the top layer of the `commit-graph` chain.
49+
If the incremental write merged the new commits with at least one
50+
existing layer, then there is potential for on-disk corruption being
51+
carried forward into the new file. This will be noticed and the new
52+
commit-graph file will be clean as Git reparses the commit data from
53+
the object database.
54+
+
55+
The incremental write is safe to run alongside concurrent Git processes
56+
since it will not expire `.graph` files that were in the previous
57+
`commit-graph-chain` file. They will be deleted by a later run based on
58+
the expiration delay.
59+
60+
gc::
61+
Cleanup unnecessary files and optimize the local repository. "GC"
62+
stands for "garbage collection," but this task performs many
63+
smaller tasks. This task can be rather expensive for large
64+
repositories, as it repacks all Git objects into a single pack-file.
65+
It can also be disruptive in some situations, as it deletes stale
66+
data.
67+
68+
OPTIONS
69+
-------
70+
--auto::
71+
When combined with the `run` subcommand, run maintenance tasks
72+
only if certain thresholds are met. For example, the `gc` task
73+
runs when the number of loose objects exceeds the number stored
74+
in the `gc.auto` config setting, or when the number of pack-files
75+
exceeds the `gc.autoPackLimit` config setting.
76+
77+
--quiet::
78+
Do not report progress or other information over `stderr`.
79+
80+
--task=<task>::
81+
If this option is specified one or more times, then only run the
82+
specified tasks in the specified order.
83+
84+
GIT
85+
---
86+
Part of the linkgit:git[1] suite

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix);
167167
int cmd_ls_remote(int argc, const char **argv, const char *prefix);
168168
int cmd_mailinfo(int argc, const char **argv, const char *prefix);
169169
int cmd_mailsplit(int argc, const char **argv, const char *prefix);
170+
int cmd_maintenance(int argc, const char **argv, const char *prefix);
170171
int cmd_merge(int argc, const char **argv, const char *prefix);
171172
int cmd_merge_base(int argc, const char **argv, const char *prefix);
172173
int cmd_merge_index(int argc, const char **argv, const char *prefix);

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ static void am_run(struct am_state *state, int resume)
17951795
if (!state->rebasing) {
17961796
am_destroy(state);
17971797
close_object_store(the_repository->objects);
1798-
run_auto_gc(state->quiet);
1798+
run_auto_maintenance(state->quiet);
17991799
}
18001800
}
18011801

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17021702
git_test_write_commit_graph_or_die();
17031703

17041704
repo_rerere(the_repository, 0);
1705-
run_auto_gc(quiet);
1705+
run_auto_maintenance(quiet);
17061706
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
17071707
if (amend && !no_post_rewrite) {
17081708
commit_post_rewrite(the_repository, current_head, &oid);

builtin/fetch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ static struct option builtin_fetch_options[] = {
196196
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
197197
N_("report that we have only objects reachable from this object")),
198198
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
199+
OPT_BOOL(0, "auto-maintenance", &enable_auto_gc,
200+
N_("run 'maintenance --auto' after fetching")),
199201
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
200-
N_("run 'gc --auto' after fetching")),
202+
N_("run 'maintenance --auto' after fetching")),
201203
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
202204
N_("check for forced-updates on all updated branches")),
203205
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
@@ -1882,7 +1884,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
18821884
close_object_store(the_repository->objects);
18831885

18841886
if (enable_auto_gc)
1885-
run_auto_gc(verbosity < 0);
1887+
run_auto_maintenance(verbosity < 0);
18861888

18871889
return result;
18881890
}

0 commit comments

Comments
 (0)