Git fork

builtin/refs: add optimize subcommand

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>

authored by

Meet Soni and committed by
Junio C Hamano
ecc70a48 93efe34f

+27
+10
Documentation/git-refs.adoc
··· 18 18 [--contains[=<object>]] [--no-contains[=<object>]] 19 19 [(--exclude=<pattern>)...] [--start-after=<marker>] 20 20 [ --stdin | (<pattern>...)] 21 + git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>] 21 22 22 23 DESCRIPTION 23 24 ----------- ··· 37 38 List references in the repository with support for filtering, 38 39 formatting, and sorting. This subcommand is an alias for 39 40 linkgit:git-for-each-ref[1] and offers identical functionality. 41 + 42 + optimize:: 43 + Optimizes references to improve repository performance and reduce disk 44 + usage. This subcommand is an alias for linkgit:git-pack-refs[1] and 45 + offers identical functionality. 40 46 41 47 OPTIONS 42 48 ------- ··· 72 78 The following options are specific to 'git refs list': 73 79 74 80 include::for-each-ref-options.adoc[] 81 + 82 + The following options are specific to 'git refs optimize': 83 + 84 + include::pack-refs-options.adoc[] 75 85 76 86 KNOWN LIMITATIONS 77 87 -----------------
+17
builtin/refs.c
··· 2 2 #include "builtin.h" 3 3 #include "config.h" 4 4 #include "fsck.h" 5 + #include "pack-refs.h" 5 6 #include "parse-options.h" 6 7 #include "refs.h" 7 8 #include "strbuf.h" ··· 13 14 14 15 #define REFS_VERIFY_USAGE \ 15 16 N_("git refs verify [--strict] [--verbose]") 17 + 18 + #define REFS_OPTIMIZE_USAGE \ 19 + N_("git refs optimize " PACK_REFS_OPTS) 16 20 17 21 static int cmd_refs_migrate(int argc, const char **argv, const char *prefix, 18 22 struct repository *repo UNUSED) ··· 113 117 return for_each_ref_core(argc, argv, prefix, repo, refs_list_usage); 114 118 } 115 119 120 + static int cmd_refs_optimize(int argc, const char **argv, const char *prefix, 121 + struct repository *repo) 122 + { 123 + static char const * const refs_optimize_usage[] = { 124 + REFS_OPTIMIZE_USAGE, 125 + NULL 126 + }; 127 + 128 + return pack_refs_core(argc, argv, prefix, repo, refs_optimize_usage); 129 + } 130 + 116 131 int cmd_refs(int argc, 117 132 const char **argv, 118 133 const char *prefix, ··· 122 137 REFS_MIGRATE_USAGE, 123 138 REFS_VERIFY_USAGE, 124 139 "git refs list " COMMON_USAGE_FOR_EACH_REF, 140 + REFS_OPTIMIZE_USAGE, 125 141 NULL, 126 142 }; 127 143 parse_opt_subcommand_fn *fn = NULL; ··· 129 145 OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate), 130 146 OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify), 131 147 OPT_SUBCOMMAND("list", &fn, cmd_refs_list), 148 + OPT_SUBCOMMAND("optimize", &fn, cmd_refs_optimize), 132 149 OPT_END(), 133 150 }; 134 151