]> git.ipfire.org Git - thirdparty/git.git/commitdiff
help: do not expect built-in commands to be hardlinked
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 7 Oct 2020 21:56:51 +0000 (21:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2020 22:25:10 +0000 (15:25 -0700)
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>
git.c
help.c
help.h

diff --git a/git.c b/git.c
index 01c456edce923cd895a95a83ac211b6a5e5a3e0c..c853210bcc622f29c4773974501273033a7dcf19 100644 (file)
--- a/git.c
+++ b/git.c
@@ -637,6 +637,25 @@ static void list_builtins(struct string_list *out, unsigned int exclude_option)
        }
 }
 
+void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
+{
+       const char *name;
+       int i;
+
+       /*
+        * Callers can ask for a subset of the commands based on a certain
+        * prefix, which is then dropped from the added names. The names in
+        * the `commands[]` array do not have the `git-` prefix, though,
+        * therefore we must expect the `prefix` to at least start with `git-`.
+        */
+       if (!skip_prefix(prefix, "git-", &prefix))
+               BUG("prefix '%s' must start with 'git-'", prefix);
+
+       for (i = 0; i < ARRAY_SIZE(commands); i++)
+               if (skip_prefix(commands[i].cmd, prefix, &name))
+                       add_cmdname(cmds, name, strlen(name));
+}
+
 #ifdef STRIP_EXTENSION
 static void strip_extension(const char **argv)
 {
diff --git a/help.c b/help.c
index 4e2468a44dfe3154642299dbca0761ab114cb859..919cbb9206aedf98ac97e59e2132451210e1d4e4 100644 (file)
--- a/help.c
+++ b/help.c
@@ -263,6 +263,8 @@ void load_command_list(const char *prefix,
        const char *env_path = getenv("PATH");
        const char *exec_path = git_exec_path();
 
+       load_builtin_commands(prefix, main_cmds);
+
        if (exec_path) {
                list_commands_in_dir(main_cmds, exec_path, prefix);
                QSORT(main_cmds->names, main_cmds->cnt, cmdname_compare);
diff --git a/help.h b/help.h
index dc02458855c09291e2caf4bac6cd5b3a7ba40cff..5871e93ba2de04753905a7cf8220261e17159003 100644 (file)
--- a/help.h
+++ b/help.h
@@ -32,6 +32,7 @@ const char *help_unknown_cmd(const char *cmd);
 void load_command_list(const char *prefix,
                       struct cmdnames *main_cmds,
                       struct cmdnames *other_cmds);
+void load_builtin_commands(const char *prefix, struct cmdnames *cmds);
 void add_cmdname(struct cmdnames *cmds, const char *name, int len);
 /* Here we require that excludes is a sorted list. */
 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);