git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Adeodato Simó" <dato@net.com.org.es>
To: git@vger.kernel.org, gitster@pobox.com
Cc: "Adeodato Simó" <dato@net.com.org.es>
Subject: [PATCH] git.c: make autocorrected aliases work
Date: Sun,  4 Jan 2009 18:08:19 +0100	[thread overview]
Message-ID: <1231088899-11943-1-git-send-email-dato@net.com.org.es> (raw)

help_unknown_cmd() is able to autocorrect a command to an alias, and not
only to internal or external commands. However, main() was not passing the
autocorrected command through handle_alias(), hence it failed if it was an
alias.

This commit makes the autocorrected command go through handle_alias, once
handle_internal_command() and execv_dashed_external() have been tried. Since
this is done twice in main() now, moved that logic to a new run_argv()
function.

Signed-off-by: Adeodato Simó <dato@net.com.org.es>
---
 git.c |   46 +++++++++++++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/git.c b/git.c
index e0d9071..f443b4c 100644
--- a/git.c
+++ b/git.c
@@ -416,12 +416,35 @@ static void execv_dashed_external(const char **argv)
 	strbuf_release(&cmd);
 }
 
+static int run_argv(int *argcp, const char ***argv)
+{
+	int done_alias = 0;
+
+	while (1) {
+		/* See if it's an internal command */
+		handle_internal_command(*argcp, *argv);
+
+		/* .. then try the external ones */
+		execv_dashed_external(*argv);
+
+		/* It could be an alias -- this works around the insanity
+		 * of overriding "git log" with "git show" by having
+		 * alias.log = show
+		 */
+		if (done_alias || !handle_alias(argcp, argv))
+			break;
+		done_alias = 1;
+	}
+
+	return done_alias;
+}
+
 
 int main(int argc, const char **argv)
 {
 	const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
 	char *slash = (char *)cmd + strlen(cmd);
-	int done_alias = 0;
+	int was_alias = 0;
 
 	/*
 	 * Take the basename of argv[0] as the command
@@ -478,32 +501,17 @@ int main(int argc, const char **argv)
 	 */
 	setup_path();
 
-	while (1) {
-		/* See if it's an internal command */
-		handle_internal_command(argc, argv);
-
-		/* .. then try the external ones */
-		execv_dashed_external(argv);
-
-		/* It could be an alias -- this works around the insanity
-		 * of overriding "git log" with "git show" by having
-		 * alias.log = show
-		 */
-		if (done_alias || !handle_alias(&argc, &argv))
-			break;
-		done_alias = 1;
-	}
+	was_alias = run_argv(&argc, &argv);
 
 	if (errno == ENOENT) {
-		if (done_alias) {
+		if (was_alias) {
 			fprintf(stderr, "Expansion of alias '%s' failed; "
 				"'%s' is not a git-command\n",
 				cmd, argv[0]);
 			exit(1);
 		}
 		argv[0] = help_unknown_cmd(cmd);
-		handle_internal_command(argc, argv);
-		execv_dashed_external(argv);
+		run_argv(&argc, &argv);
 	}
 
 	fprintf(stderr, "Failed to run command '%s': %s\n",
-- 
1.6.1.62.g677ca

             reply	other threads:[~2009-01-04 17:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-04 17:08 Adeodato Simó [this message]
2009-01-04 17:12 ` [PATCH v2] git.c: make autocorrected aliases work Adeodato Simó
2009-01-04 17:16   ` [PATCH v2 resend] " Adeodato Simó
2009-01-04 17:28     ` Alexander Potashev
2009-01-06  8:19       ` Junio C Hamano
2009-01-06  8:19     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231088899-11943-1-git-send-email-dato@net.com.org.es \
    --to=dato@net.com.org.es \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).