Skip to contentSkip to conversation

git wrapper: DWIM mistyped commands

PATCH In review Johannes Schindelin 5 participants 20 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git wrapper: DWIM mistyped commands

This patch introduces a modified Damerau-Levenshtein algorithm into Git's code base, and uses it with the following penalties to show some similar commands when an unknown command was encountered:

swap = 0, insertion = 1, substitution = 2, deletion = 4

A typical output would now look like this:

	$ git sm
	git: 'sm' is not a git-command. See 'git --help'.

Did you mean one of these?
am
rm

The cut-off is at similarity rating 6, which was empirically determined to give sensible results.

As a convenience, if there is only one candidate, Git continues under the assumption that the user mistyped it. Example:

	$ git reabse
	WARNING: You called a Git program named 'reabse', which does
	not exist.
	Continuing under the assumption that you meant 'rebase'
	[...]

---

So I mistyped 'reabse' for the hundred trillionth time, but I will never have to correct my mistakes again.

Note: this patch is _not_ meant for inclusion.

 Makefile      |    2 +
 builtin.h     |    2 +-
 git.c         |    4 ++-
 help.c        |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 levenshtein.c |   47 +++++++++++++++++++++++++++++++++++++++++++
 levenshtein.h |    8 +++++++
 6 files changed, 121 insertions(+), 3 deletions(-)
 create mode 100644 levenshtein.c
 create mode 100644 levenshtein.h
Makefile +2 -0
index 19bdd03..7e114e0 100644
@@ -347,6 +347,7 @@ LIB_H += git-compat-util.h
 LIB_H += graph.h
 LIB_H += grep.h
 LIB_H += hash.h
+LIB_H += levenshtein.h
 LIB_H += list-objects.h
 LIB_H += ll-merge.h
 LIB_H += log-tree.h
@@ -421,6 +422,7 @@ LIB_OBJS += hash.o
 LIB_OBJS += help.o
 LIB_OBJS += ident.o
 LIB_OBJS += interpolate.o
+LIB_OBJS += levenshtein.o
 LIB_OBJS += list-objects.o
 LIB_OBJS += ll-merge.o
 LIB_OBJS += lockfile.o
builtin.h +1 -1
index 0e605d4..fc5f108 100644
@@ -11,7 +11,7 @@ extern const char git_usage_string[];
 extern const char git_more_info_string[];
 
 extern void list_common_cmds_help(void);
-extern void help_unknown_cmd(const char *cmd);
+extern const char *help_unknown_cmd(const char *cmd);
 extern void prune_packed_objects(int);
 extern int read_line_with_nul(char *buf, int size, FILE *file);
 extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
git.c +3 -1
index 1bfd271..d7510ef 100644
@@ -500,7 +500,9 @@ int main(int argc, const char **argv)
 				cmd, argv[0]);
 			exit(1);
 		}
-		help_unknown_cmd(cmd);
+		argv[0] = help_unknown_cmd(cmd);
+		handle_internal_command(argc, argv);
+		execv_dashed_external(argv);
 	}
 
 	fprintf(stderr, "Failed to run command '%s': %s\n",
help.c +60 -1

75 lines not on this page · raw message

levenshtein.c new file +47 -0

47 lines not on this page · raw message

levenshtein.h new file +8 -0
new file mode 100644
index 0000000..0173abe
@@ -0,0 +1,8 @@
+#ifndef LEVENSHTEIN_H
+#define LEVENSHTEIN_H
+
+int levenshtein(const char *string1, const char *string2,
+	int swap_penalty, int substition_penalty,
+	int insertion_penalty, int deletion_penalty);
+
+#endif
Signature · 1 line
1.6.0.rc0.21.g91175
#1 lore raw
Quoted 19 lines · Johannes Schindelin

This patch introduces a modified Damerau-Levenshtein algorithm into Git's code base, and uses it with the following penalties to show some similar commands when an unknown command was encountered:

swap = 0, insertion = 1, substitution = 2, deletion = 4

A typical output would now look like this:

	$ git sm
	git: 'sm' is not a git-command. See 'git --help'.

Did you mean one of these?
am
rm

The cut-off is at similarity rating 6, which was empirically determined to give sensible results.

Quoted 8 lines

As a convenience, if there is only one candidate, Git continues under the assumption that the user mistyped it. Example:

	$ git reabse
	WARNING: You called a Git program named 'reabse', which does
	not exist.
	Continuing under the assumption that you meant 'rebase'
	[...]

<SCNR>
Or use a decent shell:

When typing e.g.: git tsa<tab>, it yields:
$ git status
---- corrections (errors 1)
status -- show working-tree's status
tag -- create tag object signed with GPG
tar-tree -- create tar archive of the files in the named tree
---- original
tsa

and it even works for non git commands ;)
</SCNR>

