git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git wrapper: also uses aliases to suggest mistyped commands
@ 2008-09-10 15:54 Pieter de Bie
  2008-09-10 21:44 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Pieter de Bie @ 2008-09-10 15:54 UTC (permalink / raw)
  To: Git Mailinglist, Junio C Hamano; +Cc: Pieter de Bie


Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl>
---
 help.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/help.c b/help.c
index 300cd38..24904d4 100644
--- a/help.c
+++ b/help.c
@@ -262,11 +262,15 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
 }
 
 static int autocorrect;
+static struct cmdnames aliases;
 
 static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "help.autocorrect"))
 		autocorrect = git_config_int(var,value);
+	/* Also use aliases for command lookup */
+	if (!prefixcmp(var, "alias."))
+		add_cmdname(&aliases, var + 6, strlen(var + 6));
 
 	return git_default_config(var, value, cb);
 }
@@ -280,6 +284,15 @@ static int levenshtein_compare(const void *p1, const void *p2)
 	return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
 }
 
+static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
+{
+	int i;
+	ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc);
+
+	for (i = 0; i < old->cnt; i++)
+		cmds->names[cmds->cnt++] = old->names[i];
+}
+
 const char *help_unknown_cmd(const char *cmd)
 {
 	int i, n, best_similarity = 0;
@@ -287,11 +300,13 @@ const char *help_unknown_cmd(const char *cmd)
 
 	memset(&main_cmds, 0, sizeof(main_cmds));
 	memset(&other_cmds, 0, sizeof(main_cmds));
+	memset(&aliases, 0, sizeof(aliases));
 
 	git_config(git_unknown_cmd_config, NULL);
 
 	load_command_list("git-", &main_cmds, &other_cmds);
 
+	add_cmd_list(&main_cmds, &aliases);
 	ALLOC_GROW(main_cmds.names, main_cmds.cnt + other_cmds.cnt,
 		   main_cmds.alloc);
 	memcpy(main_cmds.names + main_cmds.cnt, other_cmds.names,
-- 
1.6.0.1.346.g880d9.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-09-11 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-10 15:54 [PATCH] git wrapper: also uses aliases to suggest mistyped commands Pieter de Bie
2008-09-10 21:44 ` Junio C Hamano
2008-09-11 10:37   ` Pieter de Bie

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).