{"thread":{"id":"49630","subject":"[PATCH 1/2] alias: Rework comment about processing aliases","startedAt":"2018-10-21T18:46:14Z","lastAt":"2018-10-21T18:46:14Z","messageCount":2,"participants":["Tim Schumacher"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"361099","messageId":"20181021184619.6688-1-timschumi@gmx.de","threadId":"49630","inReplyTo":null,"subject":"[PATCH 1/2] alias: Rework comment about processing aliases","fromName":"Tim Schumacher","fromEmail":"timschumi@gmx.de","sentAt":"2018-10-21T18:46:18Z","receivedAt":"2018-10-21T18:46:14Z","isPatch":true,"sender":{"key":"timschumi@gmx.de","avatar":"https://avatars.githubusercontent.com/u/16820960?v=4"},"body":"The old comment's message wasn't really clear and it was in a weird\nlocation for it to talk about the alias handling process as a whole.\n\nRephrase and move it to the top of the while() loop to make the\nmessage more clear.\n---\n git.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 6a81ed6fc..0f77bce7d 100644\n--- a/git.c\n+++ b/git.c\n@@ -718,6 +718,11 @@ static int run_argv(int *argcp, const char ***argv)\n \tstruct strbuf env = STRBUF_INIT;\n \n \tinit_cmd_history(&env, &cmd_list);\n+\n+\t/*\n+\t * Check if argv[0] is a command before seeing if it is an\n+\t * alias to avoid taking over existing commands\n+\t */\n \twhile (1) {\n \t\t/*\n \t\t * If we tried alias and futzed with our environment,\n@@ -753,11 +758,6 @@ static int run_argv(int *argcp, const char ***argv)\n \n \t\tadd_cmd_history(&env, &cmd_list, *argv[0]);\n \n-\t\t/*\n-\t\t * It could be an alias -- this works around the insanity\n-\t\t * of overriding \"git log\" with \"git show\" by having\n-\t\t * alias.log = show\n-\t\t */\n \t\tif (!handle_alias(argcp, argv))\n \t\t\tbreak;\n \t\tdone_alias = 1;\n-- \n2.19.1.450.ga4b8ab536\n\n"},{"id":"361100","messageId":"20181021184619.6688-2-timschumi@gmx.de","threadId":"49630","inReplyTo":"20181021184619.6688-1-timschumi@gmx.de","subject":"[PATCH 2/2] alias: Move checking code into a seperate function","fromName":"Tim Schumacher","fromEmail":"timschumi@gmx.de","sentAt":"2018-10-21T18:46:19Z","receivedAt":"2018-10-21T18:46:14Z","isPatch":true,"sender":{"key":"timschumi@gmx.de","avatar":"https://avatars.githubusercontent.com/u/16820960?v=4"},"body":"We can save a few indentations (and possibly brain cells of people\nthat don't care about that code) by moving the code that checks for\na looping alias (and that prints the error message if one is found)\ninto a seperate function.\n\nThis restores a lot of readablility to the run_argv() function as\nwell, because it was only concerned with the high-level routing of\nthe command and alias logic before.\n---\n git.c | 40 +++++++++++++++++++++++-----------------\n 1 file changed, 23 insertions(+), 17 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 0f77bce7d..b6fdd9708 100644\n--- a/git.c\n+++ b/git.c\n@@ -710,11 +710,32 @@ static void add_cmd_history(struct strbuf *env, struct string_list *cmd_list,\n \tsetenv(COMMAND_HISTORY_ENVIRONMENT, env->buf, 1);\n }\n \n+static void cmd_unique_or_die(struct string_list *cmd_list, const char *cmd)\n+{\n+\tstruct string_list_item *seen;\n+\n+\tseen = unsorted_string_list_lookup(cmd_list, cmd);\n+\tif (!seen)\n+\t\treturn;\n+\n+\tint i;\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tfor (i = 0; i < cmd_list->nr; i++) {\n+\t\tstruct string_list_item *item = &cmd_list->items[i];\n+\t\tstrbuf_addf(&sb, \"\\n  %s\", item->string);\n+\t\tif (item == seen)\n+\t\t\tstrbuf_addstr(&sb, \" <==\");\n+\t\telse if (i == cmd_list->nr - 1)\n+\t\t\tstrbuf_addstr(&sb, \" ==>\");\n+\t}\n+\tdie(_(\"alias loop detected: expansion of '%s' does not terminate:%s\"),\n+\t    cmd_list->items[0].string, sb.buf);\n+}\n+\n static int run_argv(int *argcp, const char ***argv)\n {\n \tint done_alias = 0;\n \tstruct string_list cmd_list = STRING_LIST_INIT_DUP;\n-\tstruct string_list_item *seen;\n \tstruct strbuf env = STRBUF_INIT;\n \n \tinit_cmd_history(&env, &cmd_list);\n@@ -739,22 +760,7 @@ static int run_argv(int *argcp, const char ***argv)\n \t\t/* .. then try the external ones */\n \t\texecv_dashed_external(*argv);\n \n-\t\tseen = unsorted_string_list_lookup(&cmd_list, *argv[0]);\n-\t\tif (seen) {\n-\t\t\tint i;\n-\t\t\tstruct strbuf sb = STRBUF_INIT;\n-\t\t\tfor (i = 0; i < cmd_list.nr; i++) {\n-\t\t\t\tstruct string_list_item *item = &cmd_list.items[i];\n-\n-\t\t\t\tstrbuf_addf(&sb, \"\\n  %s\", item->string);\n-\t\t\t\tif (item == seen)\n-\t\t\t\t\tstrbuf_addstr(&sb, \" <==\");\n-\t\t\t\telse if (i == cmd_list.nr - 1)\n-\t\t\t\t\tstrbuf_addstr(&sb, \" ==>\");\n-\t\t\t}\n-\t\t\tdie(_(\"alias loop detected: expansion of '%s' does\"\n-\t\t\t      \" not terminate:%s\"), cmd_list.items[0].string, sb.buf);\n-\t\t}\n+\t\tcmd_unique_or_die(&cmd_list, *argv[0]);\n \n \t\tadd_cmd_history(&env, &cmd_list, *argv[0]);\n \n-- \n2.19.1.450.ga4b8ab536\n\n"}]}