git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] alias: Rework comment about processing aliases
@ 2018-10-21 18:46 Tim Schumacher
  2018-10-21 18:46 ` [PATCH 2/2] alias: Move checking code into a seperate function Tim Schumacher
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Schumacher @ 2018-10-21 18:46 UTC (permalink / raw
  To: git; +Cc: timschumi

The old comment's message wasn't really clear and it was in a weird
location for it to talk about the alias handling process as a whole.

Rephrase and move it to the top of the while() loop to make the
message more clear.
---
 git.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/git.c b/git.c
index 6a81ed6fc..0f77bce7d 100644
--- a/git.c
+++ b/git.c
@@ -718,6 +718,11 @@ static int run_argv(int *argcp, const char ***argv)
 	struct strbuf env = STRBUF_INIT;
 
 	init_cmd_history(&env, &cmd_list);
+
+	/*
+	 * Check if argv[0] is a command before seeing if it is an
+	 * alias to avoid taking over existing commands
+	 */
 	while (1) {
 		/*
 		 * If we tried alias and futzed with our environment,
@@ -753,11 +758,6 @@ static int run_argv(int *argcp, const char ***argv)
 
 		add_cmd_history(&env, &cmd_list, *argv[0]);
 
-		/*
-		 * It could be an alias -- this works around the insanity
-		 * of overriding "git log" with "git show" by having
-		 * alias.log = show
-		 */
 		if (!handle_alias(argcp, argv))
 			break;
 		done_alias = 1;
-- 
2.19.1.450.ga4b8ab536


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

* [PATCH 2/2] alias: Move checking code into a seperate function
  2018-10-21 18:46 [PATCH 1/2] alias: Rework comment about processing aliases Tim Schumacher
@ 2018-10-21 18:46 ` Tim Schumacher
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Schumacher @ 2018-10-21 18:46 UTC (permalink / raw
  To: git; +Cc: timschumi

We can save a few indentations (and possibly brain cells of people
that don't care about that code) by moving the code that checks for
a looping alias (and that prints the error message if one is found)
into a seperate function.

This restores a lot of readablility to the run_argv() function as
well, because it was only concerned with the high-level routing of
the command and alias logic before.
---
 git.c | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/git.c b/git.c
index 0f77bce7d..b6fdd9708 100644
--- a/git.c
+++ b/git.c
@@ -710,11 +710,32 @@ static void add_cmd_history(struct strbuf *env, struct string_list *cmd_list,
 	setenv(COMMAND_HISTORY_ENVIRONMENT, env->buf, 1);
 }
 
+static void cmd_unique_or_die(struct string_list *cmd_list, const char *cmd)
+{
+	struct string_list_item *seen;
+
+	seen = unsorted_string_list_lookup(cmd_list, cmd);
+	if (!seen)
+		return;
+
+	int i;
+	struct strbuf sb = STRBUF_INIT;
+	for (i = 0; i < cmd_list->nr; i++) {
+		struct string_list_item *item = &cmd_list->items[i];
+		strbuf_addf(&sb, "\n  %s", item->string);
+		if (item == seen)
+			strbuf_addstr(&sb, " <==");
+		else if (i == cmd_list->nr - 1)
+			strbuf_addstr(&sb, " ==>");
+	}
+	die(_("alias loop detected: expansion of '%s' does not terminate:%s"),
+	    cmd_list->items[0].string, sb.buf);
+}
+
 static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
 	struct string_list cmd_list = STRING_LIST_INIT_DUP;
-	struct string_list_item *seen;
 	struct strbuf env = STRBUF_INIT;
 
 	init_cmd_history(&env, &cmd_list);
@@ -739,22 +760,7 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
-		if (seen) {
-			int i;
-			struct strbuf sb = STRBUF_INIT;
-			for (i = 0; i < cmd_list.nr; i++) {
-				struct string_list_item *item = &cmd_list.items[i];
-
-				strbuf_addf(&sb, "\n  %s", item->string);
-				if (item == seen)
-					strbuf_addstr(&sb, " <==");
-				else if (i == cmd_list.nr - 1)
-					strbuf_addstr(&sb, " ==>");
-			}
-			die(_("alias loop detected: expansion of '%s' does"
-			      " not terminate:%s"), cmd_list.items[0].string, sb.buf);
-		}
+		cmd_unique_or_die(&cmd_list, *argv[0]);
 
 		add_cmd_history(&env, &cmd_list, *argv[0]);
 
-- 
2.19.1.450.ga4b8ab536


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

end of thread, other threads:[~2018-10-21 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-21 18:46 [PATCH 1/2] alias: Rework comment about processing aliases Tim Schumacher
2018-10-21 18:46 ` [PATCH 2/2] alias: Move checking code into a seperate function Tim Schumacher

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).