Skip to content

Commit b79973c

Browse files
committed
Merge branch 'ds/maintenance-part-2' into seen
* ds/maintenance-part-2: maintenance: add incremental-repack auto condition maintenance: auto-size incremental-repack batch maintenance: add incremental-repack task midx: use start_delayed_progress() midx: enable core.multiPackIndex by default maintenance: create auto condition for loose-objects maintenance: add loose-objects task maintenance: add prefetch task fetch: optionally allow disabling FETCH_HEAD update
2 parents bf7a618 + 6029cb0 commit b79973c

16 files changed

+730
-29
lines changed

Documentation/config/core.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ core.useReplaceRefs::
606606

607607
core.multiPackIndex::
608608
Use the multi-pack-index file to track multiple packfiles using a
609-
single index. See link:technical/multi-pack-index.html[the
610-
multi-pack-index design document].
609+
single index. See linkgit:git-multi-pack-index[1] for more
610+
information. Defaults to true.
611611

612612
core.sparseCheckout::
613613
Enable "sparse checkout" feature. See linkgit:git-sparse-checkout[1]

Documentation/config/fetch.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ fetch.writeCommitGraph::
9191
merge and the write may take longer. Having an updated commit-graph
9292
file helps performance of many Git commands, including `git merge-base`,
9393
`git push -f`, and `git log --graph`. Defaults to false.
94+
95+
fetch.writeFetchHEAD::
96+
Setting it to false tells `git fetch` not to write the list
97+
of remote refs fetched in the `FETCH_HEAD` file directly
98+
under `$GIT_DIR`. Can be countermanded from the command
99+
line with the `--[no-]write-fetch-head` option. Defaults to
100+
true.

Documentation/config/maintenance.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ maintenance.commit-graph.auto::
1212
reachable commits that are not in the commit-graph file is at least
1313
the value of `maintenance.commit-graph.auto`. The default value is
1414
100.
15+
16+
maintenance.loose-objects.auto::
17+
This integer config option controls how often the `loose-objects` task
18+
should be run as part of `git maintenance run --auto`. If zero, then
19+
the `loose-objects` task will not run with the `--auto` option. A
20+
negative value will force the task to run every time. Otherwise, a
21+
positive value implies the command should run when the number of
22+
loose objects is at least the value of `maintenance.loose-objects.auto`.
23+
The default value is 100.
24+
25+
maintenance.incremental-repack.auto::
26+
This integer config option controls how often the `incremental-repack`
27+
task should be run as part of `git maintenance run --auto`. If zero,
28+
then the `incremental-repack` task will not run with the `--auto`
29+
option. A negative value will force the task to run every time.
30+
Otherwise, a positive value implies the command should run when the
31+
number of pack-files not in the multi-pack-index is at least the value
32+
of `maintenance.incremental-repack.auto`. The default value is 10.

Documentation/fetch-options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ documented in linkgit:git-config[1].
6464
--dry-run::
6565
Show what would be done, without making any changes.
6666

67+
ifndef::git-pull[]
68+
--[no-]write-fetch-head::
69+
Write the list of remote refs fetched in the `FETCH_HEAD`
70+
file directly under `$GIT_DIR`. This is the default unless
71+
the configuration variable `fetch.writeFetchHEAD` is set to
72+
false. Passing `--no-write-fetch-head` from the command
73+
line tells Git not to write the file. Under `--dry-run`
74+
option, the file is never written.
75+
endif::git-pull[]
76+
6777
-f::
6878
--force::
6979
When 'git fetch' is used with `<src>:<dst>` refspec it may

Documentation/git-maintenance.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ since it will not expire `.graph` files that were in the previous
5757
`commit-graph-chain` file. They will be deleted by a later run based on
5858
the expiration delay.
5959

60+
prefetch::
61+
The `prefetch` task updates the object directory with the latest
62+
objects from all registered remotes. For each remote, a `git fetch`
63+
command is run. The refmap is custom to avoid updating local or remote
64+
branches (those in `refs/heads` or `refs/remotes`). Instead, the
65+
remote refs are stored in `refs/prefetch/<remote>/`. Also, tags are
66+
not updated.
67+
+
68+
This is done to avoid disrupting the remote-tracking branches. The end users
69+
expect these refs to stay unmoved unless they initiate a fetch. With prefetch
70+
task, however, the objects necessary to complete a later real fetch would
71+
already be obtained, so the real fetch would go faster. In the ideal case,
72+
it will just become an update to bunch of remote-tracking branches without
73+
any object transfer.
74+
6075
gc::
6176
Cleanup unnecessary files and optimize the local repository. "GC"
6277
stands for "garbage collection," but this task performs many
@@ -65,6 +80,32 @@ gc::
6580
It can also be disruptive in some situations, as it deletes stale
6681
data.
6782

