From: Meet Soni <meetsoni3017@gmail•com>
To: git@vger•kernel.org
Cc: ps@pks•im, shejialuo@gmail•com, Meet Soni <meetsoni3017@gmail•com>
Subject: [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand
Date: Tue, 26 Aug 2025 13:06:43 +0530 [thread overview]
Message-ID: <20250826073645.1074397-4-meetsoni3017@gmail.com> (raw)
In-Reply-To: <20250826073645.1074397-1-meetsoni3017@gmail.com>
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>
---
Documentation/git-refs.adoc | 10 ++++++++++
builtin/refs.c | 16 ++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/Documentation/git-refs.adoc b/Documentation/git-refs.adoc
index e608980711..121a2fbeff 100644
--- a/Documentation/git-refs.adoc
+++ b/Documentation/git-refs.adoc
@@ -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::
+ Pack references into a single file to improve repository performance
+ and reduce storage 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
-----------------
diff --git a/builtin/refs.c b/builtin/refs.c
index 76224feba4..e05fa5b8a6 100644
--- a/builtin/refs.c
+++ b/builtin/refs.c
@@ -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,16 @@ 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 +136,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 +144,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(),
};
--
2.34.1
next prev parent reply other threads:[~2025-08-26 7:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:56 ` Meet Soni
2025-09-03 4:37 ` Patrick Steinhardt
2025-09-03 5:25 ` Junio C Hamano
2025-09-03 6:00 ` Patrick Steinhardt
2025-09-03 18:20 ` Junio C Hamano
2025-08-26 7:36 ` [GSoC][PATCH 2/5] doc: factor out common option Meet Soni
2025-08-26 7:36 ` Meet Soni [this message]
2025-09-02 10:18 ` [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand Patrick Steinhardt
2025-08-26 7:36 ` [GSoC][PATCH 4/5] t0601: refactor tests to be shareable Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
2025-08-26 15:18 ` shejialuo
2025-08-31 6:20 ` Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:58 ` Meet Soni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250826073645.1074397-4-meetsoni3017@gmail.com \
--to=meetsoni3017@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=ps@pks$(echo .)im \
--cc=shejialuo@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox