]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/refs: add optimize subcommand
authorMeet Soni <meetsoni3017@gmail.com>
Fri, 19 Sep 2025 08:26:45 +0000 (13:56 +0530)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2025 17:02:56 +0000 (10:02 -0700)
As part of the ongoing effort to consolidate reference handling,
introduce a new `optimize` subcommand. This command provides the same
functionality and exit-code behavior as `git pack-refs`, serving as its
modern replacement.

Implement `cmd_refs_optimize` by having it call the `pack_refs_core()`
helper function. This helper was factored out of the original
`cmd_pack_refs` in a preceding commit, allowing both commands to share
the same core logic as independent peers.

Add documentation for the new command. The man page leverages the shared
options file, created in a previous commit, by using the AsciiDoc
`include::` macro to ensure consistency with git-pack-refs(1).

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-refs.adoc
builtin/refs.c

index d462953fb5ee3a82ac8230b45a01861ecb6b93b2..e233f21eeb528af6ae49f1e3438b00246ca94e95 100644 (file)
@@ -18,6 +18,7 @@ git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
                   [--contains[=<object>]] [--no-contains[=<object>]]
                   [(--exclude=<pattern>)...] [--start-after=<marker>]
                   [ --stdin | (<pattern>...)]
+git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]
 
 DESCRIPTION
 -----------
@@ -38,6 +39,11 @@ list::
        formatting, and sorting. This subcommand is an alias for
        linkgit:git-for-each-ref[1] and offers identical functionality.
 
+optimize::
+       Optimizes references to improve repository performance and reduce disk
+       usage. This subcommand is an alias for linkgit:git-pack-refs[1] and
+       offers identical functionality.
+
 OPTIONS
 -------
 
@@ -73,6 +79,10 @@ The following options are specific to 'git refs list':
 
 include::for-each-ref-options.adoc[]
 
+The following options are specific to 'git refs optimize':
+
+include::pack-refs-options.adoc[]
+
 KNOWN LIMITATIONS
 -----------------
 
index 76224feba4d55a0ff2908df51eb2eb264f9fb962..785f476e4b9f9aacf05202e0e2512d87b6fbbbcd 100644 (file)
@@ -2,6 +2,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "fsck.h"
+#include "pack-refs.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "strbuf.h"
@@ -14,6 +15,9 @@
 #define REFS_VERIFY_USAGE \
        N_("git refs verify [--strict] [--verbose]")
 
+#define REFS_OPTIMIZE_USAGE \
+       N_("git refs optimize " PACK_REFS_OPTS)
+
 static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
                            struct repository *repo UNUSED)
 {
@@ -113,6 +117,17 @@ static int cmd_refs_list(int argc, const char **argv, const char *prefix,
        return for_each_ref_core(argc, argv, prefix, repo, refs_list_usage);
 }
 
+static int cmd_refs_optimize(int argc, const char **argv, const char *prefix,
+                            struct repository *repo)
+{
+       static char const * const refs_optimize_usage[] = {
+               REFS_OPTIMIZE_USAGE,
+               NULL
+       };
+
+       return pack_refs_core(argc, argv, prefix, repo, refs_optimize_usage);
+}
+
 int cmd_refs(int argc,
             const char **argv,
             const char *prefix,
@@ -122,6 +137,7 @@ int cmd_refs(int argc,
                REFS_MIGRATE_USAGE,
                REFS_VERIFY_USAGE,
                "git refs list " COMMON_USAGE_FOR_EACH_REF,
+               REFS_OPTIMIZE_USAGE,
                NULL,
        };
        parse_opt_subcommand_fn *fn = NULL;
@@ -129,6 +145,7 @@ int cmd_refs(int argc,
                OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate),
                OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify),
                OPT_SUBCOMMAND("list", &fn, cmd_refs_list),
+               OPT_SUBCOMMAND("optimize", &fn, cmd_refs_optimize),
                OPT_END(),
        };