[PATCH] help.autocorrect: do not run a command if the command given is junk

Subsystems: the rest

DORMANTno replies

4 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] help.autocorrect: do not run a command if the command given is junk

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:47:54

From: Johannes Sixt <redacted>

If a given command is not found, then help.c tries to guess which one the
user could have meant. If help.autocorrect is 0 or unset, then a list of
suggestions is given as long as the dissimilarity between the given command
and the candidates is not excessively high. But if help.autocorrect was
non-zero (i.e., a delay after which the command is run automatically), the
latter restriction on dissimilarity was not obeyed.

In my case, this happened:

 $ git ..daab02
 WARNING: You called a Git command named '..daab02', which does not exist.
 Continuing under the assumption that you meant 'read-tree'
 in 4.0 seconds automatically...

The similarity limit that this patch introduces is already used a few lines
later where the list of suggested commands is printed.

Signed-off-by: Johannes Sixt <redacted>
---
 help.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/help.c b/help.c
index e8db31f..db888cf 100644
--- a/help.c
+++ b/help.c
@@ -331,7 +331,7 @@ const char *help_unknown_cmd(const char *cmd)
 	n = 1;
 	while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
 		++n;
-	if (autocorrect && n == 1) {
+	if (autocorrect && n == 1 && best_similarity < 6) {
 		const char *assumed = main_cmds.names[0]->name;
 		main_cmds.names[0] = NULL;
 		clean_cmdnames(&main_cmds);
-- 
1.6.6.rc1.46.g1635

Re: [PATCH] help.autocorrect: do not run a command if the command given is junk

From: Alex Riesen <hidden>
Date: 2016-06-15 22:47:54

On Mon, Dec 14, 2009 at 14:03, Johannes Sixt [off-list ref] wrote:
From: Johannes Sixt <redacted>

If a given command is not found, then help.c tries to guess which one the
user could have meant. If help.autocorrect is 0 or unset, then a list of
suggestions is given as long as the dissimilarity between the given command
and the candidates is not excessively high. But if help.autocorrect was
non-zero (i.e., a delay after which the command is run automatically), the
latter restriction on dissimilarity was not obeyed.

In my case, this happened:

 $ git ..daab02
 WARNING: You called a Git command named '..daab02', which does not exist.
 Continuing under the assumption that you meant 'read-tree'
 in 4.0 seconds automatically...

The similarity limit that this patch introduces is already used a few lines
later where the list of suggested commands is printed.
Yes, sure. We probably just missed that (I don't use autocorrect myself
apart from the testing. I assume Johannes doesn't, too)

Re: [PATCH] help.autocorrect: do not run a command if the command given is junk

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:47:54

Hi,

On Mon, 14 Dec 2009, Johannes Sixt wrote:
From: Johannes Sixt <redacted>

If a given command is not found, then help.c tries to guess which one the
user could have meant. If help.autocorrect is 0 or unset, then a list of
suggestions is given as long as the dissimilarity between the given command
and the candidates is not excessively high. But if help.autocorrect was
non-zero (i.e., a delay after which the command is run automatically), the
latter restriction on dissimilarity was not obeyed.

In my case, this happened:

 $ git ..daab02
 WARNING: You called a Git command named '..daab02', which does not exist.
 Continuing under the assumption that you meant 'read-tree'
 in 4.0 seconds automatically...

The similarity limit that this patch introduces is already used a few lines
later where the list of suggested commands is printed.

Signed-off-by: Johannes Sixt <redacted>
---
Obvious ACK from me.

Re: [PATCH] help.autocorrect: do not run a command if the command given is junk

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:47:54

Hi,

On Mon, 14 Dec 2009, Alex Riesen wrote:
I don't use autocorrect myself apart from the testing. I assume Johannes 
doesn't, too
As a matter of fact, I do.  But my common mistakes are not in forgetting 
the subcommand, rather in mispelign them.  So I never hit the problem.

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help