From 940208a771066229bc6a486f6a058e332b71cfe4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 30 Jul 2008 01:16:58 +0200 Subject: builtin-help: make some internal functions available to other builtins Make load_command_list() capable of filtering for a given prefix and loading into a pair of "struct cmdnames" supplied by the caller. Make the static add_cmdname(), exclude_cmds() and is_in_cmdlist() functions non-static. Make list_commands() accept a custom title, and work from a pair of "struct cmdnames" supplied by the caller. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- help.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 help.h (limited to 'help.h') diff --git a/help.h b/help.h new file mode 100644 index 000000000..d614e5491 --- /dev/null +++ b/help.h @@ -0,0 +1,23 @@ +#ifndef HELP_H +#define HELP_H + +struct cmdnames { + int alloc; + int cnt; + struct cmdname { + size_t len; + char name[FLEX_ARRAY]; + } **names; +}; + +unsigned int load_command_list(const char *prefix, + struct cmdnames *main_cmds, + struct cmdnames *other_cmds); +void add_cmdname(struct cmdnames *cmds, const char *name, int len); +/* Here we require that excludes is a sorted list. */ +void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); +int is_in_cmdlist(struct cmdnames *c, const char *s); +void list_commands(const char *title, unsigned int longest, + struct cmdnames *main_cmds, struct cmdnames *other_cmds); + +#endif /* HELP_H */ -- cgit v1.2.1 From 3d78d1f18f211fd3d3e95977dee85a17a2aeb16c Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 2 Aug 2008 10:08:38 +0200 Subject: Builtin git-help. This patch splits out git-help's functions to builtin-help.c and leaves only functions used by other builtins in help.c. First this removes git-help's functions from libgit which are not interesting for other builtins, second this makes 'git help help' work again. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- help.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'help.h') diff --git a/help.h b/help.h index d614e5491..3f1ae89dd 100644 --- a/help.h +++ b/help.h @@ -10,6 +10,12 @@ struct cmdnames { } **names; }; +static inline void mput_char(char c, unsigned int num) +{ + while(num--) + putchar(c); +} + unsigned int load_command_list(const char *prefix, struct cmdnames *main_cmds, struct cmdnames *other_cmds); -- cgit v1.2.1 From e321180ed3e22120e30bb350a5adecbe959e1241 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 28 Aug 2008 19:15:33 +0200 Subject: Remove calculation of the longest command name from where it is not used Just calculate it where it is needed - it is cheap and trivial, as all the lengths are already there (stored when creating the command lists). Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- help.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'help.h') diff --git a/help.h b/help.h index 3f1ae89dd..2733433bf 100644 --- a/help.h +++ b/help.h @@ -16,14 +16,14 @@ static inline void mput_char(char c, unsigned int num) putchar(c); } -unsigned int load_command_list(const char *prefix, +void load_command_list(const char *prefix, struct cmdnames *main_cmds, struct cmdnames *other_cmds); void add_cmdname(struct cmdnames *cmds, const char *name, int len); /* Here we require that excludes is a sorted list. */ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); int is_in_cmdlist(struct cmdnames *c, const char *s); -void list_commands(const char *title, unsigned int longest, - struct cmdnames *main_cmds, struct cmdnames *other_cmds); +void list_commands(const char *title, struct cmdnames *main_cmds, + struct cmdnames *other_cmds); #endif /* HELP_H */ -- cgit v1.2.1 From 8af84dadb142f7321ff0ce8690385e99da8ede2f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 31 Aug 2008 15:50:23 +0200 Subject: 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' [...] Signed-off-by: Johannes Schindelin Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- help.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'help.h') diff --git a/help.h b/help.h index 3f1ae89dd..5fc789270 100644 --- a/help.h +++ b/help.h @@ -5,7 +5,7 @@ struct cmdnames { int alloc; int cnt; struct cmdname { - size_t len; + size_t len; /* also used for similarity index in help.c */ char name[FLEX_ARRAY]; } **names; }; -- cgit v1.2.1