Skip to content

Commit ecc70a4

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 <[email protected]> Mentored-by: shejialuo <[email protected]> Signed-off-by: Meet Soni <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 93efe34 commit ecc70a4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/git-refs.adoc

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

2223
DESCRIPTION
2324
-----------
@@ -38,6 +39,11 @@ list::
3839
formatting, and sorting. This subcommand is an alias for
3940
linkgit:git-for-each-ref[1] and offers identical functionality.
4041

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.
46+
4147
OPTIONS
4248
-------
4349

@@ -73,6 +79,10 @@ The following options are specific to 'git refs list':
7379

7480
include::for-each-ref-options.adoc[]
7581

82+
The following options are specific to 'git refs optimize':
83+
84+
include::pack-refs-options.adoc[]
85+
7686
KNOWN LIMITATIONS
7787
-----------------
7888

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"
@@ -14,6 +15,9 @@
1415
#define REFS_VERIFY_USAGE \
1516
N_("git refs verify [--strict] [--verbose]")
1617

18+
#define REFS_OPTIMIZE_USAGE \
19+
N_("git refs optimize " PACK_REFS_OPTS)
20+
1721
static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
1822
struct repository *repo UNUSED)
1923
{
@@ -113,6 +117,17 @@ static int cmd_refs_list(int argc, const char **argv, const char *prefix,
113117
return for_each_ref_core(argc, argv, prefix, repo, refs_list_usage);
114118
}
115119

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+
116131
int cmd_refs(int argc,
117132
const char **argv,
118133
const char *prefix,
@@ -122,13 +137,15 @@ int cmd_refs(int argc,
122137
REFS_MIGRATE_USAGE,
123138
REFS_VERIFY_USAGE,
124139
"git refs list " COMMON_USAGE_FOR_EACH_REF,
140+
REFS_OPTIMIZE_USAGE,
125141
NULL,
126142
};
127143
parse_opt_subcommand_fn *fn = NULL;
128144
struct option opts[] = {
129145
OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate),
130146
OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify),
131147
OPT_SUBCOMMAND("list", &fn, cmd_refs_list),
148+
OPT_SUBCOMMAND("optimize", &fn, cmd_refs_optimize),
132149
OPT_END(),
133150
};
134151

0 commit comments

Comments
 (0)