@matheusbsbs / matheus-bagliano / commits / 722fc37491
Fork 0

help: do not expect built-in commands to be hardlinked

When building with SKIP_DASHED_BUILT_INS=YesPlease, the built-in commands are no longer present in the `PATH` as hardlinks to `git`. As a consequence, `load_command_list()` needs to be taught to find the names of the built-in commands from elsewhere. This only affected the output of `git --list-cmds=main`, but not the output of `git help -a` because the latter includes the built-in commands by virtue of them being listed in command-list.txt. The bug was detected via a patch series that turns the merge strategies included in Git into built-in commands: `git merge -s help` relies on `load_command_list()` to determine the list of available merge strategies. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 7, 2020 at 21:56 UTC 722fc374914d4f9b37d42a8eda603eecb790f64c
3 files changed +22
git.c
+19
@@ -637,6 +637,25 @@ static void list_builtins(struct string_list *out, unsigned int exclude_option)
637 }
638 }
639
640 +void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
641 +{
642 + const char *name;
643 + int i;
644 +
645 + /*
646 + * Callers can ask for a subset of the commands based on a certain
647 + * prefix, which is then dropped from the added names. The names in
648 + * the `commands[]` array do not have the `git-` prefix, though,
649 + * therefore we must expect the `prefix` to at least start with `git-`.
650 + */
651 + if (!skip_prefix(prefix, "git-", &prefix))
652 + BUG("prefix '%s' must start with 'git-'", prefix);
653 +
654 + for (i = 0; i < ARRAY_SIZE(commands); i++)
655 + if (skip_prefix(commands[i].cmd, prefix, &name))
656 + add_cmdname(cmds, name, strlen(name));
657 +}
658 +
659 #ifdef STRIP_EXTENSION
660 static void strip_extension(const char **argv)
661 {
help.c
+2
@@ -263,6 +263,8 @@ void load_command_list(const char *prefix,
263 const char *env_path = getenv("PATH");
264 const char *exec_path = git_exec_path();
265
266 + load_builtin_commands(prefix, main_cmds);
267 +
268 if (exec_path) {
269 list_commands_in_dir(main_cmds, exec_path, prefix);
270 QSORT(main_cmds->names, main_cmds->cnt, cmdname_compare);
help.h
+1
@@ -32,6 +32,7 @@ const char *help_unknown_cmd(const char *cmd);
32 void load_command_list(const char *prefix,
33 struct cmdnames *main_cmds,
34 struct cmdnames *other_cmds);
35 +void load_builtin_commands(const char *prefix, struct cmdnames *cmds);
36 void add_cmdname(struct cmdnames *cmds, const char *name, int len);
37 /* Here we require that excludes is a sorted list. */
38 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);