* [PATCH] Add the utterly important 'mispel' command
@ 2009-10-03 22:41 Johannes Schindelin
2009-10-04 6:52 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2009-10-03 22:41 UTC (permalink / raw)
To: git; +Cc: spearce, peff, gitster
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Add the utterly important 'mispel' command
2009-10-03 22:41 [PATCH] Add the utterly important 'mispel' command Johannes Schindelin
@ 2009-10-04 6:52 ` Jeff King
2009-10-04 10:52 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2009-10-04 6:52 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, spearce, gitster
On Sun, Oct 04, 2009 at 12:41:55AM +0200, Johannes Schindelin wrote:
> --- 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,
Hmph. This hunk doesn't apply to Shawn's master, and your blob sha1 is
not in my repository for a 3-way merge. ;P
Also, I think there is a bug:
$ git mispel show-branc
error: You probably meant show-index
Or is it intentional for it to throw the user off track?
Let this be a lesson, kids: don't drink and code.
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add the utterly important 'mispel' command
2009-10-04 6:52 ` Jeff King
@ 2009-10-04 10:52 ` Johannes Schindelin
2009-10-04 13:41 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2009-10-04 10:52 UTC (permalink / raw)
To: Jeff King; +Cc: git, spearce, gitster
Hi,
On Sun, 4 Oct 2009, Jeff King wrote:
> On Sun, Oct 04, 2009 at 12:41:55AM +0200, Johannes Schindelin wrote:
>
> > --- 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,
>
> Hmph. This hunk doesn't apply to Shawn's master, and your blob sha1 is
> not in my repository for a 3-way merge. ;P
Hmm. It might be based on 4msysgit.git's 'devel' branch.
> Also, I think there is a bug:
>
> $ git mispel show-branc
> error: You probably meant show-index
>
> Or is it intentional for it to throw the user off track?
>
> Let this be a lesson, kids: don't drink and code.
Well, the command is called "mispel", not "autocorrect". So I think you
misunderstood the purpose of the patch.
Let this be a lesson, kids: don't review GitTogether patches before you
had a drink.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add the utterly important 'mispel' command
2009-10-04 10:52 ` Johannes Schindelin
@ 2009-10-04 13:41 ` Jeff King
0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2009-10-04 13:41 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, spearce, gitster
On Sun, Oct 04, 2009 at 12:52:09PM +0200, Johannes Schindelin wrote:
> Well, the command is called "mispel", not "autocorrect". So I think you
> misunderstood the purpose of the patch.
OK, well, then I can rail against the quality of your commit message. ;)
> Let this be a lesson, kids: don't review GitTogether patches before you
> had a drink.
Heh.
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-10-04 13:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-03 22:41 [PATCH] Add the utterly important 'mispel' command Johannes Schindelin
2009-10-04 6:52 ` Jeff King
2009-10-04 10:52 ` Johannes Schindelin
2009-10-04 13:41 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).