зеркало из https://github.com/microsoft/git.git
Merge current ds/maintenance-part-4 into vfs-2.29.0
After reverting the previous commits of part-3, include the latest mostly-stable version of the patches from upstream. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
This commit is contained in:
Коммит
7a2faf21ca
|
@ -67,6 +67,7 @@
|
|||
/git-filter-branch
|
||||
/git-fmt-merge-msg
|
||||
/git-for-each-ref
|
||||
/git-for-each-repo
|
||||
/git-format-patch
|
||||
/git-fsck
|
||||
/git-fsck-objects
|
||||
|
|
|
@ -627,8 +627,8 @@ core.useReplaceRefs::
|
|||
|
||||
core.multiPackIndex::
|
||||
Use the multi-pack-index file to track multiple packfiles using a
|
||||
single index. See link:technical/multi-pack-index.html[the
|
||||
multi-pack-index design document].
|
||||
single index. See linkgit:git-multi-pack-index[1] for more
|
||||
information. Defaults to true.
|
||||
|
||||
core.gvfs::
|
||||
Enable the features needed for GVFS. This value can be set to true
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
maintenance.auto::
|
||||
This boolean config option controls whether some commands run
|
||||
`git maintenance run --auto` after doing their normal work. Defaults
|
||||
to true.
|
||||
|
||||
maintenance.strategy::
|
||||
This string config option provides a way to specify one of a few
|
||||
recommended schedules for background maintenance. This only affects
|
||||
which tasks are run during `git maintenance run --schedule=X`
|
||||
commands, provided no `--task=<task>` arguments are provided.
|
||||
Further, if a `maintenance.<task>.schedule` config value is set,
|
||||
then that value is used instead of the one provided by
|
||||
`maintenance.strategy`. The possible strategy strings are:
|
||||
+
|
||||
* `none`: This default setting implies no task are run at any schedule.
|
||||
* `incremental`: This setting optimizes for performing small maintenance
|
||||
activities that do not delete any data. This does not schedule the `gc`
|
||||
task, but runs the `prefetch` and `commit-graph` tasks hourly and the
|
||||
`loose-objects` and `incremental-repack` tasks daily.
|
||||
|
||||
maintenance.<task>.enabled::
|
||||
This boolean config option controls whether the maintenance task
|
||||
with name `<task>` is run when no `--task` option is specified to
|
||||
|
@ -5,6 +25,11 @@ maintenance.<task>.enabled::
|
|||
`--task` option exists. By default, only `maintenance.gc.enabled`
|
||||
is true.
|
||||
|
||||
maintenance.<task>.schedule::
|
||||
This config option controls whether or not the given `<task>` runs
|
||||
during a `git maintenance run --schedule=<frequency>` command. The
|
||||
value must be one of "hourly", "daily", or "weekly".
|
||||
|
||||
maintenance.commit-graph.auto::
|
||||
This integer config option controls how often the `commit-graph` task
|
||||
should be run as part of `git maintenance run --auto`. If zero, then
|
||||
|
@ -14,3 +39,21 @@ maintenance.commit-graph.auto::
|
|||
reachable commits that are not in the commit-graph file is at least
|
||||
the value of `maintenance.commit-graph.auto`. The default value is
|
||||
100.
|
||||
|
||||
maintenance.loose-objects.auto::
|
||||
This integer config option controls how often the `loose-objects` task
|
||||
should be run as part of `git maintenance run --auto`. If zero, then
|
||||
the `loose-objects` task will not run with the `--auto` option. A
|
||||
negative value will force the task to run every time. Otherwise, a
|
||||
positive value implies the command should run when the number of
|
||||
loose objects is at least the value of `maintenance.loose-objects.auto`.
|
||||
The default value is 100.
|
||||
|
||||
maintenance.incremental-repack.auto::
|
||||
This integer config option controls how often the `incremental-repack`
|
||||
task should be run as part of `git maintenance run --auto`. If zero,
|
||||
then the `incremental-repack` task will not run with the `--auto`
|
||||
option. A negative value will force the task to run every time.
|
||||
Otherwise, a positive value implies the command should run when the
|
||||
number of pack-files not in the multi-pack-index is at least the value
|
||||
of `maintenance.incremental-repack.auto`. The default value is 10.
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
git-for-each-repo(1)
|
||||
====================
|
||||
|
||||
NAME
|
||||
----
|
||||
git-for-each-repo - Run a Git command on a list of repositories
|
||||
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
[verse]
|
||||
'git for-each-repo' --config=<config> [--] <arguments>
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
Run a Git command on a list of repositories. The arguments after the
|
||||
known options or `--` indicator are used as the arguments for the Git
|
||||
subprocess.
|
||||
|
||||
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
|
||||
|
||||
For example, we could run maintenance on each of a list of repositories
|
||||
stored in a `maintenance.repo` config variable using
|
||||
|
||||
-------------
|
||||
git for-each-repo --config=maintenance.repo maintenance run
|
||||
-------------
|
||||
|
||||
This will run `git -C <repo> maintenance run` for each value `<repo>`
|
||||
in the multi-valued config variable `maintenance.repo`.
|
||||
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
--config=<config>::
|
||||
Use the given config variable as a multi-valued list storing
|
||||
absolute path names. Iterate on that list of paths to run
|
||||
the given arguments.
|
||||
+
|
||||
These config values are loaded from system, global, and local Git config,
|
||||
as available. If `git for-each-repo` is run in a directory that is not a
|
||||
Git repository, then only the system and global config is used.
|
||||
|
||||
|
||||
SUBPROCESS BEHAVIOR
|
||||
-------------------
|
||||
|
||||
If any `git -C <repo> <arguments>` subprocess returns a non-zero exit code,
|
||||
then the `git for-each-repo` process returns that exit code without running
|
||||
more subprocesses.
|
||||
|
||||
Each `git -C <repo> <arguments>` subprocess inherits the standard file
|
||||
descriptors `stdin`, `stdout`, and `stderr`.
|
||||
|
||||
|
||||
GIT
|
||||
---
|
||||
Part of the linkgit:git[1] suite
|
|
@ -29,6 +29,32 @@ Git repository.
|
|||
SUBCOMMANDS
|
||||
-----------
|
||||
|
||||
register::
|
||||
Initialize Git config values so any scheduled maintenance will
|
||||
start running on this repository. This adds the repository to the
|
||||
`maintenance.repo` config variable in the current user's global
|
||||
config and enables some recommended configuration values for
|
||||
`maintenance.<task>.schedule`. The tasks that are enabled are safe
|
||||
for running in the background without disrupting foreground
|
||||
processes.
|
||||
+
|
||||
The `register` subcomand will also set the `maintenance.strategy` config
|
||||
value to `incremental`, if this value is not previously set. The
|
||||
`incremental` strategy uses the following schedule for each maintenance
|
||||
task:
|
||||
+
|
||||
--
|
||||
* `gc`: disabled.
|
||||
* `commit-graph`: hourly.
|
||||
* `prefetch`: hourly.
|
||||
* `loose-objects`: daily.
|
||||
* `incremental-repack`: daily.
|
||||
--
|
||||
+
|
||||
`git maintenance register` will also disable foreground maintenance by
|
||||
setting `maintenance.auto = false` in the current repository. This config
|
||||
setting will remain after a `git maintenance unregister` command.
|
||||
|
||||
run::
|
||||
Run one or more maintenance tasks. If one or more `--task` options
|
||||
are specified, then those tasks are run in that order. Otherwise,
|
||||
|
@ -36,6 +62,22 @@ run::
|
|||
config options are true. By default, only `maintenance.gc.enabled`
|
||||
is true.
|
||||
|
||||
start::
|
||||
Start running maintenance on the current repository. This performs
|
||||
the same config updates as the `register` subcommand, then updates
|
||||
the background scheduler to run `git maintenance run --scheduled`
|
||||
on an hourly basis.
|
||||
|
||||
stop::
|
||||
Halt the background maintenance schedule. The current repository
|
||||
is not removed from the list of maintained repositories, in case
|
||||
the background maintenance is restarted later.
|
||||
|
||||
unregister::
|
||||
Remove the current repository from background maintenance. This
|
||||
only removes the repository from the configured list. It does not
|
||||
stop the background maintenance processes from running.
|
||||
|
||||
TASKS
|
||||
-----
|
||||
|
||||
|
@ -47,6 +89,21 @@ commit-graph::
|
|||
`commit-graph-chain` file. They will be deleted by a later run based
|
||||
on the expiration delay.
|
||||
|
||||
prefetch::
|
||||
The `prefetch` task updates the object directory with the latest
|
||||
objects from all registered remotes. For each remote, a `git fetch`
|
||||
command is run. The refmap is custom to avoid updating local or remote
|
||||
branches (those in `refs/heads` or `refs/remotes`). Instead, the
|
||||
remote refs are stored in `refs/prefetch/<remote>/`. Also, tags are
|
||||
not updated.
|
||||
+
|
||||
This is done to avoid disrupting the remote-tracking branches. The end users
|
||||
expect these refs to stay unmoved unless they initiate a fetch. With prefetch
|
||||
task, however, the objects necessary to complete a later real fetch would
|
||||
already be obtained, so the real fetch would go faster. In the ideal case,
|
||||
it will just become an update to bunch of remote-tracking branches without
|
||||
any object transfer.
|
||||
|
||||
gc::
|
||||
Clean up unnecessary files and optimize the local repository. "GC"
|
||||
stands for "garbage collection," but this task performs many
|
||||
|
@ -55,6 +112,39 @@ gc::
|
|||
be disruptive in some situations, as it deletes stale data. See
|
||||
linkgit:git-gc[1] for more details on garbage collection in Git.
|
||||
|
||||
loose-objects::
|
||||
The `loose-objects` job cleans up loose objects and places them into
|
||||
pack-files. In order to prevent race conditions with concurrent Git
|
||||
commands, it follows a two-step process. First, it deletes any loose
|
||||
objects that already exist in a pack-file; concurrent Git processes
|
||||
will examine the pack-file for the object data instead of the loose
|
||||
object. Second, it creates a new pack-file (starting with "loose-")
|
||||
containing a batch of loose objects. The batch size is limited to 50
|
||||
thousand objects to prevent the job from taking too long on a
|
||||
repository with many loose objects. The `gc` task writes unreachable
|
||||
objects as loose objects to be cleaned up by a later step only if
|
||||
they are not re-added to a pack-file; for this reason it is not
|
||||
advisable to enable both the `loose-objects` and `gc` tasks at the
|
||||
same time.
|
||||
|
||||
incremental-repack::
|
||||
The `incremental-repack` job repacks the object directory
|
||||
using the `multi-pack-index` feature. In order to prevent race
|
||||
conditions with concurrent Git commands, it follows a two-step
|
||||
process. First, it calls `git multi-pack-index expire` to delete
|
||||
pack-files unreferenced by the `multi-pack-index` file. Second, it
|
||||
calls `git multi-pack-index repack` to select several small
|
||||
pack-files and repack them into a bigger one, and then update the
|
||||
`multi-pack-index` entries that refer to the small pack-files to
|
||||
refer to the new pack-file. This prepares those small pack-files
|
||||
for deletion upon the next run of `git multi-pack-index expire`.
|
||||
The selection of the small pack-files is such that the expected
|
||||
size of the big pack-file is at least the batch size; see the
|
||||
`--batch-size` option for the `repack` subcommand in
|
||||
linkgit:git-multi-pack-index[1]. The default batch-size is zero,
|
||||
which is a special case that attempts to repack all pack-files
|
||||
into a single pack-file.
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
--auto::
|
||||
|
@ -62,7 +152,18 @@ OPTIONS
|
|||
only if certain thresholds are met. For example, the `gc` task
|
||||
runs when the number of loose objects exceeds the number stored
|
||||
in the `gc.auto` config setting, or when the number of pack-files
|
||||
exceeds the `gc.autoPackLimit` config setting.
|
||||
exceeds the `gc.autoPackLimit` config setting. Not compatible with
|
||||
the `--schedule` option.
|
||||
|
||||
--schedule::
|
||||
When combined with the `run` subcommand, run maintenance tasks
|
||||
only if certain time conditions are met, as specified by the
|
||||
`maintenance.<task>.schedule` config value for each `<task>`.
|
||||
This config value specifies a number of seconds since the last
|
||||
time that task ran, according to the `maintenance.<task>.lastRun`
|
||||
config value. The tasks that are tested are those provided by
|
||||
the `--task=<task>` option(s) or those with
|
||||
`maintenance.<task>.enabled` set to true.
|
||||
|
||||
--quiet::
|
||||
Do not report progress or other information over `stderr`.
|
||||
|
@ -74,6 +175,166 @@ OPTIONS
|
|||
`maintenance.<task>.enabled` configured as `true` are considered.
|
||||
See the 'TASKS' section for the list of accepted `<task>` values.
|
||||
|
||||
|
||||
TROUBLESHOOTING
|
||||
---------------
|
||||
The `git maintenance` command is designed to simplify the repository
|
||||
maintenance patterns while minimizing user wait time during Git commands.
|
||||
A variety of configuration options are available to allow customizing this
|
||||
process. The default maintenance options focus on operations that complete
|
||||
quickly, even on large repositories.
|
||||
|
||||
Users may find some cases where scheduled maintenance tasks do not run as
|
||||
frequently as intended. Each `git maintenance run` command takes a lock on
|
||||
the repository's object database, and this prevents other concurrent
|
||||
`git maintenance run` commands from running on the same repository. Without
|
||||
this safeguard, competing processes could leave the repository in an
|
||||
unpredictable state.
|
||||
|
||||
The background maintenance schedule runs `git maintenance run` processes
|
||||
on an hourly basis. Each run executes the "hourly" tasks. At midnight,
|
||||
that process also executes the "daily" tasks. At midnight on the first day
|
||||
of the week, that process also executes the "weekly" tasks. A single
|
||||
process iterates over each registered repository, performing the scheduled
|
||||
tasks for that frequency. Depending on the number of registered
|
||||
repositories and their sizes, this process may take longer than an hour.
|
||||
In this case, multiple `git maintenance run` commands may run on the same
|
||||
repository at the same time, colliding on the object database lock. This
|
||||
results in one of the two tasks not running.
|
||||
|
||||
If you find that some maintenance windows are taking longer than one hour
|
||||
to complete, then consider reducing the complexity of your maintenance
|
||||
tasks. For example, the `gc` task is much slower than the
|
||||
`incremental-repack` task. However, this comes at a cost of a slightly
|
||||
larger object database. Consider moving more expensive tasks to be run
|
||||
less frequently.
|
||||
|
||||
Expert users may consider scheduling their own maintenance tasks using a
|
||||
different schedule than is available through `git maintenance start` and
|
||||
Git configuration options. These users should be aware of the object
|
||||
database lock and how concurrent `git maintenance run` commands behave.
|
||||
Further, the `git gc` command should not be combined with
|
||||
`git maintenance run` commands. `git gc` modifies the object database
|
||||
but does not take the lock in the same way as `git maintenance run`. If
|
||||
possible, use `git maintenance run --task=gc` instead of `git gc`.
|
||||
|
||||
The following sections describe the mechanisms put in place to run
|
||||
background maintenance by `git maintenance start` and how to customize
|
||||
them.
|
||||
|
||||
BACKGROUND MAINTENANCE ON POSIX SYSTEMS
|
||||
---------------------------------------
|
||||
|
||||
The standard mechanism for scheduling background tasks on POSIX systems
|
||||
is cron(8). This tool executes commands based on a given schedule. The
|
||||
current list of user-scheduled tasks can be found by running `crontab -l`.
|
||||
The schedule written by `git maintenance start` is similar to this:
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
# BEGIN GIT MAINTENANCE SCHEDULE
|
||||
# The following schedule was created by Git
|
||||
# Any edits made in this region might be
|
||||
# replaced in the future by a Git command.
|
||||
|
||||
0 1-23 * * * "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly
|
||||
0 0 * * 1-6 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=daily
|
||||
0 0 * * 0 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly
|
||||
|
||||
# END GIT MAINTENANCE SCHEDULE
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
The comments are used as a region to mark the schedule as written by Git.
|
||||
Any modifications within this region will be completely deleted by
|
||||
`git maintenance stop` or overwritten by `git maintenance start`.
|
||||
|
||||
The `crontab` entry specifies the full path of the `git` executable to
|
||||
ensure that the executed `git` command is the same one with which
|
||||
`git maintenance start` was issued independent of `PATH`. If the same user
|
||||
runs `git maintenance start` with multiple Git executables, then only the
|
||||
latest executable is used.
|
||||
|
||||
These commands use `git for-each-repo --config=maintenance.repo` to run
|
||||
`git maintenance run --schedule=<frequency>` on each repository listed in
|
||||
the multi-valued `maintenance.repo` config option. These are typically
|
||||
loaded from the user-specific global config. The `git maintenance` process
|
||||
then determines which maintenance tasks are configured to run on each
|
||||
repository with each `<frequency>` using the `maintenance.<task>.schedule`
|
||||
config options. These values are loaded from the global or repository
|
||||
config values.
|
||||
|
||||
If the config values are insufficient to achieve your desired background
|
||||
maintenance schedule, then you can create your own schedule. If you run
|
||||
`crontab -e`, then an editor will load with your user-specific `cron`
|
||||
schedule. In that editor, you can add your own schedule lines. You could
|
||||
start by adapting the default schedule listed earlier, or you could read
|
||||
the crontab(5) documentation for advanced scheduling techniques. Please
|
||||
do use the full path and `--exec-path` techniques from the default
|
||||
schedule to ensure you are executing the correct binaries in your
|
||||
schedule.
|
||||
|
||||
|
||||
BACKGROUND MAINTENANCE ON MACOS SYSTEMS
|
||||
---------------------------------------
|
||||
|
||||
While macOS technically supports `cron`, using `crontab -e` requires
|
||||
elevated privileges and the executed process does not have a full user
|
||||
context. Without a full user context, Git and its credential helpers
|
||||
cannot access stored credentials, so some maintenance tasks are not
|
||||
functional.
|
||||
|
||||
Instead, `git maintenance start` interacts with the `launchctl` tool,
|
||||
which is the recommended way to schedule timed jobs in macOS. Scheduling
|
||||
maintenance through `git maintenance (start|stop)` requires some
|
||||
`launchctl` features available only in macOS 10.11 or later.
|
||||
|
||||
Your user-specific scheduled tasks are stored as XML-formatted `.plist`
|
||||
files in `~/Library/LaunchAgents/`. You can see the currently-registered
|
||||
tasks using the following command:
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
$ ls ~/Library/LaunchAgents/org.git-scm.git*
|
||||
org.git-scm.git.daily.plist
|
||||
org.git-scm.git.hourly.plist
|
||||
org.git-scm.git.weekly.plist
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
One task is registered for each `--schedule=<frequency>` option. To
|
||||
inspect how the XML format describes each schedule, open one of these
|
||||
`.plist` files in an editor and inspect the `<array>` element following
|
||||
the `<key>StartCalendarInterval</key>` element.
|
||||
|
||||
`git maintenance start` will overwrite these files and register the
|
||||
tasks again with `launchctl`, so any customizations should be done by
|
||||
creating your own `.plist` files with distinct names. Similarly, the
|
||||
`git maintenance stop` command will unregister the tasks with `launchctl`
|
||||
and delete the `.plist` files.
|
||||
|
||||
To create more advanced customizations to your background tasks, see
|
||||
launchctl.plist(5) for more information.
|
||||
|
||||
|
||||
BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS
|
||||
-----------------------------------------
|
||||
|
||||
Windows does not support `cron` and instead has its own system for
|
||||
scheduling background tasks. The `git maintenance start` command uses
|
||||
the `schtasks` command to submit tasks to this system. You can inspect
|
||||
all background tasks using the Task Scheduler application. The tasks
|
||||
added by Git have names of the form `Git Maintenance (<frequency>)`.
|
||||
The Task Scheduler GUI has ways to inspect these tasks, but you can also
|
||||
export the tasks to XML files and view the details there.
|
||||
|
||||
Note that since Git is a console application, these background tasks
|
||||
create a console window visible to the current user. This can be changed
|
||||
manually by selecting the "Run whether user is logged in or not" option
|
||||
in Task Scheduler. This change requires a password input, which is why
|
||||
`git maintenance start` does not select it by default.
|
||||
|
||||
If you want to customize the background tasks, please rename the tasks
|
||||
so future calls to `git maintenance (start|stop)` do not overwrite your
|
||||
custom tasks.
|
||||
|
||||
|
||||
GIT
|
||||
---
|
||||
Part of the linkgit:git[1] suite
|
||||
|
|
2
Makefile
2
Makefile
|
@ -695,6 +695,7 @@ TEST_BUILTINS_OBJS += test-bloom.o
|
|||
TEST_BUILTINS_OBJS += test-chmtime.o
|
||||
TEST_BUILTINS_OBJS += test-cmp.o
|
||||
TEST_BUILTINS_OBJS += test-config.o
|
||||
TEST_BUILTINS_OBJS += test-crontab.o
|
||||
TEST_BUILTINS_OBJS += test-ctype.o
|
||||
TEST_BUILTINS_OBJS += test-date.o
|
||||
TEST_BUILTINS_OBJS += test-delta.o
|
||||
|
@ -1096,6 +1097,7 @@ BUILTIN_OBJS += builtin/fetch-pack.o
|
|||
BUILTIN_OBJS += builtin/fetch.o
|
||||
BUILTIN_OBJS += builtin/fmt-merge-msg.o
|
||||
BUILTIN_OBJS += builtin/for-each-ref.o
|
||||
BUILTIN_OBJS += builtin/for-each-repo.o
|
||||
BUILTIN_OBJS += builtin/fsck.o
|
||||
BUILTIN_OBJS += builtin/gc.o
|
||||
BUILTIN_OBJS += builtin/get-tar-commit-id.o
|
||||
|
|
|
@ -155,6 +155,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix);
|
|||
int cmd_fetch_pack(int argc, const char **argv, const char *prefix);
|
||||
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
|
||||
int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
|
||||
int cmd_for_each_repo(int argc, const char **argv, const char *prefix);
|
||||
int cmd_format_patch(int argc, const char **argv, const char *prefix);
|
||||
int cmd_fsck(int argc, const char **argv, const char *prefix);
|
||||
int cmd_gc(int argc, const char **argv, const char *prefix);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
#include "cache.h"
|
||||
#include "config.h"
|
||||
#include "builtin.h"
|
||||
#include "parse-options.h"
|
||||
#include "run-command.h"
|
||||
#include "string-list.h"
|
||||
|
||||
static const char * const for_each_repo_usage[] = {
|
||||
N_("git for-each-repo --config=<config> <command-args>"),
|
||||
NULL
|
||||
};
|
||||
|
||||
static int run_command_on_repo(const char *path,
|
||||
void *cbdata)
|
||||
{
|
||||
int i;
|
||||
struct child_process child = CHILD_PROCESS_INIT;
|
||||
struct strvec *args = (struct strvec *)cbdata;
|
||||
|
||||
child.git_cmd = 1;
|
||||
strvec_pushl(&child.args, "-C", path, NULL);
|
||||
|
||||
for (i = 0; i < args->nr; i++)
|
||||
strvec_push(&child.args, args->v[i]);
|
||||
|
||||
return run_command(&child);
|
||||
}
|
||||
|
||||
int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
static const char *config_key = NULL;
|
||||
int i, result = 0;
|
||||
const struct string_list *values;
|
||||
struct strvec args = STRVEC_INIT;
|
||||
|
||||
const struct option options[] = {
|
||||
OPT_STRING(0, "config", &config_key, N_("config"),
|
||||
N_("config key storing a list of repository paths")),
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
argc = parse_options(argc, argv, prefix, options, for_each_repo_usage,
|
||||
PARSE_OPT_STOP_AT_NON_OPTION);
|
||||
|
||||
if (!config_key)
|
||||
die(_("missing --config=<config>"));
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
strvec_push(&args, argv[i]);
|
||||
|
||||
values = repo_config_get_value_multi(the_repository,
|
||||
config_key);
|
||||
|
||||
for (i = 0; !result && i < values->nr; i++)
|
||||
result = run_command_on_repo(values->items[i].string, &args);
|
||||
|
||||
return result;
|
||||
}
|
974
builtin/gc.c
974
builtin/gc.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -94,6 +94,7 @@ git-fetch-pack synchingrepositories
|
|||
git-filter-branch ancillarymanipulators
|
||||
git-fmt-merge-msg purehelpers
|
||||
git-for-each-ref plumbinginterrogators
|
||||
git-for-each-repo plumbinginterrogators
|
||||
git-format-patch mainporcelain
|
||||
git-fsck ancillaryinterrogators complete
|
||||
git-gc mainporcelain
|
||||
|
|
1
git.c
1
git.c
|
@ -585,6 +585,7 @@ static struct cmd_struct commands[] = {
|
|||
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },
|
||||
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
|
||||
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
|
||||
{ "for-each-repo", cmd_for_each_repo, RUN_SETUP_GENTLY },
|
||||
{ "format-patch", cmd_format_patch, RUN_SETUP },
|
||||
{ "fsck", cmd_fsck, RUN_SETUP | BLOCK_ON_GVFS_REPO},
|
||||
{ "fsck-objects", cmd_fsck, RUN_SETUP },
|
||||
|
|
21
midx.c
21
midx.c
|
@ -10,6 +10,7 @@
|
|||
#include "progress.h"
|
||||
#include "trace2.h"
|
||||
#include "run-command.h"
|
||||
#include "repository.h"
|
||||
|
||||
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
|
||||
#define MIDX_VERSION 1
|
||||
|
@ -398,15 +399,9 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
|
|||
{
|
||||
struct multi_pack_index *m;
|
||||
struct multi_pack_index *m_search;
|
||||
int config_value;
|
||||
static int env_value = -1;
|
||||
|
||||
if (env_value < 0)
|
||||
env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
|
||||
|
||||
if (!env_value &&
|
||||
(repo_config_get_bool(r, "core.multipackindex", &config_value) ||
|
||||
!config_value))
|
||||
prepare_repo_settings(r);
|
||||
if (!r->settings.core_multi_pack_index)
|
||||
return 0;
|
||||
|
||||
for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
|
||||
|
@ -850,7 +845,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
|
|||
|
||||
packs.pack_paths_checked = 0;
|
||||
if (flags & MIDX_PROGRESS)
|
||||
packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0);
|
||||
packs.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0);
|
||||
else
|
||||
packs.progress = NULL;
|
||||
|
||||
|
@ -987,7 +982,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
|
|||
}
|
||||
|
||||
if (flags & MIDX_PROGRESS)
|
||||
progress = start_progress(_("Writing chunks to multi-pack-index"),
|
||||
progress = start_delayed_progress(_("Writing chunks to multi-pack-index"),
|
||||
num_chunks);
|
||||
for (i = 0; i < num_chunks; i++) {
|
||||
if (written != chunk_offsets[i])
|
||||
|
@ -1129,7 +1124,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
|
|||
}
|
||||
|
||||
if (flags & MIDX_PROGRESS)
|
||||
progress = start_progress(_("Looking for referenced packfiles"),
|
||||
progress = start_delayed_progress(_("Looking for referenced packfiles"),
|
||||
m->num_packs);
|
||||
for (i = 0; i < m->num_packs; i++) {
|
||||
if (prepare_midx_pack(r, m, i))
|
||||
|
@ -1250,7 +1245,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
|
|||
count = xcalloc(m->num_packs, sizeof(uint32_t));
|
||||
|
||||
if (flags & MIDX_PROGRESS)
|
||||
progress = start_progress(_("Counting referenced objects"),
|
||||
progress = start_delayed_progress(_("Counting referenced objects"),
|
||||
m->num_objects);
|
||||
for (i = 0; i < m->num_objects; i++) {
|
||||
int pack_int_id = nth_midxed_pack_int_id(m, i);
|
||||
|
@ -1260,7 +1255,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
|
|||
stop_progress(&progress);
|
||||
|
||||
if (flags & MIDX_PROGRESS)
|
||||
progress = start_progress(_("Finding and deleting unreferenced packfiles"),
|
||||
progress = start_delayed_progress(_("Finding and deleting unreferenced packfiles"),
|
||||
m->num_packs);
|
||||
for (i = 0; i < m->num_packs; i++) {
|
||||
char *pack_name;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "cache.h"
|
||||
#include "config.h"
|
||||
#include "repository.h"
|
||||
#include "midx.h"
|
||||
|
||||
#define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0)
|
||||
|
||||
|
@ -52,6 +53,11 @@ void prepare_repo_settings(struct repository *r)
|
|||
r->settings.pack_use_sparse = value;
|
||||
UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1);
|
||||
|
||||
value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
|
||||
if (value || !repo_config_get_bool(r, "core.multipackindex", &value))
|
||||
r->settings.core_multi_pack_index = value;
|
||||
UPDATE_DEFAULT_BOOL(r->settings.core_multi_pack_index, 1);
|
||||
|
||||
if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) {
|
||||
UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
|
||||
UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
|
||||
|
|
|
@ -39,6 +39,8 @@ struct repo_settings {
|
|||
|
||||
int pack_use_sparse;
|
||||
enum fetch_negotiation_setting fetch_negotiation_algorithm;
|
||||
|
||||
int core_multi_pack_index;
|
||||
};
|
||||
|
||||
struct repository {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "strbuf.h"
|
||||
#include "string-list.h"
|
||||
#include "quote.h"
|
||||
#include "config.h"
|
||||
|
||||
void child_process_init(struct child_process *child)
|
||||
{
|
||||
|
@ -1950,8 +1951,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
|
|||
|
||||
int run_auto_maintenance(int quiet)
|
||||
{
|
||||
int enabled;
|
||||
struct child_process maint = CHILD_PROCESS_INIT;
|
||||
|
||||
if (!git_config_get_bool("maintenance.auto", &enabled) &&
|
||||
!enabled)
|
||||
return 0;
|
||||
|
||||
maint.git_cmd = 1;
|
||||
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
|
||||
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "test-tool.h"
|
||||
#include "cache.h"
|
||||
|
||||
/*
|
||||
* Usage: test-tool cron <file> [-l]
|
||||
*
|
||||
* If -l is specified, then write the contents of <file> to stdout.
|
||||
* Otherwise, write from stdin into <file>.
|
||||
*/
|
||||
int cmd__crontab(int argc, const char **argv)
|
||||
{
|
||||
int a;
|
||||
FILE *from, *to;
|
||||
|
||||
if (argc == 3 && !strcmp(argv[2], "-l")) {
|
||||
from = fopen(argv[1], "r");
|
||||
if (!from)
|
||||
return 0;
|
||||
to = stdout;
|
||||
} else if (argc == 2) {
|
||||
from = stdin;
|
||||
to = fopen(argv[1], "w");
|
||||
} else
|
||||
return error("unknown arguments");
|
||||
|
||||
while ((a = fgetc(from)) != EOF)
|
||||
fputc(a, to);
|
||||
|
||||
if (argc == 3)
|
||||
fclose(from);
|
||||
else
|
||||
fclose(to);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -19,6 +19,7 @@ static struct test_cmd cmds[] = {
|
|||
{ "chmtime", cmd__chmtime },
|
||||
{ "cmp", cmd__cmp },
|
||||
{ "config", cmd__config },
|
||||
{ "crontab", cmd__crontab },
|
||||
{ "ctype", cmd__ctype },
|
||||
{ "date", cmd__date },
|
||||
{ "delta", cmd__delta },
|
||||
|
|
|
@ -9,6 +9,7 @@ int cmd__bloom(int argc, const char **argv);
|
|||
int cmd__chmtime(int argc, const char **argv);
|
||||
int cmd__cmp(int argc, const char **argv);
|
||||
int cmd__config(int argc, const char **argv);
|
||||
int cmd__crontab(int argc, const char **argv);
|
||||
int cmd__ctype(int argc, const char **argv);
|
||||
int cmd__date(int argc, const char **argv);
|
||||
int cmd__delta(int argc, const char **argv);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='git for-each-repo builtin'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'run based on configured value' '
|
||||
git init one &&
|
||||
git init two &&
|
||||
git init three &&
|
||||
git -C two commit --allow-empty -m "DID NOT RUN" &&
|
||||
git config run.key "$TRASH_DIRECTORY/one" &&
|
||||
git config --add run.key "$TRASH_DIRECTORY/three" &&
|
||||
git for-each-repo --config=run.key commit --allow-empty -m "ran" &&
|
||||
git -C one log -1 --pretty=format:%s >message &&
|
||||
grep ran message &&
|
||||
git -C two log -1 --pretty=format:%s >message &&
|
||||
! grep ran message &&
|
||||
git -C three log -1 --pretty=format:%s >message &&
|
||||
grep ran message &&
|
||||
git for-each-repo --config=run.key -- commit --allow-empty -m "ran again" &&
|
||||
git -C one log -1 --pretty=format:%s >message &&
|
||||
grep again message &&
|
||||
git -C two log -1 --pretty=format:%s >message &&
|
||||
! grep again message &&
|
||||
git -C three log -1 --pretty=format:%s >message &&
|
||||
grep again message
|
||||
'
|
||||
|
||||
test_done
|
|
@ -3,6 +3,7 @@
|
|||
test_description='multi-pack-indexes'
|
||||
. ./test-lib.sh
|
||||
|
||||
GIT_TEST_MULTI_PACK_INDEX=0
|
||||
objdir=.git/objects
|
||||
|
||||
HASH_LEN=$(test_oid rawsz)
|
||||
|
@ -173,12 +174,12 @@ test_expect_success 'write progress off for redirected stderr' '
|
|||
'
|
||||
|
||||
test_expect_success 'write force progress on for stderr' '
|
||||
git multi-pack-index --object-dir=$objdir --progress write 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress write 2>err &&
|
||||
test_file_not_empty err
|
||||
'
|
||||
|
||||
test_expect_success 'write with the --no-progress option' '
|
||||
git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
|
||||
test_line_count = 0 err
|
||||
'
|
||||
|
||||
|
@ -368,17 +369,17 @@ test_expect_success 'git-fsck incorrect offset' '
|
|||
'
|
||||
|
||||
test_expect_success 'repack progress off for redirected stderr' '
|
||||
git multi-pack-index --object-dir=$objdir repack 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
|
||||
test_line_count = 0 err
|
||||
'
|
||||
|
||||
test_expect_success 'repack force progress on for stderr' '
|
||||
git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
|
||||
test_file_not_empty err
|
||||
'
|
||||
|
||||
test_expect_success 'repack with the --no-progress option' '
|
||||
git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
|
||||
test_line_count = 0 err
|
||||
'
|
||||
|
||||
|
@ -562,7 +563,7 @@ test_expect_success 'expire progress off for redirected stderr' '
|
|||
test_expect_success 'expire force progress on for stderr' '
|
||||
(
|
||||
cd dup &&
|
||||
git multi-pack-index --progress expire 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --progress expire 2>err &&
|
||||
test_file_not_empty err
|
||||
)
|
||||
'
|
||||
|
@ -570,7 +571,7 @@ test_expect_success 'expire force progress on for stderr' '
|
|||
test_expect_success 'expire with the --no-progress option' '
|
||||
(
|
||||
cd dup &&
|
||||
git multi-pack-index --no-progress expire 2>err &&
|
||||
GIT_PROGRESS_DELAY=0 git multi-pack-index --no-progress expire 2>err &&
|
||||
test_line_count = 0 err
|
||||
)
|
||||
'
|
||||
|
|
|
@ -5,10 +5,24 @@ test_description='git maintenance builtin'
|
|||
. ./test-lib.sh
|
||||
|
||||
GIT_TEST_COMMIT_GRAPH=0
|
||||
GIT_TEST_MULTI_PACK_INDEX=0
|
||||
|
||||
test_lazy_prereq XMLLINT '
|
||||
xmllint --version
|
||||
'
|
||||
|
||||
test_xmllint () {
|
||||
if test_have_prereq XMLLINT
|
||||
then
|
||||
xmllint --noout "$@"
|
||||
else
|
||||
true
|
||||
fi
|
||||
}
|
||||
|
||||
test_expect_success 'help text' '
|
||||
test_expect_code 129 git maintenance -h 2>err &&
|
||||
test_i18ngrep "usage: git maintenance run" err &&
|
||||
test_i18ngrep "usage: git maintenance <subcommand>" err &&
|
||||
test_expect_code 128 git maintenance barf 2>err &&
|
||||
test_i18ngrep "invalid subcommand: barf" err &&
|
||||
test_expect_code 129 git maintenance 2>err &&
|
||||
|
@ -27,6 +41,19 @@ test_expect_success 'run [--auto|--quiet]' '
|
|||
test_subcommand git gc --no-quiet <run-no-quiet.txt
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.auto config option' '
|
||||
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
|
||||
test_subcommand git maintenance run --auto --quiet <default &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/true" \
|
||||
git -c maintenance.auto=true \
|
||||
commit --quiet --allow-empty -m 2 &&
|
||||
test_subcommand git maintenance run --auto --quiet <true &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/false" \
|
||||
git -c maintenance.auto=false \
|
||||
commit --quiet --allow-empty -m 3 &&
|
||||
test_subcommand ! git maintenance run --auto --quiet <false
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.<task>.enabled' '
|
||||
git config maintenance.gc.enabled false &&
|
||||
git config maintenance.commit-graph.enabled true &&
|
||||
|
@ -62,4 +89,416 @@ test_expect_success 'run --task duplicate' '
|
|||
test_i18ngrep "cannot be selected multiple times" err
|
||||
'
|
||||
|
||||
test_expect_success 'run --task=prefetch with no remotes' '
|
||||
git maintenance run --task=prefetch 2>err &&
|
||||
test_must_be_empty err
|
||||
'
|
||||
|
||||
test_expect_success 'prefetch multiple remotes' '
|
||||
git clone . clone1 &&
|
||||
git clone . clone2 &&
|
||||
git remote add remote1 "file://$(pwd)/clone1" &&
|
||||
git remote add remote2 "file://$(pwd)/clone2" &&
|
||||
git -C clone1 switch -c one &&
|
||||
git -C clone2 switch -c two &&
|
||||
test_commit -C clone1 one &&
|
||||
test_commit -C clone2 two &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
|
||||
fetchargs="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" &&
|
||||
test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* <run-prefetch.txt &&
|
||||
test_subcommand git fetch remote2 $fetchargs +refs/heads/\\*:refs/prefetch/remote2/\\* <run-prefetch.txt &&
|
||||
test_path_is_missing .git/refs/remotes &&
|
||||
git log prefetch/remote1/one &&
|
||||
git log prefetch/remote2/two &&
|
||||
git fetch --all &&
|
||||
test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one &&
|
||||
test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two
|
||||
'
|
||||
|
||||
test_expect_success 'loose-objects task' '
|
||||
# Repack everything so we know the state of the object dir
|
||||
git repack -adk &&
|
||||
|
||||
# Hack to stop maintenance from running during "git commit"
|
||||
echo in use >.git/objects/maintenance.lock &&
|
||||
|
||||
# Assuming that "git commit" creates at least one loose object
|
||||
test_commit create-loose-object &&
|
||||
rm .git/objects/maintenance.lock &&
|
||||
|
||||
ls .git/objects >obj-dir-before &&
|
||||
test_file_not_empty obj-dir-before &&
|
||||
ls .git/objects/pack/*.pack >packs-before &&
|
||||
test_line_count = 1 packs-before &&
|
||||
|
||||
# The first run creates a pack-file
|
||||
# but does not delete loose objects.
|
||||
git maintenance run --task=loose-objects &&
|
||||
ls .git/objects >obj-dir-between &&
|
||||
test_cmp obj-dir-before obj-dir-between &&
|
||||
ls .git/objects/pack/*.pack >packs-between &&
|
||||
test_line_count = 2 packs-between &&
|
||||
ls .git/objects/pack/loose-*.pack >loose-packs &&
|
||||
test_line_count = 1 loose-packs &&
|
||||
|
||||
# The second run deletes loose objects
|
||||
# but does not create a pack-file.
|
||||
git maintenance run --task=loose-objects &&
|
||||
ls .git/objects >obj-dir-after &&
|
||||
cat >expect <<-\EOF &&
|
||||
info
|
||||
pack
|
||||
EOF
|
||||
test_cmp expect obj-dir-after &&
|
||||
ls .git/objects/pack/*.pack >packs-after &&
|
||||
test_cmp packs-between packs-after
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.loose-objects.auto' '
|
||||
git repack -adk &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
|
||||
git -c maintenance.loose-objects.auto=1 maintenance \
|
||||
run --auto --task=loose-objects 2>/dev/null &&
|
||||
test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
|
||||
printf data-A | git hash-object -t blob --stdin -w &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
|
||||
git -c maintenance.loose-objects.auto=2 \
|
||||
maintenance run --auto --task=loose-objects 2>/dev/null &&
|
||||
test_subcommand ! git prune-packed --quiet <trace-loA &&
|
||||
printf data-B | git hash-object -t blob --stdin -w &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
|
||||
git -c maintenance.loose-objects.auto=2 \
|
||||
maintenance run --auto --task=loose-objects 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <trace-loB &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
|
||||
git -c maintenance.loose-objects.auto=2 \
|
||||
maintenance run --auto --task=loose-objects 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <trace-loC
|
||||
'
|
||||
|
||||
test_expect_success 'incremental-repack task' '
|
||||
packDir=.git/objects/pack &&
|
||||
for i in $(test_seq 1 5)
|
||||
do
|
||||
test_commit $i || return 1
|
||||
done &&
|
||||
|
||||
# Create three disjoint pack-files with size BIG, small, small.
|
||||
echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
|
||||
test_tick &&
|
||||
git pack-objects --revs $packDir/test-2 <<-\EOF &&
|
||||
HEAD~1
|
||||
^HEAD~2
|
||||
EOF
|
||||
test_tick &&
|
||||
git pack-objects --revs $packDir/test-3 <<-\EOF &&
|
||||
HEAD
|
||||
^HEAD~1
|
||||
EOF
|
||||
rm -f $packDir/pack-* &&
|
||||
rm -f $packDir/loose-* &&
|
||||
ls $packDir/*.pack >packs-before &&
|
||||
test_line_count = 3 packs-before &&
|
||||
|
||||
# the job repacks the two into a new pack, but does not
|
||||
# delete the old ones.
|
||||
git maintenance run --task=incremental-repack &&
|
||||
ls $packDir/*.pack >packs-between &&
|
||||
test_line_count = 4 packs-between &&
|
||||
|
||||
# the job deletes the two old packs, and does not write
|
||||
# a new one because the batch size is not high enough to
|
||||
# pack the largest pack-file.
|
||||
git maintenance run --task=incremental-repack &&
|
||||
ls .git/objects/pack/*.pack >packs-after &&
|
||||
test_line_count = 2 packs-after
|
||||
'
|
||||
|
||||
test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
|
||||
for i in $(test_seq 1 5)
|
||||
do
|
||||
test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
|
||||
return 1
|
||||
done &&
|
||||
git add big &&
|
||||
git commit -m "Add big file (1)" &&
|
||||
|
||||
# ensure any possible loose objects are in a pack-file
|
||||
git maintenance run --task=loose-objects &&
|
||||
|
||||
rm big &&
|
||||
for i in $(test_seq 6 10)
|
||||
do
|
||||
test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
|
||||
return 1
|
||||
done &&
|
||||
git add big &&
|
||||
git commit -m "Add big file (2)" &&
|
||||
|
||||
# ensure any possible loose objects are in a pack-file
|
||||
git maintenance run --task=loose-objects &&
|
||||
|
||||
# Now run the incremental-repack task and check the batch-size
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
|
||||
--task=incremental-repack 2>/dev/null &&
|
||||
test_subcommand git multi-pack-index repack \
|
||||
--no-progress --batch-size=2147483647 <run-2g.txt
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.incremental-repack.auto' '
|
||||
git repack -adk &&
|
||||
git config core.multiPackIndex true &&
|
||||
git multi-pack-index write &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
|
||||
-c maintenance.incremental-repack.auto=1 \
|
||||
maintenance run --auto --task=incremental-repack 2>/dev/null &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
|
||||
test_commit A &&
|
||||
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
|
||||
HEAD
|
||||
^HEAD~1
|
||||
EOF
|
||||
GIT_TRACE2_EVENT=$(pwd)/trace-A git \
|
||||
-c maintenance.incremental-repack.auto=2 \
|
||||
maintenance run --auto --task=incremental-repack 2>/dev/null &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
|
||||
test_commit B &&
|
||||
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
|
||||
HEAD
|
||||
^HEAD~1
|
||||
EOF
|
||||
GIT_TRACE2_EVENT=$(pwd)/trace-B git \
|
||||
-c maintenance.incremental-repack.auto=2 \
|
||||
maintenance run --auto --task=incremental-repack 2>/dev/null &&
|
||||
test_subcommand git multi-pack-index write --no-progress <trace-B
|
||||
'
|
||||
|
||||
test_expect_success '--auto and --schedule incompatible' '
|
||||
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
|
||||
test_i18ngrep "at most one" err
|
||||
'
|
||||
|
||||
test_expect_success 'invalid --schedule value' '
|
||||
test_must_fail git maintenance run --schedule=annually 2>err &&
|
||||
test_i18ngrep "unrecognized --schedule" err
|
||||
'
|
||||
|
||||
test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
|
||||
git config maintenance.loose-objects.enabled true &&
|
||||
git config maintenance.loose-objects.schedule hourly &&
|
||||
git config maintenance.commit-graph.enabled true &&
|
||||
git config maintenance.commit-graph.schedule daily &&
|
||||
git config maintenance.incremental-repack.enabled true &&
|
||||
git config maintenance.incremental-repack.schedule weekly &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
|
||||
git maintenance run --schedule=hourly 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <hourly.txt &&
|
||||
test_subcommand ! git commit-graph write --split --reachable \
|
||||
--no-progress <hourly.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
|
||||
git maintenance run --schedule=daily 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <daily.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <daily.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
|
||||
git maintenance run --schedule=weekly 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <weekly.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <weekly.txt &&
|
||||
test_subcommand git multi-pack-index write --no-progress <weekly.txt
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.strategy inheritance' '
|
||||
for task in commit-graph loose-objects incremental-repack
|
||||
do
|
||||
git config --unset maintenance.$task.schedule || return 1
|
||||
done &&
|
||||
|
||||
test_when_finished git config --unset maintenance.strategy &&
|
||||
git config maintenance.strategy incremental &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
|
||||
git maintenance run --schedule=hourly --quiet &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
|
||||
git maintenance run --schedule=daily --quiet &&
|
||||
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <incremental-hourly.txt &&
|
||||
test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress \
|
||||
<incremental-hourly.txt &&
|
||||
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <incremental-daily.txt &&
|
||||
test_subcommand git prune-packed --quiet <incremental-daily.txt &&
|
||||
test_subcommand git multi-pack-index write --no-progress \
|
||||
<incremental-daily.txt &&
|
||||
|
||||
# Modify defaults
|
||||
git config maintenance.commit-graph.schedule daily &&
|
||||
git config maintenance.loose-objects.schedule hourly &&
|
||||
git config maintenance.incremental-repack.enabled false &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
|
||||
git maintenance run --schedule=hourly --quiet &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
|
||||
git maintenance run --schedule=daily --quiet &&
|
||||
|
||||
test_subcommand ! git commit-graph write --split --reachable \
|
||||
--no-progress <modified-hourly.txt &&
|
||||
test_subcommand git prune-packed --quiet <modified-hourly.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress \
|
||||
<modified-hourly.txt &&
|
||||
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <modified-daily.txt &&
|
||||
test_subcommand git prune-packed --quiet <modified-daily.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress \
|
||||
<modified-daily.txt
|
||||
'
|
||||
|
||||
test_expect_success 'register and unregister' '
|
||||
test_when_finished git config --global --unset-all maintenance.repo &&
|
||||
git config --global --add maintenance.repo /existing1 &&
|
||||
git config --global --add maintenance.repo /existing2 &&
|
||||
git config --global --get-all maintenance.repo >before &&
|
||||
|
||||
git maintenance register &&
|
||||
test_cmp_config false maintenance.auto &&
|
||||
git config --global --get-all maintenance.repo >between &&
|
||||
cp before expect &&
|
||||
pwd >>expect &&
|
||||
test_cmp expect between &&
|
||||
|
||||
git maintenance unregister &&
|
||||
git config --global --get-all maintenance.repo >actual &&
|
||||
test_cmp before actual
|
||||
'
|
||||
|
||||
test_expect_success 'start from empty cron table' '
|
||||
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
|
||||
|
||||
# start registers the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt &&
|
||||
grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt &&
|
||||
grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt
|
||||
'
|
||||
|
||||
test_expect_success 'stop from existing schedule' '
|
||||
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
|
||||
|
||||
# stop does not unregister the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
# Operation is idempotent
|
||||
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
|
||||
test_must_be_empty cron.txt
|
||||
'
|
||||
|
||||
test_expect_success 'start preserves existing schedule' '
|
||||
echo "Important information!" >cron.txt &&
|
||||
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
|
||||
grep "Important information!" cron.txt
|
||||
'
|
||||
|
||||
test_expect_success 'start and stop macOS maintenance' '
|
||||
# ensure $HOME can be compared against hook arguments on all platforms
|
||||
pfx=$(cd "$HOME" && pwd) &&
|
||||
|
||||
write_script print-args <<-\EOF &&
|
||||
echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
|
||||
EOF
|
||||
|
||||
rm -f args &&
|
||||
GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start &&
|
||||
|
||||
# start registers the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
ls "$HOME/Library/LaunchAgents" >actual &&
|
||||
cat >expect <<-\EOF &&
|
||||
org.git-scm.git.daily.plist
|
||||
org.git-scm.git.hourly.plist
|
||||
org.git-scm.git.weekly.plist
|
||||
EOF
|
||||
test_cmp expect actual &&
|
||||
|
||||
rm -f expect &&
|
||||
for frequency in hourly daily weekly
|
||||
do
|
||||
PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
|
||||
test_xmllint "$PLIST" &&
|
||||
grep schedule=$frequency "$PLIST" &&
|
||||
echo "bootout gui/[UID] $PLIST" >>expect &&
|
||||
echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
|
||||
done &&
|
||||
test_cmp expect args &&
|
||||
|
||||
rm -f args &&
|
||||
GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
|
||||
|
||||
# stop does not unregister the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
|
||||
hourly daily weekly >expect &&
|
||||
test_cmp expect args &&
|
||||
ls "$HOME/Library/LaunchAgents" >actual &&
|
||||
test_line_count = 0 actual
|
||||
'
|
||||
|
||||
test_expect_success 'start and stop Windows maintenance' '
|
||||
write_script print-args <<-\EOF &&
|
||||
echo $* >>args
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
/xml) shift; xmlfile=$1; break ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
|
||||
EOF
|
||||
|
||||
rm -f args &&
|
||||
GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" GIT_TRACE2_PERF=1 git maintenance start &&
|
||||
|
||||
# start registers the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
for frequency in hourly daily weekly
|
||||
do
|
||||
grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
|
||||
file=$(ls schedule_$frequency*.xml) &&
|
||||
test_xmllint "$file" &&
|
||||
grep "encoding=.US-ASCII." "$file" || return 1
|
||||
done &&
|
||||
|
||||
rm -f args &&
|
||||
GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
|
||||
|
||||
# stop does not unregister the repo
|
||||
git config --get --global maintenance.repo "$(pwd)" &&
|
||||
|
||||
printf "/delete /tn Git Maintenance (%s) /f\n" \
|
||||
hourly daily weekly >expect &&
|
||||
test_cmp expect args
|
||||
'
|
||||
|
||||
test_expect_success 'register preserves existing strategy' '
|
||||
git config maintenance.strategy none &&
|
||||
git maintenance register &&
|
||||
test_config maintenance.strategy none &&
|
||||
git config --unset maintenance.strategy &&
|
||||
git maintenance register &&
|
||||
test_config maintenance.strategy incremental
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
|
@ -1729,3 +1729,10 @@ test_lazy_prereq SHA1 '
|
|||
test_lazy_prereq REBASE_P '
|
||||
test -z "$GIT_TEST_SKIP_REBASE_P"
|
||||
'
|
||||
|
||||
# Ensure that no test accidentally triggers a Git command
|
||||
# that runs the actual maintenance scheduler, affecting a user's
|
||||
# system permanently.
|
||||
# Tests that verify the scheduler integration must set this locally
|
||||
# to avoid errors.
|
||||
GIT_TEST_MAINT_SCHEDULER="none:exit 1"
|
||||
|
|
Загрузка…
Ссылка в новой задаче