Skip to content

Commit 48794ac

Browse files
committed
Merge branch 'ds/maintenance-part-1'
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-part-1: 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 e1cfff6 + 25914c4 commit 48794ac

24 files changed

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

Documentation/fetch-options.txt

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

98+
--[no-]auto-maintenance::
9899
--[no-]auto-gc::
99-
Run `git gc --auto` at the end to perform garbage collection
100-
if needed. This is enabled by default.
100+
Run `git maintenance run --auto` at the end to perform automatic
101+
repository maintenance if needed. (`--[no-]auto-gc` is a synonym.)
102+
This is enabled by default.
101103

102104
--[no-]write-commit-graph::
103105
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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. The incremental
45+
write is safe to run alongside concurrent Git processes since it
46+
will not expire `.graph` files that were in the previous
47+
`commit-graph-chain` file. They will be deleted by a later run based
48+
on the expiration delay.
49+
50+
gc::
51+
Clean up unnecessary files and optimize the local repository. "GC"
52+
stands for "garbage collection," but this task performs many
53+
smaller tasks. This task can be expensive for large repositories,
54+
as it repacks all Git objects into a single pack-file. It can also
55+
be disruptive in some situations, as it deletes stale data. See
56+
linkgit:git-gc[1] for more details on garbage collection in Git.
57+
58+
OPTIONS
59+
-------
60+
--auto::
61+
When combined with the `run` subcommand, run maintenance tasks
62+
only if certain thresholds are met. For example, the `gc` task
63+
runs when the number of loose objects exceeds the number stored
64+
in the `gc.auto` config setting, or when the number of pack-files
65+
exceeds the `gc.autoPackLimit` config setting.
66+
67+
--quiet::
68+
Do not report progress or other information over `stderr`.
69+
70+
--task=<task>::
71+
If this option is specified one or more times, then only run the
72+
specified tasks in the specified order. If no `--task=<task>`
73+
arguments are specified, then only the tasks with
74+
`maintenance.<task>.enabled` configured as `true` are considered.
75+
See the 'TASKS' section for the list of accepted `<task>` values.
76+
77+
GIT
78+
---
79+
Part of the linkgit:git[1] suite

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix);
172172
int cmd_ls_remote(int argc, const char **argv, const char *prefix);
173173
int cmd_mailinfo(int argc, const char **argv, const char *prefix);
174174
int cmd_mailsplit(int argc, const char **argv, const char *prefix);
175+
int cmd_maintenance(int argc, const char **argv, const char *prefix);
175176
int cmd_merge(int argc, const char **argv, const char *prefix);
176177
int cmd_merge_base(int argc, const char **argv, const char *prefix);
177178
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
@@ -1813,7 +1813,7 @@ static void am_run(struct am_state *state, int resume)
18131813
if (!state->rebasing) {
18141814
am_destroy(state);
18151815
close_object_store(the_repository->objects);
1816-
run_auto_gc(state->quiet);
1816+
run_auto_maintenance(state->quiet);
18171817
}
18181818
}
18191819

builtin/commit.c

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

17021702
repo_rerere(the_repository, 0);
1703-
run_auto_gc(quiet);
1703+
run_auto_maintenance(quiet);
17041704
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
17051705
if (amend && !no_post_rewrite) {
17061706
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
@@ -200,8 +200,10 @@ static struct option builtin_fetch_options[] = {
200200
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
201201
N_("report that we have only objects reachable from this object")),
202202
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
203+
OPT_BOOL(0, "auto-maintenance", &enable_auto_gc,
204+
N_("run 'maintenance --auto' after fetching")),
203205
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
204-
N_("run 'gc --auto' after fetching")),
206+
N_("run 'maintenance --auto' after fetching")),
205207
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
206208
N_("check for forced-updates on all updated branches")),
207209
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
@@ -1925,7 +1927,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
19251927
close_object_store(the_repository->objects);
19261928

19271929
if (enable_auto_gc)
1928-
run_auto_gc(verbosity < 0);
1930+
run_auto_maintenance(verbosity < 0);
19291931

19301932
return result;
19311933
}

0 commit comments

Comments
 (0)