Skip to content

Commit eecccfe

Browse files
inosmeetgitster
authored andcommitted
builtin/refs: add list subcommand
Git's reference management is distributed across multiple commands. As part of an ongoing effort to consolidate and modernize reference handling, introduce a `list` subcommand under the `git refs` umbrella as a replacement for `git for-each-ref`. Implement `cmd_refs_list` by having it call the `for_each_ref_core()` helper function. This helper was factored out of the original `cmd_for_each_ref` 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-for-each-ref(1). Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: shejialuo <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Signed-off-by: Meet Soni <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6eeb1c0 commit eecccfe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Documentation/git-refs.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ SYNOPSIS
1111
[synopsis]
1212
git refs migrate --ref-format=<format> [--no-reflog] [--dry-run]
1313
git refs verify [--strict] [--verbose]
14+
git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
15+
[(--sort=<key>)...] [--format=<format>]
16+
[--include-root-refs] [--points-at=<object>]
17+
[--merged[=<object>]] [--no-merged[=<object>]]
18+
[--contains[=<object>]] [--no-contains[=<object>]]
19+
[(--exclude=<pattern>)...] [--start-after=<marker>]
20+
[ --stdin | <pattern>... ]
1421

1522
DESCRIPTION
1623
-----------
@@ -26,6 +33,11 @@ migrate::
2633
verify::
2734
Verify reference database consistency.
2835

36+
list::
37+
List references in the repository with support for filtering,
38+
formatting, and sorting. This subcommand is an alias for
39+
linkgit:git-for-each-ref[1] and offers identical functionality.
40+
2941
OPTIONS
3042
-------
3143

@@ -57,6 +69,10 @@ The following options are specific to 'git refs verify':
5769
--verbose::
5870
When verifying the reference database consistency, be chatty.
5971

72+
The following options are specific to 'git refs list':
73+
74+
include::for-each-ref-options.adoc[]
75+
6076
KNOWN LIMITATIONS
6177
-----------------
6278

builtin/refs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "refs.h"
77
#include "strbuf.h"
88
#include "worktree.h"
9+
#include "for-each-ref.h"
910

1011
#define REFS_MIGRATE_USAGE \
1112
N_("git refs migrate --ref-format=<format> [--no-reflog] [--dry-run]")
@@ -101,6 +102,17 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
101102
return ret;
102103
}
103104

105+
static int cmd_refs_list(int argc, const char **argv, const char *prefix,
106+
struct repository *repo)
107+
{
108+
static char const * const refs_list_usage[] = {
109+
N_("git refs list " COMMON_USAGE_FOR_EACH_REF),
110+
NULL
111+
};
112+
113+
return for_each_ref_core(argc, argv, prefix, repo, refs_list_usage);
114+
}
115+
104116
int cmd_refs(int argc,
105117
const char **argv,
106118
const char *prefix,
@@ -109,12 +121,14 @@ int cmd_refs(int argc,
109121
const char * const refs_usage[] = {
110122
REFS_MIGRATE_USAGE,
111123
REFS_VERIFY_USAGE,
124+
"git refs list " COMMON_USAGE_FOR_EACH_REF,
112125
NULL,
113126
};
114127
parse_opt_subcommand_fn *fn = NULL;
115128
struct option opts[] = {
116129
OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate),
117130
OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify),
131+
OPT_SUBCOMMAND("list", &fn, cmd_refs_list),
118132
OPT_END(),
119133
};
120134

0 commit comments

Comments
 (0)