Despite that, I really like your idea. **hint hint** One could even hook that for long options into parse-options.

Signature · 3 lines
·O·  Pierre Habouzit
··O                                                [email protected]
OOO                                                http://www.madism.org
#2 lore raw

Hi,

Quoted 2 lines · Pierre Habouzit

<SCNR>
Or use a decent shell:

I tried that:

	git reab<tab><tab><TAB><TTAAABBB!>
Quoted 1 line

Despite that, I really like your idea. **hint hint**

I said that _I_ did not mean it for inclusion. **hint hint**

Ciao,
Dscho

#3 lore raw
Quoted 10 lines · Johannes Schindelin

Hi,

Quoted 2 lines · Pierre Habouzit

<SCNR>
Or use a decent shell:

I tried that:

	git reab<tab><tab><TAB><TTAAABBB!>

It yields the following here:

    $ git read-tree
    ---- corrections (errors 1)
    read-tree  -- read tree information into the directory index
    rebase     -- rebase local commits to new upstream head
    ---- original
    reab

and indeed, it should really suggest rebase first, I suppose I should reorder my zsh completion error weights. but oh well...

Quoted 3 lines
Quoted 1 line

Despite that, I really like your idea. **hint hint**

I said that _I_ did not mean it for inclusion. **hint hint**

Damn...

Signature · 3 lines
·O·  Pierre Habouzit
··O                                                [email protected]
OOO                                                http://www.madism.org
#4 lore raw
In reply to Johannes Schindelin

Johannes Schindelin, Tue, Jul 22, 2008 22:01:29 +0200:

Quoted 8 lines

As a convenience, if there is only one candidate, Git continues under the assumption that the user mistyped it. Example:

	$ git reabse
	WARNING: You called a Git program named 'reabse', which does
	not exist.
	Continuing under the assumption that you meant 'rebase'
	[...]

Oh, that would make me suspicios (and I hit Ctrl-C fast when I get suspicios about what happens to my precious data). Could it be configurable? For example, BASH's cdspell is configurable and even off by default.

P.S. I'm still using your first patch and am forced to like it every day :)

#5 lore raw

PATCH 1/1 Add help.autocorrect to enable/disable autocorrecting

It is off by default, to avoid scaring people unless they asked to.

---

Alex Riesen, Tue, Jul 22, 2008 22:37:30 +0200:

Quoted 10 lines

Johannes Schindelin, Tue, Jul 22, 2008 22:01:29 +0200:

Quoted 8 lines

As a convenience, if there is only one candidate, Git continues under the assumption that the user mistyped it. Example:

	$ git reabse
	WARNING: You called a Git program named 'reabse', which does
	not exist.
	Continuing under the assumption that you meant 'rebase'
	[...]
Quoted 5 lines

Oh, that would make me suspicios (and I hit Ctrl-C fast when I get suspicios about what happens to my precious data). Could it be configurable? For example, BASH's cdspell is configurable and even off by default.

Like this, perhaps?

 help.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
help.c +6 -2
index 480befe..f08eb9d 100644
@@ -28,6 +28,7 @@ enum help_format {
 	HELP_FORMAT_WEB,
 };
 
+static int autocorrect;
 static int show_all = 0;
 static enum help_format help_format = HELP_FORMAT_MAN;
 static struct option builtin_help_options[] = {
@@ -269,6 +270,8 @@ static int git_help_config(const char *var, const char *value, void *cb)
 	}
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
+	if (!strcmp(var, "help.autocorrect"))
+		autocorrect = git_config_bool(var,value);
 
 	return git_default_config(var, value, cb);
 }
@@ -704,9 +707,10 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
+	git_config(git_help_config, NULL);
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))
Signature · 1 line
1.6.0.rc0.48.g6dda.dirty
#6 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Hi,

help.c const char *help_unknown_cmd(const char *cmd) · line 716

Quoted 5 lines · Alex Riesen
help.c +2 -0
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))

In that case, you need to put in the "one of these" / "this" conditional again, which I ripped out because I do not need it any more.

Ciao,
Dscho

#7 lore raw

PATCH 1/1 Add help.autocorrect to enable/disable autocorrecting

It is off by default, to avoid scaring people unless they asked to.
---
Johannes Schindelin, Tue, Jul 22, 2008 23:08:19 +0200:

Quoted 11 lines · Alex Riesen

Review

Quoted 6 lines
(quoted diff) +2 -0
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))

