Skip to content

Commit 916f56d

Browse files
committed
Merge branch 'js/help-commands-verbose-by-default-fix' into maint
"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
2 parents bf29f07 + 1c4b985 commit 916f56d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

help.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ static void print_command_list(const struct cmdname_help *cmds,
8383

8484
for (i = 0; cmds[i].name; i++) {
8585
if (cmds[i].category & mask) {
86+
size_t len = strlen(cmds[i].name);
8687
printf(" %s ", cmds[i].name);
87-
mput_char(' ', longest - strlen(cmds[i].name));
88+
mput_char(' ', longest > len ? longest - len : 1);
8889
puts(_(cmds[i].help));
8990
}
9091
}
@@ -526,6 +527,13 @@ void list_all_cmds_help(void)
526527

527528
git_config(get_alias, &alias_list);
528529
string_list_sort(&alias_list);
530+
531+
for (i = 0; i < alias_list.nr; i++) {
532+
size_t len = strlen(alias_list.items[i].string);
533+
if (longest < len)
534+
longest = len;
535+
}
536+
529537
if (alias_list.nr) {
530538
printf("\n%s\n", _("Command aliases"));
531539
ALLOC_ARRAY(aliases, alias_list.nr + 1);

help.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct cmdnames {
1515

1616
static inline void mput_char(char c, unsigned int num)
1717
{
18-
while(num--)
18+
while (num--)
1919
putchar(c);
2020
}
2121

0 commit comments

Comments
 (0)