From patchwork Tue Dec 11 14:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10723931 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 923A13E9D for ; Tue, 11 Dec 2018 14:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 804A92AFC4 for ; Tue, 11 Dec 2018 14:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7435C2B2BA; Tue, 11 Dec 2018 14:58: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 8F3952B2DF for ; Tue, 11 Dec 2018 14:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbeLKO6N (ORCPT ); Tue, 11 Dec 2018 09:58:13 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41863 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbeLKO6N (ORCPT ); Tue, 11 Dec 2018 09:58:13 -0500 Received: by mail-pg1-f196.google.com with SMTP id 70so6747561pgh.8 for ; Tue, 11 Dec 2018 06:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2zAVFgByiYaZhRv1KMxW+b14Ef/qtVYjHxNui6FH3Ms=; b=U8qH0AyNGaw5QJhJBpVoqNULzGezyupGhdhJF77dMa18VtmmV/bPquql6S98D7ruwu 9CwRyFVLmsUVDOmmk7erKRJyEuTwJ9TN1W3K7gqmTTqSfLawXjh7GiHWB5ujy8SI7kTS KkvkjH5YfrwIt14UIzJ/+1Cr8kRSC1GISH7w1C+93wjZ34qB2RsMJwXH0oOmYYBaV7SQ JufV62Nd7CVphhnl6wUyVWsKyoSnWS4N9yCUeMsoEhby5gjWlZwN0D4EsTCxDRmI6h0R uPDyQDZc/+IxxE+sJgcH9rVTY+Us8SM+eYkjN6PwxOF7LDnqFmMawnX3GuF9juH8jJCp YnVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2zAVFgByiYaZhRv1KMxW+b14Ef/qtVYjHxNui6FH3Ms=; b=f9o/pY/qORbzKE8ogNN/i86TV46aQaUpd7eK5Yt6dE3rYojqIKAwWq6rEkHe4Kqv85 roAxV6lslMLVn6Ik6lm0fkaItuVpqcppyNaVpK6phJHEPGC41WkDxZzzZED+m4ariqEu nw0VCKQGgIoL66GYaJN6BSfoS7Ke78q6kxRC7mrXatYeZv3+bZ7vL6EEpYX86BRAQCQI TyjoSVLl/I99Z5tiICUaiIhM4Bcc9v0oVKx/AuIm6G7Gvk/Ikt2CMeyxGZC82MV3Fvw2 82kz7Zi0VTC+/JOYMMm8nnKSQECa+LSFNifALyR/NLPEva1N/3S0XPJ2cvpA7kVEWhnU Ud3A== X-Gm-Message-State: AA+aEWZTc38RvMG2zGvMN5m0PbP06ku44IUFGuNwKzFLAi9fh1qJjH/X bbmdewp3dFOV16TVh7RBy48rtph5 X-Google-Smtp-Source: AFSGD/VjFJRD8zX8IFygZod0vzM0t0j1hAksHcNfESF/mEA3udckvc6N2NvqcPf2vdQ/OX7Fg0rHBg== X-Received: by 2002:a62:1bd7:: with SMTP id b206mr16509072pfb.213.1544540291810; Tue, 11 Dec 2018 06:58:11 -0800 (PST) Received: from [127.0.0.1] ([40.112.139.188]) by smtp.gmail.com with ESMTPSA id 84sm33462181pfk.134.2018.12.11.06.58.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 06:58:11 -0800 (PST) Date: Tue, 11 Dec 2018 06:58:11 -0800 (PST) X-Google-Original-Date: Tue, 11 Dec 2018 14:58:06 GMT Message-Id: <850cd5d15abe5b8a4356efe86ba81bc032278dce.1544540287.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 2/2] help -a: handle aliases with long names gracefully Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin We take pains to determine the longest command beforehand, so that we can align the category column after printing the command names. However, then we re-use that value when printing the aliases. If any alias name is longer than the longest command name, we consequently try to add a negative number of spaces (but `mput_char()` does not expect any negative values and simply decrements until the value is 0, i.e. it tries to add close to 2**31 spaces). Let's fix this by adjusting the `longest` variable before printing the aliases. This fixes https://github.com/git-for-windows/git/issues/1975. Signed-off-by: Johannes Schindelin --- help.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/help.c b/help.c index 4745b32299..ff05fd22df 100644 --- a/help.c +++ b/help.c @@ -83,8 +83,9 @@ static void print_command_list(const struct cmdname_help *cmds, for (i = 0; cmds[i].name; i++) { if (cmds[i].category & mask) { + size_t len = strlen(cmds[i].name); printf(" %s ", cmds[i].name); - mput_char(' ', longest - strlen(cmds[i].name)); + mput_char(' ', longest > len ? longest - len : 1); puts(_(cmds[i].help)); } } @@ -526,6 +527,13 @@ void list_all_cmds_help(void) git_config(get_alias, &alias_list); string_list_sort(&alias_list); + + for (i = 0; i < alias_list.nr; i++) { + size_t len = strlen(alias_list.items[i].string); + if (longest < len) + longest = len; + } + if (alias_list.nr) { printf("\n%s\n", _("Command aliases")); ALLOC_ARRAY(aliases, alias_list.nr + 1);