git: add hidden --list-builtins option

It can be useful in the test suite to be able to iterate over the list of builtins. We could do this with some Makefile magic. But since the authoritative list is in the commands array inside git.c, and since this could also be handy for debugging, let's add a hidden command-line option to dump that list. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 30, 2017 at 01:18 UTC 8893fd95b66cbd6566136a289dd05fcf4e547281
1 file changed +12
git.c
+12
@@ -26,6 +26,8 @@ static const char *env_names[] = {
26 static char *orig_env[4];
27 static int save_restore_env_balance;
28
29 +static void list_builtins(void);
30 +
31 static void save_env_before_alias(void)
32 {
33 int i;
@@ -232,6 +234,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
234 }
235 (*argv)++;
236 (*argc)--;
237 + } else if (!strcmp(cmd, "--list-builtins")) {
238 + list_builtins();
239 + exit(0);
240 } else {
241 fprintf(stderr, "Unknown option: %s\n", cmd);
242 usage(git_usage_string);
@@ -529,6 +534,13 @@ int is_builtin(const char *s)
534 return !!get_builtin(s);
535 }
536
537 +static void list_builtins(void)
538 +{
539 + int i;
540 + for (i = 0; i < ARRAY_SIZE(commands); i++)
541 + printf("%s\n", commands[i].cmd);
542 +}
543 +
544 #ifdef STRIP_EXTENSION
545 static void strip_extension(const char **argv)
546 {