#include "cache.h"
#include "config.h"
#include "builtin.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
#include "run-command.h"
#include "levenshtein.h"
#include "help.h"
{ 0, NULL }
};
-static const char *drop_prefix(const char *name)
+static const char *drop_prefix(const char *name, uint32_t category)
{
const char *new_name;
if (skip_prefix(name, "git-", &new_name))
return new_name;
+ if (category == CAT_guide && skip_prefix(name, "git", &new_name))
+ return new_name;
return name;
}
continue;
cmds[nr] = *cmd;
- cmds[nr].name = drop_prefix(cmd->name);
+ cmds[nr].name = drop_prefix(cmd->name, cmd->category);
nr++;
}
for (i = 0; i < n; i++) {
struct cmdname_help *cmd = command_list + i;
- if (cmd->category & cat_id)
- string_list_append(list, drop_prefix(cmd->name));
+ if (!(cmd->category & cat_id))
+ continue;
+ string_list_append(list, drop_prefix(cmd->name, cmd->category));
+ }
+}
+
+void list_cmds_by_config(struct string_list *list)
+{
+ const char *cmd_list;
+
+ /*
+ * There's no actual repository setup at this point (and even
+ * if there is, we don't really care; only global config
+ * matters). If we accidentally set up a repository, it's ok
+ * too since the caller (git --list-cmds=) should exit shortly
+ * anyway.
+ */
+ if (git_config_get_string_const("completion.commands", &cmd_list))
+ return;
+
+ string_list_sort(list);
+ string_list_remove_duplicates(list, 0);
+
+ while (*cmd_list) {
+ struct strbuf sb = STRBUF_INIT;
+ const char *p = strchrnul(cmd_list, ' ');
+
+ strbuf_add(&sb, cmd_list, p - cmd_list);
+ if (*cmd_list == '-')
+ string_list_remove(list, cmd_list + 1, 0);
+ else
+ string_list_insert(list, sb.buf);
+ strbuf_release(&sb);
+ while (*p == ' ')
+ p++;
+ cmd_list = p;
}
}
+void list_common_guides_help(void)
+{
+ struct category_description catdesc[] = {
+ { CAT_guide, N_("The common Git guides are:") },
+ { 0, NULL }
+ };
+ print_cmd_by_category(catdesc);
+ putchar('\n');
+}
+
void list_all_cmds_help(void)
{
print_cmd_by_category(main_categories);