Skip to content

Commit fe1611d

Browse files
inosmeetgitster
authored andcommitted
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>
1 parent 3a84742 commit fe1611d

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Documentation/git-refs.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
1919
[(--exclude=<pattern>)...] [--start-after=<marker>]
2020
[ --stdin | (<pattern>...)]
2121
git refs exists <ref>
22+
git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]
2223

2324
DESCRIPTION
2425
-----------
@@ -45,6 +46,11 @@ exists::
4546
failed with an error other than the reference being missing. This does
4647
not verify whether the reference resolves to an actual object.
4748

49+
optimize::
50+
Optimizes references to improve repository performance and reduce disk
51+
usage. This subcommand is an alias for linkgit:git-pack-refs[1] and
52+
offers identical functionality.
53+
4854
OPTIONS
4955
-------
5056

@@ -80,6 +86,10 @@ The following options are specific to 'git refs list':
8086

8187
include::for-each-ref-options.adoc[]
8288

89+
The following options are specific to 'git refs optimize':
90+
91+
include::pack-refs-options.adoc[]
92+
8393
KNOWN LIMITATIONS
8494
-----------------
8595

builtin/refs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "builtin.h"
33
#include "config.h"
44
#include "fsck.h"
5+
#include "pack-refs.h"
56
#include "parse-options.h"
67
#include "refs.h"
78
#include "strbuf.h"
@@ -18,6 +19,9 @@
1819
#define REFS_EXISTS_USAGE \
1920
N_("git refs exists <ref>")
2021

22+
#define REFS_OPTIMIZE_USAGE \
23+
N_("git refs optimize " PACK_REFS_OPTS)
24+
2125
static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
2226
struct repository *repo UNUSED)
2327
{
@@ -159,6 +163,17 @@ static int cmd_refs_exists(int argc, const char **argv, const char *prefix,
159163
return ret;
160164
}
161165

166+
static int cmd_refs_optimize(int argc, const char **argv, const char *prefix,
167+
struct repository *repo)
168+
{
169+
static char const * const refs_optimize_usage[] = {
170+
REFS_OPTIMIZE_USAGE,
171+
NULL
172+
};
173+
174+
return pack_refs_core(argc, argv, prefix, repo, refs_optimize_usage);
175+
}
176+
162177
int cmd_refs(int argc,
163178
const char **argv,
164179
const char *prefix,
@@ -169,6 +184,7 @@ int cmd_refs(int argc,
169184
REFS_VERIFY_USAGE,
170185
"git refs list " COMMON_USAGE_FOR_EACH_REF,
171186
REFS_EXISTS_USAGE,
187+
REFS_OPTIMIZE_USAGE,
172188
NULL,
173189
};
174190
parse_opt_subcommand_fn *fn = NULL;
@@ -177,6 +193,7 @@ int cmd_refs(int argc,
177193
OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify),
178194
OPT_SUBCOMMAND("list", &fn, cmd_refs_list),
179195
OPT_SUBCOMMAND("exists", &fn, cmd_refs_exists),
196+
OPT_SUBCOMMAND("optimize", &fn, cmd_refs_optimize),
180197
OPT_END(),
181198
};
182199

0 commit comments

Comments
 (0)