[PATCH] Add the utterly important 'mispel' command
If you do not remember how to mispel a command, you need some help.
Provide it.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: A Large Angry SCM <gitzilla@gmail.com>
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Acked-By: <paisleyklm@gmail.com>
---
Please apply.
Makefile | 1 +
builtin-mispel.c | 11 +++++++++++
builtin.h | 2 ++
git.c | 1 +
help.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 46 insertions(+), 0 deletions(-)
create mode 100644 builtin-mispel.c
diff --git a/Makefile b/Makefile
index 690ac55..0b48b3b 100644
--- a/Makefile
+++ b/Makefile
@@ -610,6 +610,7 @@ BUILTIN_OBJS += builtin-merge-file.o
BUILTIN_OBJS += builtin-merge-ours.o
BUILTIN_OBJS += builtin-merge-recursive.o
BUILTIN_OBJS += builtin-mktree.o
+BUILTIN_OBJS += builtin-mispel.o
BUILTIN_OBJS += builtin-mv.o
BUILTIN_OBJS += builtin-name-rev.o
BUILTIN_OBJS += builtin-pack-objects.o
diff --git a/builtin-mispel.c b/builtin-mispel.c
new file mode 100644
index 0000000..e685f91
--- /dev/null
+++ b/builtin-mispel.c
@@ -0,0 +1,11 @@
+#include "cache.h"
+#include "builtin.h"
+
+int cmd_mispel(int argc, const char **argv, const char *prefix)
+{
+ if (argc < 2)
+ die ("What command do you want to mispel?");
+ error("You probably meant %s", help_mispeld_comd(argv[1]));
+ return 0;
+
+}
diff --git a/builtin.h b/builtin.h
index 20427d2..2973d90 100644
--- a/builtin.h
+++ b/builtin.h
@@ -12,6 +12,7 @@ extern const char git_more_info_string[];
extern void list_common_cmds_help(void);
extern const char *help_unknown_cmd(const char *cmd);
+const char *help_mispeld_comd(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,
@@ -73,6 +74,7 @@ extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);
extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
extern int cmd_mktree(int argc, const char **argv, const char *prefix);
+extern int cmd_mispel(int argc, const char **argv, const char *prefix);
extern int cmd_mv(int argc, const char **argv, const char *prefix);
extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 807d875..2caca54 100644
--- a/git.c
+++ b/git.c
@@ -327,6 +327,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
{ "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
{ "mktree", cmd_mktree, RUN_SETUP },
+ { "mispel", cmd_mispel },
{ "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
{ "name-rev", cmd_name_rev, RUN_SETUP },
{ "pack-objects", cmd_pack_objects, RUN_SETUP },
diff --git a/help.c b/help.c
index 6c46d8b..97f0f22 100644
--- a/help.c
+++ b/help.c
@@ -296,6 +296,37 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
old->names = NULL;
}
+const char *help_mispeld_comd(const char *cmd)
+{
+ struct cmdnames main_cmds, other_cmds;
+ int i;
+
+ memset(&main_cmds, 0, sizeof(main_cmds));
+ memset(&other_cmds, 0, sizeof(main_cmds));
+ git_config(git_unknown_cmd_config, NULL);
+
+ load_command_list("git-", &main_cmds, &other_cmds);
+
+ add_cmd_list(&main_cmds, &aliases);
+ add_cmd_list(&main_cmds, &other_cmds);
+ qsort(main_cmds.names, main_cmds.cnt,
+ sizeof(main_cmds.names), cmdname_compare);
+ uniq(&main_cmds);
+
+ /* This reuses cmdname->len for similarity index */
+ for (i = 0; i < main_cmds.cnt; ++i)
+ main_cmds.names[i]->len =
+ levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);
+
+ qsort(main_cmds.names, main_cmds.cnt,
+ sizeof(*main_cmds.names), levenshtein_compare);
+
+ if (main_cmds.cnt< 2)
+ die ("Uh oh. Your system reports no Git commands at all.");
+
+ return main_cmds.names[1]->name;
+}
+
const char *help_unknown_cmd(const char *cmd)
{
int i, n, best_similarity = 0;
--
1.6.4.msysgit.0.1.g2dcf.dirty