In that case, you need to put in the "one of these" / "this" conditional again, which I ripped out because I do not need it any more.

Of course, missed it. Like this, then.

 help.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
help.c +14 -6
index 480befe..cf6b459 100644
@@ -28,6 +28,7 @@ enum help_format {
 	HELP_FORMAT_WEB,
 };
 
+static int autocorrect;
 static int show_all = 0;
 static enum help_format help_format = HELP_FORMAT_MAN;
 static struct option builtin_help_options[] = {
@@ -269,6 +270,8 @@ static int git_help_config(const char *var, const char *value, void *cb)
 	}
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
+	if (!strcmp(var, "help.autocorrect"))
+		autocorrect = git_config_bool(var,value);
 
 	return git_default_config(var, value, cb);
 }
@@ -704,9 +707,10 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
+	git_config(git_help_config, NULL);
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))
@@ -721,10 +725,14 @@ const char *help_unknown_cmd(const char *cmd)
 	fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
 
 	if (best_similarity < 6) {
-		fprintf(stderr, "\nDid you mean one of these?\n");
-
-		for (i = 0; i < main_cmds.cnt && best_similarity ==
-				similarity(main_cmds.names[i]->name); i++)
+		int n = 0;
+		while (n < main_cmds.cnt &&
+			best_similarity == similarity(main_cmds.names[n]->name))
+			++n;
+		fprintf(stderr, "\nDid you mean %s?\n",
+			n < 2 ? "this": "one of these");
+
+		for (i = 0; i < n; i++)
 			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
 	}
 
Signature · 1 line
1.6.0.rc0.48.ga184
#8 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Hi,

help.c const char *help_unknown_cmd(const char *cmd) · line 716

Quoted 13 lines · Alex Riesen
help.c +3 -2
@@ -704,9 +707,10 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
+	git_config(git_help_config, NULL);
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))

This "if" already checks if there is only one candidate. So you should just add an inner "if (autocorrect) ... else single = 1;" or some such.

However, I think that the intention of this patch is too much DWIMery, which might be good for me (just like my "git add remote" patch), but not for the general audience.

Ciao,
Dscho

#9 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Quoted 21 lines · Johannes Schindelin

Hi,

help.c const char *help_unknown_cmd(const char *cmd) · line 716

Quoted 13 lines · Alex Riesen
help.c +3 -2
@@ -704,9 +707,10 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
+	git_config(git_help_config, NULL);
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))

This "if" already checks if there is only one candidate. So you should just add an inner "if (autocorrect) ... else single = 1;" or some such.

Quoted 3 lines

However, I think that the intention of this patch is too much DWIMery, which might be good for me (just like my "git add remote" patch), but not for the general audience.

Please make autocorrect not a binary but optionally the number of deciseconds before it continues, so that I have a chance to hit ^C ;-)

#10 lore raw

PATCH 1/1 Wait help.autocorrect deciseconds before running corrected command

Suggested by Junio, so he has a chance to hit Ctrl-C.
---
Junio C Hamano, Wed, Jul 23, 2008 01:08:17 +0200:

Quoted 3 lines

Please make autocorrect not a binary but optionally the number of deciseconds before it continues, so that I have a chance to hit ^C ;-)

on top of the last patch.

 Documentation/config.txt |    9 +++++++++
 help.c                   |    7 ++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
Documentation/config.txt +9 -0
index e784805..5bf1d0d 100644
@@ -771,6 +771,15 @@ help.format::
 	Values 'man', 'info', 'web' and 'html' are supported. 'man' is
 	the default. 'web' and 'html' are the same.
 
+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,
+	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.
+
 http.proxy::
 	Override the HTTP proxy, normally configured using the 'http_proxy'
 	environment variable (see linkgit:curl[1]).  This can be overridden
help.c +6 -1
index 8b25a55..4d52781 100644
@@ -271,7 +271,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
 	if (!strcmp(var, "help.autocorrect"))
-		autocorrect = git_config_bool(var,value);
+		autocorrect = git_config_int(var,value);
 
 	return git_default_config(var, value, cb);
 }
@@ -722,6 +722,11 @@ const char *help_unknown_cmd(const char *cmd)
 			"which does not exist.\n"
 			"Continuing under the assumption that you meant '%s'\n",
 			cmd, main_cmds.names[0]->name);
+		if (autocorrect > 0) {
+			fprintf(stderr, "in %0.1f seconds automatically...\n",
+				(float)autocorrect/10.0);
+			poll(NULL, 0, autocorrect * 100);
+		}
 		return main_cmds.names[0]->name;
 	}
 
Signature · 1 line
1.6.0.rc0.50.g9c23
#11 lore raw