83+
loose-objects::
84+
The `loose-objects` job cleans up loose objects and places them into
85+
pack-files. In order to prevent race conditions with concurrent Git
86+
commands, it follows a two-step process. First, it deletes any loose
87+
objects that already exist in a pack-file; concurrent Git processes
88+
will examine the pack-file for the object data instead of the loose
89+
object. Second, it creates a new pack-file (starting with "loose-")
90+
containing a batch of loose objects. The batch size is limited to 50
91+
thousand objects to prevent the job from taking too long on a
92+
repository with many loose objects.
93+
94+
incremental-repack::
95+
The `incremental-repack` job repacks the object directory
96+
using the `multi-pack-index` feature. In order to prevent race
97+
conditions with concurrent Git commands, it follows a two-step
98+
process. First, it deletes any pack-files included in the
99+
`multi-pack-index` where none of the objects in the
100+
`multi-pack-index` reference those pack-files; this only happens
101+
if all objects in the pack-file are also stored in a newer
102+
pack-file. Second, it selects a group of pack-files whose "expected
103+
size" is below the batch size until the group has total expected
104+
size at least the batch size; see the `--batch-size` option for
105+
the `repack` subcommand in linkgit:git-multi-pack-index[1]. The
106+
default batch-size is zero, which is a special case that attempts
107+
to repack all pack-files into a single pack-file.
108+
68109
OPTIONS
69110
-------
70111
--auto::

builtin/fetch.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static int prune_tags = -1; /* unspecified */
5656
#define PRUNE_TAGS_BY_DEFAULT 0 /* do we prune tags by default? */
5757

5858
static int all, append, dry_run, force, keep, multiple, update_head_ok;
59+
static int write_fetch_head = 1;
5960
static int verbosity, deepen_relative, set_upstream;
6061
static int progress = -1;
6162
static int enable_auto_gc = 1;
@@ -118,6 +119,10 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
118119
return 0;
119120
}
120121

122+
if (!strcmp(k, "fetch.writefetchhead")) {
123+
write_fetch_head = git_config_bool(k, v);
124+
return 0;
125+
}
121126
return git_default_config(k, v, cb);
122127
}
123128

@@ -162,6 +167,8 @@ static struct option builtin_fetch_options[] = {
162167
PARSE_OPT_OPTARG, option_fetch_parse_recurse_submodules),
163168
OPT_BOOL(0, "dry-run", &dry_run,
164169
N_("dry run")),
170+
OPT_BOOL(0, "write-fetch-head", &write_fetch_head,
171+
N_("write fetched references to the FETCH_HEAD file")),
165172
OPT_BOOL('k', "keep", &keep, N_("keep downloaded pack")),
166173
OPT_BOOL('u', "update-head-ok", &update_head_ok,
167174
N_("allow updating of HEAD ref")),
@@ -895,7 +902,9 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
895902
const char *what, *kind;
896903
struct ref *rm;
897904
char *url;
898-
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head(the_repository);
905+
const char *filename = (!write_fetch_head
906+
? "/dev/null"
907+
: git_path_fetch_head(the_repository));
899908
int want_status;
900909
int summary_width = transport_summary_width(ref_map);
901910

@@ -1329,7 +1338,7 @@ static int do_fetch(struct transport *transport,
13291338
}
13301339

13311340
/* if not appending, truncate FETCH_HEAD */
1332-
if (!append && !dry_run) {
1341+
if (!append && write_fetch_head) {
13331342
retcode = truncate_fetch_head();
13341343
if (retcode)
13351344
goto cleanup;
@@ -1596,7 +1605,7 @@ static int fetch_multiple(struct string_list *list, int max_children)
15961605
int i, result = 0;
15971606
struct strvec argv = STRVEC_INIT;
15981607

1599-
if (!append && !dry_run) {
1608+
if (!append && write_fetch_head) {
16001609
int errcode = truncate_fetch_head();
16011610
if (errcode)
16021611
return errcode;
@@ -1797,6 +1806,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
17971806
if (depth || deepen_since || deepen_not.nr)
17981807
deepen = 1;
17991808

1809+
/* FETCH_HEAD never gets updated in --dry-run mode */
1810+
if (dry_run)
1811+
write_fetch_head = 0;
1812+
18001813
if (all) {
18011814
if (argc == 1)
18021815
die(_("fetch --all does not take a repository argument"));

0 commit comments

Comments
 (0)