Skip to content

Commit 5f31632

Browse files
LemmingAvalanchegitster
authored andcommitted
git: add deprecated category to --list-cmds
With 145 builtin commands (according to `git --list-cmds=builtins`), users are probably not keeping on top of which ones (if any) are deprecated. Let’s expand the experimental `--list-cmds`[1] to allow users and programs to query for this information. We will also use this in an upcoming commit to implement `is_deprecated_command`. [1]: Using something which is experimental to query for deprecations is perhaps not the most ideal approach, but it is simple to implement and better than having to scan the documentation Acked-by: Patrick Steinhardt <[email protected]> Helped-by: Patrick Steinhardt <[email protected]> Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29fe658 commit 5f31632

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Documentation/git.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ If you just want to run git as if it was started in `<path>` then use
219219
List commands by group. This is an internal/experimental
220220
option and may change or be removed in the future. Supported
221221
groups are: builtins, parseopt (builtin commands that use
222-
parse-options), main (all commands in libexec directory),
222+
parse-options), deprecated (deprecated builtins),
223+
main (all commands in libexec directory),
223224
others (all other commands in `$PATH` that have git- prefix),
224225
list-<category> (see categories in command-list.txt),
225226
nohelpers (exclude helper commands), alias and config

git.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define NEED_WORK_TREE (1<<3)
2929
#define DELAY_PAGER_CONFIG (1<<4)
3030
#define NO_PARSEOPT (1<<5) /* parse-options is not used */
31+
#define DEPRECATED (1<<6)
3132

3233
struct cmd_struct {
3334
const char *cmd;
@@ -51,7 +52,9 @@ const char git_more_info_string[] =
5152

5253
static int use_pager = -1;
5354

54-
static void list_builtins(struct string_list *list, unsigned int exclude_option);
55+
static void list_builtins(struct string_list *list,
56+
unsigned int include_option,
57+
unsigned int exclude_option);
5558

5659
static void exclude_helpers_from_list(struct string_list *list)
5760
{
@@ -88,7 +91,7 @@ static int list_cmds(const char *spec)
8891
int len = sep - spec;
8992

9093
if (match_token(spec, len, "builtins"))
91-
list_builtins(&list, 0);
94+
list_builtins(&list, 0, 0);
9295
else if (match_token(spec, len, "main"))
9396
list_all_main_cmds(&list);
9497
else if (match_token(spec, len, "others"))
@@ -99,6 +102,8 @@ static int list_cmds(const char *spec)
99102
list_aliases(&list);
100103
else if (match_token(spec, len, "config"))
101104
list_cmds_by_config(&list);
105+
else if (match_token(spec, len, "deprecated"))
106+
list_builtins(&list, DEPRECATED, 0);
102107
else if (len > 5 && !strncmp(spec, "list-", 5)) {
103108
struct strbuf sb = STRBUF_INIT;
104109

@@ -322,7 +327,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
322327
if (!strcmp(cmd, "parseopt")) {
323328
struct string_list list = STRING_LIST_INIT_DUP;
324329

325-
list_builtins(&list, NO_PARSEOPT);
330+
list_builtins(&list, 0, NO_PARSEOPT);
326331
for (size_t i = 0; i < list.nr; i++)
327332
printf("%s ", list.items[i].string);
328333
string_list_clear(&list, 0);
@@ -590,7 +595,7 @@ static struct cmd_struct commands[] = {
590595
{ "notes", cmd_notes, RUN_SETUP },
591596
{ "pack-objects", cmd_pack_objects, RUN_SETUP },
592597
#ifndef WITH_BREAKING_CHANGES
593-
{ "pack-redundant", cmd_pack_redundant, RUN_SETUP | NO_PARSEOPT },
598+
{ "pack-redundant", cmd_pack_redundant, RUN_SETUP | NO_PARSEOPT | DEPRECATED },
594599
#endif
595600
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
596601
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
@@ -647,7 +652,7 @@ static struct cmd_struct commands[] = {
647652
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
648653
{ "version", cmd_version },
649654
#ifndef WITH_BREAKING_CHANGES
650-
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
655+
{ "whatchanged", cmd_whatchanged, RUN_SETUP | DEPRECATED },
651656
#endif
652657
{ "worktree", cmd_worktree, RUN_SETUP },
653658
{ "write-tree", cmd_write_tree, RUN_SETUP },
@@ -668,11 +673,16 @@ int is_builtin(const char *s)
668673
return !!get_builtin(s);
669674
}
670675

671-
static void list_builtins(struct string_list *out, unsigned int exclude_option)
676+
static void list_builtins(struct string_list *out,
677+
unsigned int include_option,
678+
unsigned int exclude_option)
672679
{
680+
if (include_option && exclude_option)
681+
BUG("'include_option' and 'exclude_option' are mutually exclusive");
673682
for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
674-
if (exclude_option &&
675-
(commands[i].option & exclude_option))
683+
if (include_option && !(commands[i].option & include_option))
684+
continue;
685+
if (exclude_option && (commands[i].option & exclude_option))
676686
continue;
677687
string_list_append(out, commands[i].cmd);
678688
}

0 commit comments

Comments
 (0)