t5562: fix perl path
[gitweb.git] / help.c
diff --git a/help.c b/help.c
index 1117f7d1d1f7b4ba439e5f9d1a08cffd5ff6ecad..e469f5731c3983ae5a20056e41fec42be798e7ad 100644 (file)
--- a/help.c
+++ b/help.c
@@ -1,7 +1,7 @@
 #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"
@@ -27,13 +27,26 @@ static struct category_description common_categories[] = {
        { CAT_remote, N_("collaborate (see also: git help workflows)") },
        { 0, NULL }
 };
+static struct category_description main_categories[] = {
+       { CAT_mainporcelain, N_("Main Porcelain Commands") },
+       { CAT_ancillarymanipulators, N_("Ancillary Commands / Manipulators") },
+       { CAT_ancillaryinterrogators, N_("Ancillary Commands / Interrogators") },
+       { CAT_foreignscminterface, N_("Interacting with Others") },
+       { CAT_plumbingmanipulators, N_("Low-level Commands / Manipulators") },
+       { CAT_plumbinginterrogators, N_("Low-level Commands / Interrogators") },
+       { CAT_synchingrepositories, N_("Low-level Commands / Synching Repositories") },
+       { CAT_purehelpers, N_("Low-level Commands / Internal Helpers") },
+       { 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;
 
 }
@@ -55,7 +68,7 @@ static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
                        continue;
 
                cmds[nr] = *cmd;
-               cmds[nr].name = drop_prefix(cmd->name);
+               cmds[nr].name = drop_prefix(cmd->name, cmd->category);
 
                nr++;
        }
@@ -347,11 +360,60 @@ void list_cmds_by_category(struct string_list *list,
        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);
+}
+
 int is_in_cmdlist(struct cmdnames *c, const char *s)
 {
        int i;
@@ -547,6 +609,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
                else
                        printf("no commit associated with this build\n");
                printf("sizeof-long: %d\n", (int)sizeof(long));
+               printf("sizeof-size_t: %d\n", (int)sizeof(size_t));
                /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
        }
        return 0;