git-p4: improve path encoding verbose output
[gitweb.git] / help.c
diff --git a/help.c b/help.c
index f31f29ac421e224a59726fc1f2dfc16d92faad0f..d996b340669a66d0b1619472fedf5c11b940d7c5 100644 (file)
--- a/help.c
+++ b/help.c
@@ -144,7 +144,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 
        while ((de = readdir(dir)) != NULL) {
                const char *ent;
-               int entlen;
+               size_t entlen;
 
                if (!skip_prefix(de->d_name, prefix, &ent))
                        continue;
@@ -155,8 +155,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
                        continue;
 
                entlen = strlen(ent);
-               if (has_extension(ent, ".exe"))
-                       entlen -= 4;
+               strip_suffix(ent, ".exe", &entlen);
 
                add_cmdname(cmds, ent, entlen);
        }
@@ -219,17 +218,39 @@ void list_commands(unsigned int colopts,
        }
 }
 
+static int cmd_group_cmp(const void *elem1, const void *elem2)
+{
+       const struct cmdname_help *e1 = elem1;
+       const struct cmdname_help *e2 = elem2;
+
+       if (e1->group < e2->group)
+               return -1;
+       if (e1->group > e2->group)
+               return 1;
+       return strcmp(e1->name, e2->name);
+}
+
 void list_common_cmds_help(void)
 {
        int i, longest = 0;
+       int current_grp = -1;
 
        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
                if (longest < strlen(common_cmds[i].name))
                        longest = strlen(common_cmds[i].name);
        }
 
-       puts(_("The most commonly used git commands are:"));
+       qsort(common_cmds, ARRAY_SIZE(common_cmds),
+               sizeof(common_cmds[0]), cmd_group_cmp);
+
+       puts(_("These are common Git commands used in various situations:"));
+
        for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
+               if (common_cmds[i].group != current_grp) {
+                       printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group]));
+                       current_grp = common_cmds[i].group;
+               }
+
                printf("   %s   ", common_cmds[i].name);
                mput_char(' ', longest - strlen(common_cmds[i].name));
                puts(_(common_cmds[i].help));
@@ -306,7 +327,7 @@ const char *help_unknown_cmd(const char *cmd)
        add_cmd_list(&main_cmds, &aliases);
        add_cmd_list(&main_cmds, &other_cmds);
        qsort(main_cmds.names, main_cmds.cnt,
-             sizeof(main_cmds.names), cmdname_compare);
+             sizeof(*main_cmds.names), cmdname_compare);
        uniq(&main_cmds);
 
        /* This abuses cmdname->len for levenshtein distance */
@@ -373,7 +394,7 @@ const char *help_unknown_cmd(const char *cmd)
                if (autocorrect > 0) {
                        fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
                                (float)autocorrect/10.0);
-                       poll(NULL, 0, autocorrect * 100);
+                       sleep_millisec(autocorrect * 100);
                }
                return assumed;
        }
@@ -408,7 +429,7 @@ struct similar_ref_cb {
        struct string_list *similar_refs;
 };
 
-static int append_similar_ref(const char *refname, const unsigned char *sha1,
+static int append_similar_ref(const char *refname, const struct object_id *oid,
                              int flags, void *cb_data)
 {
        struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);