From patchwork Sun Oct 21 18:46:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Schumacher X-Patchwork-Id: 10651407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 203DB13A4 for ; Sun, 21 Oct 2018 18:46:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04740287D1 for ; Sun, 21 Oct 2018 18:46:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB85B287E5; Sun, 21 Oct 2018 18:46:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A9C0287D1 for ; Sun, 21 Oct 2018 18:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728032AbeJVDB0 (ORCPT ); Sun, 21 Oct 2018 23:01:26 -0400 Received: from mout.gmx.net ([212.227.15.15]:37641 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727825AbeJVDB0 (ORCPT ); Sun, 21 Oct 2018 23:01:26 -0400 Received: from p2520la.lan ([217.235.92.200]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lkwc9-1fe92d2D9p-00alPv; Sun, 21 Oct 2018 20:46:10 +0200 Received: from p2520la.lan ([217.235.92.200]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lkwc9-1fe92d2D9p-00alPv; Sun, 21 Oct 2018 20:46:10 +0200 From: Tim Schumacher To: git@vger.kernel.org Cc: timschumi@gmx.de Subject: [PATCH 1/2] alias: Rework comment about processing aliases Date: Sun, 21 Oct 2018 20:46:18 +0200 Message-Id: <20181021184619.6688-1-timschumi@gmx.de> X-Mailer: git-send-email 2.19.1.450.ga4b8ab536 MIME-Version: 1.0 X-Provags-ID: V03:K1:7PuzMI7Vbu3W6MMinr8Ke/P1Y65DJlmCDHbZ5OhtotMzUu4D0c/ 2g/An44dx00OWlZnX9KcheKJhVPUhRTSg4Byc7gvb274BI+sKgxfQ4Efv9cd/8Cu0nYPbfe HJWr//Cu5VZ3QLT4ws+X3YFXoCE7DDH0eplg5dwcRKoKVbuh0WMGURgSYpirrBVAamJHZTZ e3DvXjlSDpS8hzbpVFYkg== X-UI-Out-Filterresults: notjunk:1;V01:K0:g0kJDg3e2dg=:1diPSB5dPeq1Usy5CnSk+A AlmPK7lsLx2DRPDnXUmty4Wve+mlm2OFlodNcDvJ9YxcZrB17J+OJQck5dRp/PjIxOrQzVYzq cwvlgMNsveD1ZG0RjX6XG8qQ3x0mCjeBfkNZMb+oj1ZE3jkiSBEUROeH/4NUsDMWgeMFVLQQ4 QatdMATtgfz8Dm2Wp7knJm4/RyFNrL7hmh2bWDGD3LBS9uYZ0Tz5aN5BbemFWcg5MKkKQZQv2 fh58SYDwv9CD1vopb9inj8lCn6EwCKKddLshH8PU2o+Sow4JvvjyWAA4mwBLLf9dq7kZwz/uZ zIZrzXredalnDVnGbz4YBW0n9mXwwlCxnXCdXBibSRdJ2bjp0z+6azenFQIDVJkmaWTZI7jbe YRAnh9ytWLA6UmNiTwQa2XdLWLHdaj+rV3iGtwBEX6aEPH+clSSDzehd4DvMixsEI+w9Kcdlq XOcuk97XNCq+cJ2AodW6idikWlcmLiOwq6l0dce0xESzqlILOTySlc9NeQbWJauMGDgV+XGTW Lhk4h77qocsIifCEwfcZUe+4fTC50nlF4KM2zy9n6NU3G8rFX9EBOBCfdCiuIs2eei2limKPc GjfHG+Jwxbi6Lb/i7wMPu73Bribsfl6fN3OIHFGwTG8wRKHvGEho/U3uEr376/E7RimNM8Ysm u+CSYnUX4Zuej45Y/qHv4hwSQ/kh8RMEEJx+MckbsYxiOOtxVxhPJS2AQVCThH5kiC6MuWfjc jeNB6IWgKLRtAliBn6EZTTsYIdrkiyaGs97TuUZP6FeBqfFIetXzXXI3o/dWzil7fh96dIwEo fgNUrFznhl1i85DcLAvuRjdoEn/FA== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; From patchwork Sun Oct 21 18:46:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Schumacher X-Patchwork-Id: 10651409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DF5713A4 for ; Sun, 21 Oct 2018 18:46:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D8B9287D1 for ; Sun, 21 Oct 2018 18:46:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2083F287D5; Sun, 21 Oct 2018 18:46:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B83E287D2 for ; Sun, 21 Oct 2018 18:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728045AbeJVDB1 (ORCPT ); Sun, 21 Oct 2018 23:01:27 -0400 Received: from mout.gmx.net ([212.227.15.19]:50069 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbeJVDB0 (ORCPT ); Sun, 21 Oct 2018 23:01:26 -0400 Received: from p2520la.lan ([217.235.92.200]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MbOoG-1fvXOw3CXk-00Ioza; Sun, 21 Oct 2018 20:46:10 +0200 Received: from p2520la.lan ([217.235.92.200]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MbOoG-1fvXOw3CXk-00Ioza; Sun, 21 Oct 2018 20:46:10 +0200 From: Tim Schumacher To: git@vger.kernel.org Cc: timschumi@gmx.de Subject: [PATCH 2/2] alias: Move checking code into a seperate function Date: Sun, 21 Oct 2018 20:46:19 +0200 Message-Id: <20181021184619.6688-2-timschumi@gmx.de> X-Mailer: git-send-email 2.19.1.450.ga4b8ab536 In-Reply-To: <20181021184619.6688-1-timschumi@gmx.de> References: <20181021184619.6688-1-timschumi@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:deAdfgkfrRfr68uCpq6hhE0kkyUlyURjBcpP8FXjPPDooFod/PL Rg63pL8wzQGl/hIxWYKoz1AAi65IUMxi6BK9/SD0Utl03TBJVMqbE+Jm+eowBktLO4ECdlO iH/QswPCxZf9LEllCpJR5j6gz61BGZZ6j2w7LY1aCgW/uu6dLpmFin0OiwerVKuJGbOMg5E n5AXwEYK7AbHgZ3gtWnvg== X-UI-Out-Filterresults: notjunk:1;V01:K0:yUZV1FKSkvE=:fBisPAB4Qy48pLg39efZyU WVb76zZutTLaR9Km4emuiAxT53zXY5Ph7rigs9F+jPbEbrCXjd4mEZdrtbof6Y0/rpu7t3Ibm EHE81OOaHwg1jNYgn/VXABnm7FX4uM+oXBr6zbiTyQ7isGLc9XihxkPevDkG0ZGbrj4egr0DH gEiy5c50GzOzIQWKA35Fbh38bLlKukKSR+BEKN+rJAOt6lSyMz0sWJMifafwUwi2AYvwoLho/ LySF6QU65eGKmlaIQIP/E4shkTg/h0mbgTf/FQjO3/VJwijVnRmFrrCrNqiS1BMk767fsDZRY dEZZVsAx6OXcNPE8hGpd+S6E67mDN9ueHZL+NwiVIJNpQ6KkWYl4qLbU98DGp5CCDxQksTZpw 4+rmK9Zwk6KWNu+NJJr8frgjj1k3n5yK4NqON4YWXC4xo1wTlg+xljfnKwON06Be++4L7MlPV 4LqyGfJGGJw/s5W3UKyY1bOOm7WMzRS3mOvQDmlSzA4aPkJhhGo35U9qWnpiw7Av0GtpxlStR Hq5G66veqeWse/36Q2JFl8H/PJ7rzerFSHlhse+IcAeBxI8LTkErHbR9xjduCkxo/YgKN12tV Y+2L8RflNiK0ZPVXBtlY+UX0bovl2IcWolagKKegbFTM9xl7uvenDrn2FAH6VH+g2AQP2JuOn Gvz6PA3KIELOtIILNHUw6gIcNPdnCA50BaM//hXaBBBfMuiW4lLrf7+GpaAizN4f5e8L19VaY tHkAAbJ6dw7TUyO9NJz6ryPb5HZmdjLUxRanPXbFHwT7qwu/BufZarERpA26c9a5qelCx9kqt gfF+KTJEc6YB+9nIH4/G68kqceJ0g== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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]);