summary refs log tree commit
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-12-15 12:24:33 +0900
committerJunio C Hamano <gitster@pobox.com>2018-12-15 12:24:33 +0900
commit916f56d38bc86cf8bed0698afde5051c05e7cc68 (patch)
tree3a0d09409abaea41a184c712095913e305736e05
parentbf29f074ed7019abb53398c4cd5659d9f939d9a8 (diff)
parent1c4b985965a4c424e7e5ae4756e139c98183278d (diff)
"git help -a" did not work well when an overly long alias is
defined, which has been corrected.

* js/help-commands-verbose-by-default-fix:
  help -a: handle aliases with long names gracefully
  help.h: fix coding style
-rw-r--r--help.c10
-rw-r--r--help.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/help.c b/help.c
index 4745b32299..ff05fd22df 100644
--- a/help.c
+++ b/help.c
@@ -83,8 +83,9 @@ static void print_command_list(const struct cmdname_help *cmds,
 
         for (i = 0; cmds[i].name; i++) {
                 if (cmds[i].category & mask) {
+                        size_t len = strlen(cmds[i].name);
                         printf("   %s   ", cmds[i].name);
-                        mput_char(' ', longest - strlen(cmds[i].name));
+                        mput_char(' ', longest > len ? longest - len : 1);
                         puts(_(cmds[i].help));
                 }
         }
@@ -526,6 +527,13 @@ void list_all_cmds_help(void)
 
         git_config(get_alias, &alias_list);
         string_list_sort(&alias_list);
+
+        for (i = 0; i < alias_list.nr; i++) {
+                size_t len = strlen(alias_list.items[i].string);
+                if (longest < len)
+                        longest = len;
+        }
+
         if (alias_list.nr) {
                 printf("\n%s\n", _("Command aliases"));
                 ALLOC_ARRAY(aliases, alias_list.nr + 1);
diff --git a/help.h b/help.h
index 9eab6a3f89..a141e209ae 100644
--- a/help.h
+++ b/help.h
@@ -15,7 +15,7 @@ struct cmdnames {
 
 static inline void mput_char(char c, unsigned int num)
 {
-        while(num--)
+        while (num--)
                 putchar(c);
 }