{"thread":{"id":"50007","subject":"[PATCH 0/2] Fix git help -a with long alias names","startedAt":"2018-12-11T14:58:11Z","lastAt":"2018-12-12T09:43:44Z","messageCount":4,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"365083","messageId":"pull.97.git.gitgitgadget@gmail.com","threadId":"50007","inReplyTo":null,"subject":"[PATCH 0/2] Fix git help -a with long alias names","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-12-11T14:58:08Z","receivedAt":"2018-12-11T14:58:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"The code added in 26c7d0678324 (help -a: improve and make --verbose default,\n2018-09-29) that intends to print out aliases in addition to commands failed\nto adjust for the length of the aliases. As a consequence, if there was any\nalias whose name is longer than 18 characters, git help -a tried to print an\ninsanely large number of spaces, one at a time, causing what appeared to be\na \"hang\".\n\nLet's fix this, and while at it fix a style issue that I saw on the way as\nwell.\n\nOriginal report at https://github.com/git-for-windows/git/issues/1975\n\nJohannes Schindelin (2):\n  help.h: fix coding style\n  help -a: handle aliases with long names gracefully\n\n help.c | 10 +++++++++-\n help.h |  2 +-\n 2 files changed, 10 insertions(+), 2 deletions(-)\n\n\nbase-commit: 5d826e972970a784bd7a7bdf587512510097b8c7\nPublished-As: https://github.com/gitgitgadget/git/releases/tags/pr-97%2Fdscho%2Ffix-help-a-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-97/dscho/fix-help-a-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/97\n-- \ngitgitgadget\n"},{"id":"365084","messageId":"9dcaace5075fd83463d9c3d57bc51123fdd1568d.1544540287.git.gitgitgadget@gmail.com","threadId":"50007","inReplyTo":"pull.97.git.gitgitgadget@gmail.com","subject":"[PATCH 1/2] help.h: fix coding style","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-12-11T14:58:10Z","receivedAt":"2018-12-11T14:58:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe want a space after the `while` keyword.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n help.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/help.h b/help.h\nindex 9eab6a3f89..a141e209ae 100644\n--- a/help.h\n+++ b/help.h\n@@ -15,7 +15,7 @@ struct cmdnames {\n \n static inline void mput_char(char c, unsigned int num)\n {\n-\twhile(num--)\n+\twhile (num--)\n \t\tputchar(c);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"365085","messageId":"850cd5d15abe5b8a4356efe86ba81bc032278dce.1544540287.git.gitgitgadget@gmail.com","threadId":"50007","inReplyTo":"pull.97.git.gitgitgadget@gmail.com","subject":"[PATCH 2/2] help -a: handle aliases with long names gracefully","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-12-11T14:58:11Z","receivedAt":"2018-12-11T14:58:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe take pains to determine the longest command beforehand, so that we\ncan align the category column after printing the command names.\n\nHowever, then we re-use that value when printing the aliases. If any\nalias name is longer than the longest command name, we consequently try\nto add a negative number of spaces (but `mput_char()` does not expect\nany negative values and simply decrements until the value is 0, i.e.\nit tries to add close to 2**31 spaces).\n\nLet's fix this by adjusting the `longest` variable before printing the\naliases.\n\nThis fixes https://github.com/git-for-windows/git/issues/1975.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n help.c | 10 +++++++++-\n 1 file changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/help.c b/help.c\nindex 4745b32299..ff05fd22df 100644\n--- a/help.c\n+++ b/help.c\n@@ -83,8 +83,9 @@ static void print_command_list(const struct cmdname_help *cmds,\n \n \tfor (i = 0; cmds[i].name; i++) {\n \t\tif (cmds[i].category & mask) {\n+\t\t\tsize_t len = strlen(cmds[i].name);\n \t\t\tprintf(\"   %s   \", cmds[i].name);\n-\t\t\tmput_char(' ', longest - strlen(cmds[i].name));\n+\t\t\tmput_char(' ', longest > len ? longest - len : 1);\n \t\t\tputs(_(cmds[i].help));\n \t\t}\n \t}\n@@ -526,6 +527,13 @@ void list_all_cmds_help(void)\n \n \tgit_config(get_alias, &alias_list);\n \tstring_list_sort(&alias_list);\n+\n+\tfor (i = 0; i < alias_list.nr; i++) {\n+\t\tsize_t len = strlen(alias_list.items[i].string);\n+\t\tif (longest < len)\n+\t\t\tlongest = len;\n+\t}\n+\n \tif (alias_list.nr) {\n \t\tprintf(\"\\n%s\\n\", _(\"Command aliases\"));\n \t\tALLOC_ARRAY(aliases, alias_list.nr + 1);\n-- \ngitgitgadget\n"},{"id":"365164","messageId":"xmqqlg4vhygl.fsf@gitster-ct.c.googlers.com","threadId":"50007","inReplyTo":"850cd5d15abe5b8a4356efe86ba81bc032278dce.1544540287.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/2] help -a: handle aliases with long names gracefully","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-12T09:43:38Z","receivedAt":"2018-12-12T09:43:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> We take pains to determine the longest command beforehand, so that we\n> can align the category column after printing the command names.\n>\n> However, then we re-use that value when printing the aliases. If any\n> alias name is longer than the longest command name, we consequently try\n> to add a negative number of spaces (but `mput_char()` does not expect\n> any negative values and simply decrements until the value is 0, i.e.\n> it tries to add close to 2**31 spaces).\n\nThanks.  Let's take this and a few other topics that fix 2.20 brown\npaper bag breakages and prepare for 2.20.1 soonish.\n\n"}]}