git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] Fix git help -a with long alias names
@ 2018-12-11 14:58 Johannes Schindelin via GitGitGadget
  2018-12-11 14:58 ` [PATCH 1/2] help.h: fix coding style Johannes Schindelin via GitGitGadget
  2018-12-11 14:58 ` [PATCH 2/2] help -a: handle aliases with long names gracefully Johannes Schindelin via GitGitGadget
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-12-11 14:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

The code added in 26c7d0678324 (help -a: improve and make --verbose default,
2018-09-29) that intends to print out aliases in addition to commands failed
to adjust for the length of the aliases. As a consequence, if there was any
alias whose name is longer than 18 characters, git help -a tried to print an
insanely large number of spaces, one at a time, causing what appeared to be
a "hang".

Let's fix this, and while at it fix a style issue that I saw on the way as
well.

Original report at https://github.com/git-for-windows/git/issues/1975

Johannes Schindelin (2):
  help.h: fix coding style
  help -a: handle aliases with long names gracefully

 help.c | 10 +++++++++-
 help.h |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)


base-commit: 5d826e972970a784bd7a7bdf587512510097b8c7
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-97%2Fdscho%2Ffix-help-a-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-97/dscho/fix-help-a-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/97
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] help.h: fix coding style
  2018-12-11 14:58 [PATCH 0/2] Fix git help -a with long alias names Johannes Schindelin via GitGitGadget
@ 2018-12-11 14:58 ` Johannes Schindelin via GitGitGadget
  2018-12-11 14:58 ` [PATCH 2/2] help -a: handle aliases with long names gracefully Johannes Schindelin via GitGitGadget
  1 sibling, 0 replies; 4+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-12-11 14:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

We want a space after the `while` keyword.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 help.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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);
 }
 
-- 
gitgitgadget


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] help -a: handle aliases with long names gracefully
  2018-12-11 14:58 [PATCH 0/2] Fix git help -a with long alias names Johannes Schindelin via GitGitGadget
  2018-12-11 14:58 ` [PATCH 1/2] help.h: fix coding style Johannes Schindelin via GitGitGadget
@ 2018-12-11 14:58 ` Johannes Schindelin via GitGitGadget
  2018-12-12  9:43   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-12-11 14:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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 https://github.com/git-for-windows/git/issues/1975.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 help.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

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);
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] help -a: handle aliases with long names gracefully
  2018-12-11 14:58 ` [PATCH 2/2] help -a: handle aliases with long names gracefully Johannes Schindelin via GitGitGadget
@ 2018-12-12  9:43   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2018-12-12  9:43 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget; +Cc: git, Johannes Schindelin

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> 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).

Thanks.  Let's take this and a few other topics that fix 2.20 brown
paper bag breakages and prepare for 2.20.1 soonish.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-12  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-11 14:58 [PATCH 0/2] Fix git help -a with long alias names Johannes Schindelin via GitGitGadget
2018-12-11 14:58 ` [PATCH 1/2] help.h: fix coding style Johannes Schindelin via GitGitGadget
2018-12-11 14:58 ` [PATCH 2/2] help -a: handle aliases with long names gracefully Johannes Schindelin via GitGitGadget
2018-12-12  9:43   ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git