]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ds/maintenance-pack-refs'
authorJunio C Hamano <gitster@pobox.com>
Thu, 18 Feb 2021 01:21:42 +0000 (17:21 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Feb 2021 01:21:42 +0000 (17:21 -0800)
"git maintenance" tool learned a new "pack-refs" maintenance task.

* ds/maintenance-pack-refs:
  maintenance: incremental strategy runs pack-refs weekly
  maintenance: add pack-refs task

Documentation/config/maintenance.txt
Documentation/git-maintenance.txt
builtin/gc.c
t/t7900-maintenance.sh

index a5ead09e4bc2d1ca8834b332322315bcc72f352c..18f056213145e595d0a57792e716f29521122997 100644 (file)
@@ -15,8 +15,9 @@ maintenance.strategy::
 * `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.
+  task, but runs the `prefetch` and `commit-graph` tasks hourly, the
+  `loose-objects` and `incremental-repack` tasks daily, and the `pack-refs`
+  task weekly.
 
 maintenance.<task>.enabled::
        This boolean config option controls whether the maintenance task
index 3b432171d60826f50ad1251d7fa07f3d8f15cc1a..80ddd33ceba0dd5f47319ea8355fec7d35a74bef 100644 (file)
@@ -145,6 +145,12 @@ incremental-repack::
        which is a special case that attempts to repack all pack-files
        into a single pack-file.
 
+pack-refs::
+       The `pack-refs` task collects the loose reference files and
+       collects them into a single file. This speeds up operations that
+       need to iterate across many references. See linkgit:git-pack-refs[1]
+       for more information.
+
 OPTIONS
 -------
 --auto::
index 4c40594d660ebb21c2cf0223b21af88ea81f872c..6db9cb39e6797f9f3bea580916ec4e855e32cea3 100644 (file)
@@ -54,7 +54,6 @@ static const char *prune_worktrees_expire = "3.months.ago";
 static unsigned long big_pack_threshold;
 static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
 
-static struct strvec pack_refs_cmd = STRVEC_INIT;
 static struct strvec reflog = STRVEC_INIT;
 static struct strvec repack = STRVEC_INIT;
 static struct strvec prune = STRVEC_INIT;
@@ -163,6 +162,15 @@ static void gc_config(void)
        git_config(git_default_config, NULL);
 }
 
+struct maintenance_run_opts;
+static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts)
+{
+       struct strvec pack_refs_cmd = STRVEC_INIT;
+       strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
+
+       return run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD);
+}
+
 static int too_many_loose_objects(void)
 {
        /*
@@ -518,8 +526,8 @@ static void gc_before_repack(void)
        if (done++)
                return;
 
-       if (pack_refs && run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD))
-               die(FAILED_RUN, pack_refs_cmd.v[0]);
+       if (pack_refs && maintenance_task_pack_refs(NULL))
+               die(FAILED_RUN, "pack-refs");
 
        if (prune_reflogs && run_command_v_opt(reflog.v, RUN_GIT_CMD))
                die(FAILED_RUN, reflog.v[0]);
@@ -556,7 +564,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_gc_usage, builtin_gc_options);
 
-       strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
        strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
        strvec_pushl(&repack, "repack", "-d", "-l", NULL);
        strvec_pushl(&prune, "prune", "--expire", NULL);
@@ -1224,6 +1231,7 @@ enum maintenance_task_label {
        TASK_INCREMENTAL_REPACK,
        TASK_GC,
        TASK_COMMIT_GRAPH,
+       TASK_PACK_REFS,
 
        /* Leave as final value */
        TASK__COUNT
@@ -1255,6 +1263,11 @@ static struct maintenance_task tasks[] = {
                maintenance_task_commit_graph,
                should_write_commit_graph,
        },
+       [TASK_PACK_REFS] = {
+               "pack-refs",
+               maintenance_task_pack_refs,
+               NULL,
+       },
 };
 
 static int compare_tasks_by_selection(const void *a_, const void *b_)
@@ -1339,6 +1352,8 @@ static void initialize_maintenance_strategy(void)
                tasks[TASK_INCREMENTAL_REPACK].schedule = SCHEDULE_DAILY;
                tasks[TASK_LOOSE_OBJECTS].enabled = 1;
                tasks[TASK_LOOSE_OBJECTS].schedule = SCHEDULE_DAILY;
+               tasks[TASK_PACK_REFS].enabled = 1;
+               tasks[TASK_PACK_REFS].schedule = SCHEDULE_WEEKLY;
        }
 }
 
index 78ccf4b33f87c98d8b795ea7e31b6c29fc8837fb..286b18db3cc2d59e000f897d4a9fa3ad7ae46af7 100755 (executable)
@@ -343,6 +343,18 @@ test_expect_success 'maintenance.incremental-repack.auto' '
        test_subcommand git multi-pack-index write --no-progress <trace-B
 '
 
+test_expect_success 'pack-refs task' '
+       for n in $(test_seq 1 5)
+       do
+               git branch -f to-pack/$n HEAD || return 1
+       done &&
+       GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
+               git maintenance run --task=pack-refs &&
+       ls .git/refs/heads/ >after &&
+       test_must_be_empty after &&
+       test_subcommand git pack-refs --all --prune <pack-refs.txt
+'
+
 test_expect_success '--auto and --schedule incompatible' '
        test_must_fail git maintenance run --auto --schedule=daily 2>err &&
        test_i18ngrep "at most one" err
@@ -396,18 +408,32 @@ test_expect_success 'maintenance.strategy inheritance' '
                git maintenance run --schedule=hourly --quiet &&
        GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
                git maintenance run --schedule=daily --quiet &&
+       GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
+               git maintenance run --schedule=weekly --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 pack-refs --all --prune \
+               <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 &&
+       test_subcommand ! git pack-refs --all --prune \
+               <incremental-daily.txt &&
+
+       test_subcommand git commit-graph write --split --reachable \
+               --no-progress <incremental-weekly.txt &&
+       test_subcommand git prune-packed --quiet <incremental-weekly.txt &&
+       test_subcommand git multi-pack-index write --no-progress \
+               <incremental-weekly.txt &&
+       test_subcommand git pack-refs --all --prune \
+               <incremental-weekly.txt &&
 
        # Modify defaults
        git config maintenance.commit-graph.schedule daily &&