Skip to content

Commit

Permalink
help -a: handle aliases with long names gracefully
Browse files Browse the repository at this point in the history
We take pains to determine the longest command beforehand, so that we
can align the category column after printing the command names.

However, then we re-use that value when printing the aliases. If any
alias name is longer than the longest command name, we consequently try
to add a negative number of spaces (but `mput_char()` does not expect
any negative values and simply decrements until the value is 0, i.e.
it tries to add close to 2**31 spaces).

Let's fix this by adjusting the `longest` variable before printing the
aliases.

This fixes git-for-windows#1975.

Signed-off-by: Johannes Schindelin <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
dscho authored and gitster committed Dec 12, 2018
1 parent 5acea87 commit 1c4b985
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1c4b985

Please sign in to comment.