Re: [PATCH] Wait help.autocorrect deciseconds before running corrected command

Hi,

help.c const char *help_unknown_cmd(const char *cmd) · line 729

Quoted 5 lines · Alex Riesen
help.c +5 -0
+		if (autocorrect > 0) {
+			fprintf(stderr, "in %0.1f seconds automatically...\n",
+				(float)autocorrect/10.0);
+			poll(NULL, 0, autocorrect * 100);
+		}

What? No countdown? No fancy sounds when the time ran up?

Ciao,
Dscho

#12 lore raw

Re: [PATCH] Wait help.autocorrect deciseconds before running corrected command

Johannes Schindelin, Wed, Jul 23, 2008 18:57:05 +0200:

Quoted 10 lines · Alex Riesen

help.c const char *help_unknown_cmd(const char *cmd) · line 729

Quoted 6 lines
help.c +5 -0
+		if (autocorrect > 0) {
+			fprintf(stderr, "in %0.1f seconds automatically...\n",
+				(float)autocorrect/10.0);
+			poll(NULL, 0, autocorrect * 100);
+		}

What? No countdown? No fancy sounds when the time ran up?

Hate them fancies... :)

#13 lore raw

PATCH 1/1 Add help.autocorrect to enable/disable autocorrecting

In reply to Johannes Schindelin

It is off by default, to avoid scaring people unless they asked to.
---

Johannes Schindelin, Tue, Jul 22, 2008 23:44:50 +0200:

Quoted 18 lines · Alex Riesen
Quoted 4 lines
(quoted diff) +0 -0
@@ -704,9 +707,10 @@ const char *help_unknown_cmd(const char *cmd)
 
 	if (!main_cmds.cnt)

Review const char *help_unknown_cmd(const char *cmd) · line 716

Quoted 10 lines
(quoted diff) +3 -2
 		die ("Uh oh.  Your system reports no Git commands at all.");
+	git_config(git_help_config, NULL);
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	if (autocorrect && (main_cmds.cnt < 2 ||
+		best_similarity < similarity(main_cmds.names[1]->name))) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))

This "if" already checks if there is only one candidate. So you should just add an inner "if (autocorrect) ... else single = 1;" or some such.

Oh right, stupid me.

Quoted 3 lines

However, I think that the intention of this patch is too much DWIMery, which might be good for me (just like my "git add remote" patch), but not for the general audience.

Mustn't be good for all (for the "general audience" it is even common practice to forget to thank. It may be even a sign of bad manners for it). It is good for me though. And thanks for sharing.

Moved git_config before the calls where current directory is changed:
so that it has the same filesystem context as in normal case. Less surprises.

 help.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
help.c +13 -6
index 480befe..8b25a55 100644
@@ -28,6 +28,7 @@ enum help_format {
 	HELP_FORMAT_WEB,
 };
 
+static int autocorrect;
 static int show_all = 0;
 static enum help_format help_format = HELP_FORMAT_MAN;
 static struct option builtin_help_options[] = {
@@ -269,6 +270,8 @@ static int git_help_config(const char *var, const char *value, void *cb)
 	}
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
+	if (!strcmp(var, "help.autocorrect"))
+		autocorrect = git_config_bool(var,value);
 
 	return git_default_config(var, value, cb);
 }
