[PATCH] help_unknown_command: disable auto correction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This is a very minor nitpick, but since it bothers me I thought I'd patch it
anyway. If it doesn't bother anyone else, then please ignore this patch.

I am a fast but rather inaccurate typer, so now and then I mistype a Git
command. The first time this happens I have to wait up to 15 seconds before
Git returns with an error. It takes my brain only 0.15 seconds to see the
typo, but I still have the wait the remaining 14.45 seconds before I can
retry.

I have patched help_unknown_command(), so you can disable auto correction
with help.autocorrect == -2.

Beware that this is not 100% backward compatible, because before this patch
_any_ negative value (including -2) would set the auto correction delay to
zero.

- Theo

-- >8 --
Subject: [PATCH] help_unknown_command: disable auto correction

Auto correction can be rather slow (because it searches the path), so
disable it with "git config help.autocorrect -2".

Signed-off-by: Theo Niessink <theo@xxxxxxxxxx>
---
 Documentation/config.txt |    5 +++--
 help.c                   |    8 ++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 0658ffb..452e3a8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1188,10 +1188,11 @@ help.autocorrect::
 	Automatically correct and execute mistyped commands after
 	waiting for the given number of deciseconds (0.1 sec). If more
 	than one command can be deduced from the entered text, nothing
-	will be executed.  If the value of this option is negative,
+	will be executed.  If the value of this option is -1,
 	the corrected command will be executed immediately. If the
 	value is 0 - the command will be just shown but not executed.
-	This is the default.
+	This is the default. If the value is -2, auto correction is disabled
+	altogether.
 
 http.proxy::
 	Override the HTTP proxy, normally configured using the 'http_proxy'
diff --git a/help.c b/help.c
index cbbe966..31a6d54 100644
--- a/help.c
+++ b/help.c
@@ -320,6 +320,13 @@ const char *help_unknown_cmd(const char *cmd)
 
 	git_config(git_unknown_cmd_config, NULL);
 
+	if (autocorrect == -2)
+	{
+		/* No similarity */
+		best_similarity = SIMILARITY_FLOOR;
+		goto skip_autocorrect;
+	}
+
 	load_command_list("git-", &main_cmds, &other_cmds);
 
 	add_cmd_list(&main_cmds, &aliases);
@@ -396,6 +403,7 @@ const char *help_unknown_cmd(const char *cmd)
 		return assumed;
 	}
 
+skip_autocorrect:
 	fprintf(stderr, "git: '%s' is not a git command. See 'git --help'.\n", cmd);
 
 	if (SIMILAR_ENOUGH(best_similarity)) {
-- 
1.7.6.msysgit.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]