@@ -683,7 +686,7 @@ static int levenshtein_compare(const void *p1, const void *p2)
 
 const char *help_unknown_cmd(const char *cmd)
 {
-	int i, best_similarity = 0;
+	int i, best_similarity = 0, n;
 	char cwd[PATH_MAX];
 
 	if (!getcwd(cwd, sizeof(cwd))) {
@@ -691,6 +694,7 @@ const char *help_unknown_cmd(const char *cmd)
 		cwd[0] = '\0';
 	}
 
+	git_config(git_help_config, NULL);
 	load_command_list();
 	ALLOC_GROW(main_cmds.names, main_cmds.cnt + other_cmds.cnt,
 			main_cmds.alloc);
@@ -705,8 +709,11 @@ const char *help_unknown_cmd(const char *cmd)
 	if (!main_cmds.cnt)
 		die ("Uh oh.  Your system reports no Git commands at all.");
 	best_similarity = similarity(main_cmds.names[0]->name);
-	if (main_cmds.cnt < 2 || best_similarity <
-			similarity(main_cmds.names[1]->name)) {
+	n = 1;
+	while (n < main_cmds.cnt &&
+		best_similarity == similarity(main_cmds.names[n]->name))
+		++n;
+	if (autocorrect && n == 1) {
 		if (!*cwd)
 			exit(1);
 		if (chdir(cwd))
@@ -721,10 +728,10 @@ const char *help_unknown_cmd(const char *cmd)
 	fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
 
 	if (best_similarity < 6) {
-		fprintf(stderr, "\nDid you mean one of these?\n");
+		fprintf(stderr, "\nDid you mean %s?\n",
+			n < 2 ? "this": "one of these");
 
-		for (i = 0; i < main_cmds.cnt && best_similarity ==
-				similarity(main_cmds.names[i]->name); i++)
+		for (i = 0; i < n; i++)
 			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
 	}
 
Signature · 1 line
1.6.0.rc0.48.ga184
#14 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Hi,

Quoted 6 lines · Alex Riesen

Johannes Schindelin, Tue, Jul 22, 2008 23:44:50 +0200:

Quoted 3 lines

However, I think that the intention of this patch is too much DWIMery, which might be good for me (just like my "git add remote" patch), but not for the general audience.

Mustn't be good for all

You meant "needn't"? It is good for me ;-)

Quoted 1 line

And thanks for sharing.

You're welcome.

help.c const char *help_unknown_cmd(const char *cmd) · line 715

Quoted 4 lines
help.c +4 -0
+	n = 1;
+	while (n < main_cmds.cnt &&
+		best_similarity == similarity(main_cmds.names[n]->name))
+		++n;

Mini-nit: you never ask for the value of n, only if it is 1 or larger. So you do not need to count...

Ciao,
Dscho

#15 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Johannes Schindelin, Wed, Jul 23, 2008 18:44:49 +0200:

Quoted 7 lines

help.c const char *help_unknown_cmd(const char *cmd) · line 715

Quoted 4 lines
help.c +4 -0
+	n = 1;
+	while (n < main_cmds.cnt &&
+		best_similarity == similarity(main_cmds.names[n]->name))
+		++n;

Mini-nit: you never ask for the value of n, only if it is 1 or larger. So you do not need to count...

But I do, don't I? AFAICS, I use 0, 1 and >1 (this-these).

#16 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Hi,

Quoted 10 lines · Alex Riesen

Johannes Schindelin, Wed, Jul 23, 2008 18:44:49 +0200:

Quoted 7 lines

help.c const char *help_unknown_cmd(const char *cmd) · line 715

Quoted 4 lines
help.c +4 -0
+	n = 1;
+	while (n < main_cmds.cnt &&
+		best_similarity == similarity(main_cmds.names[n]->name))
+		++n;

Mini-nit: you never ask for the value of n, only if it is 1 or larger. So you do not need to count...

But I do, don't I? AFAICS, I use 0, 1 and >1 (this-these).

Yes. So check cnt > 0 && best_similarity > 5 says if it is 0, and cnt > 1 && best_similarity < similarity(...[1]...) says if it is 1.

Ergo: no need to count,
Dscho

#17 lore raw

Re: [PATCH] Add help.autocorrect to enable/disable autocorrecting

Hi,

Quoted 11 lines · Johannes Schindelin
Quoted 9 lines · Alex Riesen

Johannes Schindelin, Wed, Jul 23, 2008 18:44:49 +0200:

Quoted 7 lines

help.c const char *help_unknown_cmd(const char *cmd) · line 715

Quoted 4 lines
help.c +4 -0
+	n = 1;
+	while (n < main_cmds.cnt &&
+		best_similarity == similarity(main_cmds.names[n]->name))
+		++n;

Mini-nit: you never ask for the value of n, only if it is 1 or larger. So you do not need to count...

Quoted 3 lines
Quoted 1 line

But I do, don't I? AFAICS, I use 0, 1 and >1 (this-these).

Yes. So check cnt > 0 && best_similarity > 5 says if it is 0,

Oh, I just realized that my patch is bogus anyway. It only checks for best_similarity > 5 in the case that the first two commands have equal similarity. D'oh.

Ciao,
Dscho

#18 lore raw
In reply to Johannes Schindelin
Quoted 4 lines · Johannes Schindelin

So I mistyped 'reabse' for the hundred trillionth time, but I will never have to correct my mistakes again.

Note: this patch is _not_ meant for inclusion.

Heh, I do "git emrge" all the time ;-)

Time to start a "gitster private edition" branch for my own use, I guess.

#19 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin

So I mistyped 'reabse' for the hundred trillionth time, but I will never have to correct my mistakes again.

Note: this patch is _not_ meant for inclusion.

Heh, I do "git emrge" all the time ;-)

Time to start a "gitster private edition" branch for my own use, I guess.

If it is the same typo all the time, wouldn't aliasses do the trick?

Signature · 3 lines
Cheers,

Sverre Rabbelier