From patchwork Wed Sep 8 15:24:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC1BC433EF for ; Wed, 8 Sep 2021 15:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4677D6109E for ; Wed, 8 Sep 2021 15:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352018AbhIHPZl (ORCPT ); Wed, 8 Sep 2021 11:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348081AbhIHPZg (ORCPT ); Wed, 8 Sep 2021 11:25:36 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D3CC06175F for ; Wed, 8 Sep 2021 08:24:28 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id u19-20020a7bc053000000b002f8d045b2caso1865015wmc.1 for ; Wed, 08 Sep 2021 08:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gp44aEWKZgvTJql8gqXKwd/kYJBrfjaR6lyZoEfbONI=; b=C6/+t3JiAAJsB8/q573U28IZiiX/Pvui9hPqqkAun4XZWpIw7pf+qhTXXjrwSxPS86 JJQSsaqogAxlrI+799TD6FqW60ShhqIWpPzDVHx+wEu15WdZd9OeF4S4rzktsHD1/bWI 0JqtmfRHYKwHf1FOP5zwXbRRU+7DSmPA4tlCLO5MFlKYCdaJn5x6RpbNcVE9/ef7C092 EMHmTpFIEgHDWIVnepnxKBWLpZIMgZew1uJQ2ezcINRcBmHk+AIdV3wPM7/yYB7oHn5q +WEeOxdiDFn+HDamk9V32WBZ2H1z9+TC+QIQ1+10kMXUzi1PZiFnb5a8zbMl+ssfzqeE xd4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gp44aEWKZgvTJql8gqXKwd/kYJBrfjaR6lyZoEfbONI=; b=imNE+W7YtZA1wf2NymkngKSH841HZ1NUjpYen9AHdylBfGBbK17ljCunElvFd5XRs8 PcE/E0/bnKDD/wHTbMUR4mAM4MHkVT8BabI8NEzMWxFfqkHDUPB2k+bPvlp/NMFGDEHR YXMoLJRMzqoLuUaND0d/29/wgSfleyrCWTxaSfQDeHok8LYqIRnng70LkYMtQYB+eOAh o/yGNEWe8YmXouBxd9o3bkVYXC4vd+AFFoBChpAGlTw8+9RYKRzTFX+k3sfn0SLNCXpT ilaZX0eTEzaiN0eLIiPWKShmk+S6/iQPq0vd8fk8IAGZjr8bngYpOvi6r4JlG+XJ55ri nkpA== X-Gm-Message-State: AOAM531r8gurqTluzmwgAqNzJCexGzg3UgHWNfaM91k93ObfZpb/i7AM cnG0sfaZMk++XaWeczlk9op98eddH3vrMg== X-Google-Smtp-Source: ABdhPJzbdSYv5NgwN+Fnwtqe1ye9t/cdfjAQUD5+wZB3Pd7xp1TjUhOR77ytaut7AWGgNzf21UJfjA== X-Received: by 2002:a1c:a181:: with SMTP id k123mr4157612wme.90.1631114666920; Wed, 08 Sep 2021 08:24:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/6] help: correct the usage string in -h and documentation Date: Wed, 8 Sep 2021 17:24:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Clarify the usage string in the documentation so we group e.g. -i and --info, and add the missing short options to the "-h" output. The alignment of the second line is off now, but will be fixed with another series of mine[1]. In the meantime let's just assume that fix will make it in eventually for the purposes of this patch, if it's misaligned for a bit it doesn't matter much. 1. https://lore.kernel.org/git/cover-0.2-00000000000-20210901T110917Z-avarab@gmail.com Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 2 +- builtin/help.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index 44fe8860b3f..568a0b606f3 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git help' [-a|--all [--[no-]verbose]] [-g|--guides] - [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE] + [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] DESCRIPTION ----------- diff --git a/builtin/help.c b/builtin/help.c index b7eec06c3de..44ea2798cda 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -59,7 +59,8 @@ static struct option builtin_help_options[] = { }; static const char * const builtin_help_usage[] = { - N_("git help [--all] [--guides] [--man | --web | --info] []"), + N_("git help [-a|--all] [-g|--guides] [--[no-]verbose]]\n" + " [[-i|--info] [-m|--man] [-w|--web]] []"), NULL }; From patchwork Wed Sep 8 15:24:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE3ECC433FE for ; Wed, 8 Sep 2021 15:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAA2C610A3 for ; Wed, 8 Sep 2021 15:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352023AbhIHPZm (ORCPT ); Wed, 8 Sep 2021 11:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348356AbhIHPZh (ORCPT ); Wed, 8 Sep 2021 11:25:37 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84154C061575 for ; Wed, 8 Sep 2021 08:24:29 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id d6so3848998wrc.11 for ; Wed, 08 Sep 2021 08:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Riwawg7bkbhRneeTM2zFhUajOuQs+hSXu12hgjAMIxA=; b=NacMASg1NGKWo0TQzxvudfjWTQ1fo/RuBmqIWqthbyXQPRqyqRR+Wv06b3yK83Z5ft GrsAH/UHVOBOTm/HiYJNcgDWzSPZWEK1dc80JcJJ7m3nd1RtspB4cXlyhREfIwG9qGOQ RpGy87bi/j3dC4VvpaLEVFD+JN9MaYpPu9FUiLwqy7HiF654x5eUxdXjG/Nw0s6Luwb8 cqbaXqP9UBUFt//DE1LIbc+HXqxnWMFFcJ3RdEaSGyousBVtoXfK79DKtMYR+jxleYKR 7Uu9tjH6qa0JvOV4QpNhijCM8hfzlvArFYnPSU+VLTMJo0pJX+dJJ6fK+nGPjGCSsbqO Gptw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Riwawg7bkbhRneeTM2zFhUajOuQs+hSXu12hgjAMIxA=; b=0Snq+NCiVrB9PhOkRL60PfVzKeeLOfilvq/o/KgNyPWsRtYn7s0DCjnPYi9lTBCWrb Q2GyZMyM1T9n74knsetQoaXvYBy2w2F3Q2du+DpiC4JdGI3NqOSyhb0Au7G055crd6nc YXbLym4k9Ica0jJuu4WmO6SZ2tikdienC4U2giCLsomUvauziNW5pYukF4UEW3D7l+SG 48tPQJieHauPrIvWwrPw7/hWoiKh+Y9T5NBOOcN/Mzmrm3CvJSC+MyVqmkw8r3oOBXts tYg2JmwsflZ0QA4xsD1DbNEI85hVqBWTdTKj6sO915yu3QNFq5ko11tVRhYFOkn1tcC+ It8A== X-Gm-Message-State: AOAM531TqsBTOganrRs42q8nYXtUcARy3i11lddV+nrUfCDemChOjzpU hI9dfg1rmMrf65ZMHSzgZtMN4Cvc9ZLLAg== X-Google-Smtp-Source: ABdhPJwMkQQtDj7uqKSzdC65ARbqCYT1O5txpncuQLm0l8K0qM/amqh5Sw5MbgXTFwbzmRj69Apw8A== X-Received: by 2002:adf:b7c7:: with SMTP id t7mr4552762wre.259.1631114667853; Wed, 08 Sep 2021 08:24:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/6] help: correct usage string for "git help --guides" Date: Wed, 8 Sep 2021 17:24:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As noted in 65f98358c0c (builtin/help.c: add --guide option, 2013-04-02) and a133737b809 (doc: include --guide option description for "git help", 2013-04-02) which introduced the --guide option it cannot be combined with e.g. . Change both the usage string to reflect that, and test and assert for this behavior in the command itself. Now that we assert this in code we don't need to exhaustively describe the previous confusing behavior in the documentation either, instead of silently ignoring the provided argument we'll now error out. The comment being removed was added in 15f7d494380 (builtin/help.c: split "-a" processing into two, 2013-04-02) and is no longer applicable as explained above. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 6 +++--- builtin/help.c | 14 +++++++++----- t/t0012-help.sh | 5 +++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index 568a0b606f3..cb8e3d4da9e 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -8,8 +8,9 @@ git-help - Display help information about Git SYNOPSIS -------- [verse] -'git help' [-a|--all [--[no-]verbose]] [-g|--guides] +'git help' [-a|--all [--[no-]verbose]] [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] +'git help' [-g|--guides] DESCRIPTION ----------- @@ -58,8 +59,7 @@ OPTIONS -g:: --guides:: - Prints a list of the Git concept guides on the standard output. This - option overrides any given command or guide name. + Prints a list of the Git concept guides on the standard output. -i:: --info:: diff --git a/builtin/help.c b/builtin/help.c index 44ea2798cda..0f9dc31c40f 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -59,8 +59,9 @@ static struct option builtin_help_options[] = { }; static const char * const builtin_help_usage[] = { - N_("git help [-a|--all] [-g|--guides] [--[no-]verbose]]\n" + N_("git help [-a|--all] [--[no-]verbose]]\n" " [[-i|--info] [-m|--man] [-w|--web]] []"), + N_("git help [-g|--guides]"), NULL }; @@ -547,11 +548,17 @@ int cmd_help(int argc, const char **argv, const char *prefix) int nongit; enum help_format parsed_help_format; const char *page; + int standalone = 0; argc = parse_options(argc, argv, prefix, builtin_help_options, builtin_help_usage, 0); parsed_help_format = help_format; + /* Options that take no further arguments */ + standalone = show_config || show_guides; + if (standalone && argc) + usage_with_options(builtin_help_usage, builtin_help_options); + if (show_all) { git_config(git_help_config, NULL); if (verbose) { @@ -580,11 +587,8 @@ int cmd_help(int argc, const char **argv, const char *prefix) if (show_guides) list_guides_help(); - if (show_all || show_guides) { + if (show_all || standalone) { printf("%s\n", _(git_more_info_string)); - /* - * We're done. Ignore any remaining args - */ return 0; } diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 5679e29c624..6e01da614f0 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -34,6 +34,11 @@ test_expect_success 'basic help commands' ' git help -a >/dev/null ' +test_expect_success 'invalid usage' ' + test_expect_code 129 git help -c git-add && + test_expect_code 129 git help -g git-add +' + test_expect_success "works for commands and guides by default" ' configure_help && git help status && From patchwork Wed Sep 8 15:24:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7448C433F5 for ; Wed, 8 Sep 2021 15:24:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A09FD6109E for ; Wed, 8 Sep 2021 15:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352028AbhIHPZn (ORCPT ); Wed, 8 Sep 2021 11:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348652AbhIHPZj (ORCPT ); Wed, 8 Sep 2021 11:25:39 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70FDC061757 for ; Wed, 8 Sep 2021 08:24:30 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n5so3845227wro.12 for ; Wed, 08 Sep 2021 08:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t5LbAozKjshRVXrGUscdqiWPP24wJcMZ3huXfGwYW8k=; b=i3/6PKNQfEoWBv69S4Bom4uHYNWk0Q9MbWamGe9nkLPOB8BkJM3Hqh+lUz4pJD+4om blJK7amZRhkyx6pjslRBbo7zHPNYxT4quleNFAFGBgGoCJTJOyw+5LHR0nNuoANpnG2v iXB/A4bAGsA2uxfnhFEA7yT7GjzrUx5fW4og/2e7S0WCTXeLxisLOoHEtX/xTPGPn0T7 hm34fQsty8lStJat/74gFSMlx8emA3WS3Xou6nwzsChzjfx/6Wt+xt5omllyuyPYYd8b J+X5yMYaYzG4yB0BdZjsRM8lJjIjTzMjydAjcqFWmEtOu/n4Us7JcWi+LW09/cJezybz 6y5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t5LbAozKjshRVXrGUscdqiWPP24wJcMZ3huXfGwYW8k=; b=te/njrQ5iZZuCm9JiwjiHtztQZPv0aJ6EpiS5U1wqnLhQbNQG/x8KUwLB0WR5XnD9T dpBnH/5HKZRFcsaJs6toV1kegAihdUItuzGQCMHF/KP2DoUySvA9/mt0lQ12pcjTdSuw 4DZ1WBu+sdG1NQsIIQucX+2myxK2+qRhaCVuM7dOv7I/OYRRhDgHedaIPk6BxsaJXXZm sZLeoUjypnXQHBBNMpI9PECb+pWKyLwPDmCWxCS7Rz6x9CyVyorXQ4UBH7AbmXMez5jt mIpfJKMqf2wP7A4LoflAfSGUeEIxn9jRa5ZUJAOQ0iRJFQzJevE/s0FGE3242ZQSYeiy 83/Q== X-Gm-Message-State: AOAM531nvAgUJtqaXqen5er7j0kGCcgur6Uq2EafWC3NSSeTiqlD0/pg WQIc/73vTVLDrxy+fMq4mzoAtmuX+bHx/w== X-Google-Smtp-Source: ABdhPJzKa2mRhZype1ni72rkPWUcnMLzOG9wdBKKIwYdw5+C+GJtU+MV9KNgX5MXYvfnuILzh77LFg== X-Received: by 2002:adf:fc43:: with SMTP id e3mr4684809wrs.436.1631114668760; Wed, 08 Sep 2021 08:24:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/6] help tests: add test for --config output Date: Wed, 8 Sep 2021 17:24:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a missing test for checking what the --config output added in ac68a93fd2 (help: add --config to list all available config, 2018-05-26) looks like. We should not be emitting anything except config variables and the brief usage information at the end here. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0012-help.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 6e01da614f0..94d1f481c8b 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -78,6 +78,19 @@ test_expect_success 'git help -g' ' test_i18ngrep "^ tutorial " help.output ' +test_expect_success 'git help -c' ' + git help -c >help.output && + cat >expect <<-\EOF && + + '"'"'git help config'"'"' for more information + EOF + grep -v -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" \ + help.output >actual && + test_cmp expect actual +' + test_expect_success 'generate builtin list' ' git --list-cmds=builtins >builtins ' From patchwork Wed Sep 8 15:24:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24D71C433FE for ; Wed, 8 Sep 2021 15:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00D236115C for ; Wed, 8 Sep 2021 15:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348652AbhIHPZo (ORCPT ); Wed, 8 Sep 2021 11:25:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348669AbhIHPZj (ORCPT ); Wed, 8 Sep 2021 11:25:39 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A6C1C06175F for ; Wed, 8 Sep 2021 08:24:31 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso1851696wmi.5 for ; Wed, 08 Sep 2021 08:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R4WEpNsRtGsOLPdzFG29r+7FZrBMrdX51URTaA1o6hg=; b=SsRzU5CGz70NwTJyJCa2pTGulaQ0CzoTv+wliqlR3ANbgHxfn++YtLtmBY0idJAklO dw1o5BvDRS3ytgemKPVhG2/vta+sW7wXOpqgLgEAM15ox+gFIpRUrhUFJ1WjnPxJiGDj Ft3k2Cfgtr7Nc/nRoYyiRj3jHUjkR7T/bYEWNTpUb0ozXZYrGTU+HVB9DqnUGM7pIgNI ws/0jOfLWhNjXvh4rNO9dZdiP/vJJsHl2yMomfHbTAJSoZbJVstPrFjqzuy/8fBD1n3O Xa3CJAGtzF5SrIIt/w+N4XiHJk/3ZVrgr0lDK9KOfxzxpJa0sVhBqS8DSINyQic2WX2v FNsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4WEpNsRtGsOLPdzFG29r+7FZrBMrdX51URTaA1o6hg=; b=SqgG5WrGIpsxDSie5O8Xcnh0cdKNs18pVGWjqvVyattV38iAT16F8r9xNSwUNbnJcM k6zBC7+kqhJBDx8nC/XxFC2PrHBmk4KsdD2BWzXerS7eshlRWoD+Mt+/+guWUyz1cy9E udi5htIeH34Ky2dMhsNcJ1YQaH+mPC9wFmWyk0Qe5nLnAIT+1ohvoNLHP9eUjituzyEl yC+mKG11aAxFUpjIzwSg+1l+9Aoz/sAz3R03J1QyVIYXfIHRkzATQrALOBp0YreGLjNq pkco4VIhre61lPC7uVRytgtPJWRoGmOxAZMj6FpqajuS7hcixXE3G1f6t8HdCDHWivLB csog== X-Gm-Message-State: AOAM533SneRfa/hA1Ar2GhGC58pvY+PeLSarow5JEXGRBJkDXyIAcaUc uU60MYZEHKLsnitLgetL69CNuYHkymzAgg== X-Google-Smtp-Source: ABdhPJzosTPbk0yL50i2TtUzBL4rF7it8vIOPm24A9Kj2PnV1HTwgBf2AwJUB1d8RLIitpCtC8bvKQ== X-Received: by 2002:a05:600c:2114:: with SMTP id u20mr4233418wml.65.1631114669852; Wed, 08 Sep 2021 08:24:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/6] help: refactor "for_human" control flow in cmd_help() Date: Wed, 8 Sep 2021 17:24:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of having two lines that call list_config_help(for_human) let's setup the pager and print the trailer conditionally. This makes it clearer at a glance how the two differ in behavior. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/help.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index 0f9dc31c40f..0737b22069b 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -574,13 +574,12 @@ int cmd_help(int argc, const char **argv, const char *prefix) if (show_config) { int for_human = show_config == 1; - if (!for_human) { - list_config_help(for_human); - return 0; - } - setup_pager(); + if (for_human) + setup_pager(); list_config_help(for_human); - printf("\n%s\n", _("'git help config' for more information")); + if (for_human) + printf("\n%s\n", _("'git help config' for more information")); + return 0; } From patchwork Wed Sep 8 15:24:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B3AC433F5 for ; Wed, 8 Sep 2021 15:24:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8866361100 for ; Wed, 8 Sep 2021 15:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352044AbhIHPZq (ORCPT ); Wed, 8 Sep 2021 11:25:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352008AbhIHPZk (ORCPT ); Wed, 8 Sep 2021 11:25:40 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B73C061575 for ; Wed, 8 Sep 2021 08:24:32 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id q26so3865885wrc.7 for ; Wed, 08 Sep 2021 08:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O6PlMg7VzgYa625bIaTA+7GKpto1SMiOt57OduwRSVs=; b=pQltzwgSkHcM8WlLNOggci0mQGnsAE2zE6Es/pBAy/GbfOHe9+wQxZdGoiC6fOticW V7Du8V07v6yNxJLeD7oxbPeiLrjhloWUBKlfxC66RZM021B5IkrWKAlArZyv2/34u4fX ufd0xZd5llf1eCm24JKixVuXO2YmOiGTqn/azhYtLEB62Je0cbH9KC2QzzAaw8X+0O+i a/DvUvdYcxwmYOV/njAvcFxL/8QzuSYvGm2SCcwSaz4TNBrqRvbvL+WO9bQcX7S5MaSf EmNeF+7sLbsEn/MacV7sKbxk3xspk59ifaEnJU+gubGOq3oSE6/D9O8QlTsIf/IrHHUT 3m0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O6PlMg7VzgYa625bIaTA+7GKpto1SMiOt57OduwRSVs=; b=5S3cpsc7npzEVvtj2oIgMpcNLCGzxrBfNRmY6h/qxP78NS+9MTNJwvjmvVELDMRahh sM2idJbZF5lFCG4dBF9n32w4q5GWgjUg5GgfG0LLLq3FulsKl3LmaVQRi8MFzEK2Yxwq FOUWs24yhVtStfURTkUFDA41IIQRa00UkYOrgvLMhSWZp6eaeNfg+AvIUTcPbh/euDYx cWq0tNFZRAC9OLElznmV1Z+0AQnGn/738xxw/3lZhh72Q5nwfF1Ytd/DMhIEorS0w48i VATiS37FWZyO2Rj5t+4KE2xdRDLcxM/pmfspGXcOyizMWMPlyGRKa/pvslt47+WGTd+A +N+A== X-Gm-Message-State: AOAM532WdzZ3m2heTnVmt0KJUBhwMd0ENt/ihtJMiN9Z+Q+EUsNRY0Up ztCxztjPMD7Ex+T/GvvIrGYlGI/y+8XVTg== X-Google-Smtp-Source: ABdhPJyM1EAanUUAlBYIAsYojaLAAGuLuaFc+s0Tp1n16lFps5UAzCTF1Hm6jGuESudvRiDt7mmLug== X-Received: by 2002:adf:eb81:: with SMTP id t1mr2828948wrn.245.1631114670772; Wed, 08 Sep 2021 08:24:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/6] help: correct logic error in combining --all and --config Date: Wed, 8 Sep 2021 17:24:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a bug in the --config option that's been there ever since its introduction in 3ac68a93fd2 (help: add --config to list all available config, 2018-05-26). Die when --all and --config are combined, combining them doesn't make sense. The code for the --config option when combined with an earlier refactoring done to support the --guide option in 65f98358c0c (builtin/help.c: add --guide option, 2013-04-02) would cause us to take the "--all" branch early and ignore the --config option. Let's instead list these as incompatible, both in the synopsis and help output, and enforce it in the code itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 1 + builtin/help.c | 27 ++++++++++++++++++--------- t/t0012-help.sh | 5 ++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index cb8e3d4da9e..96d5f598b4b 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -11,6 +11,7 @@ SYNOPSIS 'git help' [-a|--all [--[no-]verbose]] [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] 'git help' [-g|--guides] +'git help' [-c|--config] DESCRIPTION ----------- diff --git a/builtin/help.c b/builtin/help.c index 0737b22069b..83f71d6765e 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -62,6 +62,7 @@ static const char * const builtin_help_usage[] = { N_("git help [-a|--all] [--[no-]verbose]]\n" " [[-i|--info] [-m|--man] [-w|--web]] []"), N_("git help [-g|--guides]"), + N_("git help [-c|--config]"), NULL }; @@ -549,18 +550,26 @@ int cmd_help(int argc, const char **argv, const char *prefix) enum help_format parsed_help_format; const char *page; int standalone = 0; + int need_config = 0; argc = parse_options(argc, argv, prefix, builtin_help_options, builtin_help_usage, 0); parsed_help_format = help_format; + /* Incompatible options */ + if (show_all + !!show_config + show_guides > 1) + usage_with_options(builtin_help_usage, builtin_help_options); + /* Options that take no further arguments */ standalone = show_config || show_guides; if (standalone && argc) usage_with_options(builtin_help_usage, builtin_help_options); - if (show_all) { + need_config = show_all || show_config; + if (need_config) git_config(git_help_config, NULL); + + if (show_all) { if (verbose) { setup_pager(); list_all_cmds_help(); @@ -571,6 +580,14 @@ int cmd_help(int argc, const char **argv, const char *prefix) list_commands(colopts, &main_cmds, &other_cmds); } + if (show_guides) + list_guides_help(); + + if (show_all || show_guides) { + printf("%s\n", _(git_more_info_string)); + return 0; + } + if (show_config) { int for_human = show_config == 1; @@ -583,14 +600,6 @@ int cmd_help(int argc, const char **argv, const char *prefix) return 0; } - if (show_guides) - list_guides_help(); - - if (show_all || standalone) { - printf("%s\n", _(git_more_info_string)); - return 0; - } - if (!argv[0]) { printf(_("usage: %s%s"), _(git_usage_string), "\n\n"); list_common_cmds_help(); diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 94d1f481c8b..68e7f57470e 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -36,7 +36,10 @@ test_expect_success 'basic help commands' ' test_expect_success 'invalid usage' ' test_expect_code 129 git help -c git-add && - test_expect_code 129 git help -g git-add + test_expect_code 129 git help -g git-add && + + test_expect_code 129 git help -a -c && + test_expect_code 129 git help -g -c ' test_expect_success "works for commands and guides by default" ' From patchwork Wed Sep 8 15:24:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12481355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A060C433FE for ; Wed, 8 Sep 2021 15:24:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F0B961100 for ; Wed, 8 Sep 2021 15:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352068AbhIHPZr (ORCPT ); Wed, 8 Sep 2021 11:25:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348081AbhIHPZl (ORCPT ); Wed, 8 Sep 2021 11:25:41 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A61C061757 for ; Wed, 8 Sep 2021 08:24:33 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id n14-20020a05600c3b8e00b002f8bd2f8ab6so1915899wms.5 for ; Wed, 08 Sep 2021 08:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SmQ+EeoJ9K1n74LHFORCMMUvelmeWz1cD+PpeeiUIvM=; b=SwOfaHAeUO0AOpcJEHJ1zZljm3YjScI4SDNRks186+St+NcbJ2vsIZzZp/vdPfKaaP GvrrNV0QkmeKrugu+kFj+E0waiVKivelX4iEe+TlqPBaMT1Xa1ypoobBMB3QZm52EdaW uneZCpONwYEcTtbIildiR3GVg7ON55YZTG6Js8yl4U3Ntsm8IYo93dNUeO0D7C30Fvsa tgeY8WGgJbIUgnEMoBqTxgQ9pN18eDTqGVZSD7mfa6+x6EEiuA01NUH2vYGxJFpFICrv hQPtaMmmEAfj5EAwE8wKu718A1miTcVnop3ecgX/9Xg9hMCEx9FADDnay4ITJoO6NDnv p1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SmQ+EeoJ9K1n74LHFORCMMUvelmeWz1cD+PpeeiUIvM=; b=zX1TyTk9V9gJz93ZKy9clHk1yh8AHeZVgm++Nt3MNkMJccJLifbbgbMXDRKPbmvyRV jPmGddlWJaLIXRzDK/HFSEHfWFURI8pdE3XSOJ6JKLHwRC26dgCpPVmVlIZi74qX3Ejn ygvtg2+ktkCTjavgKhABmfg3Xewut7SaNs2+c3ABFJsqiYqnjQDXeiXRJlygFRm87njm BW4DCa6sk4kfZv3Kf6flnBiLl8nKsLigrKyWVG/IDVB3XbY/T9Y5pjg7/LLnkwgZnCWo GRJ+Jz9ZmFA0A+BwBydSkin+d/F32MjHc9R0ed2/SiNd/e8l1K6q1Naoj+2SXLGq7Pyl ZhxA== X-Gm-Message-State: AOAM531xZovQkUiHjqxeRdtRleFMBoxiVA/d42FwBjOexGinnBWVG23E DreZWSDKbCiFtrBwjqKjIkI+Isb2oRzzNA== X-Google-Smtp-Source: ABdhPJwD2e1DkbCHbzdCSmU//GKeuv2h1EMqh96GCmeJvKuOL9wFTGi4SvFOWr0tnRhAkwoQgXpKNQ== X-Received: by 2002:a1c:2705:: with SMTP id n5mr4168967wmn.176.1631114672013; Wed, 08 Sep 2021 08:24:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x21sm2365240wmi.15.2021.09.08.08.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 08:24:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 6/6] help / completion: make "git help" do the hard work Date: Wed, 8 Sep 2021 17:24:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.825.g2bf60429931 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "help" builtin has been able to emit configuration variables since e17ca926371 (completion: drop the hard coded list of config vars, 2018-05-26), but it hasn't produced exactly the format the completion script wanted. Let's do that. We got partway there in 2675ea1cc0f (completion: use 'sort -u' to deduplicate config variable names, 2019-08-13) and d9438873c4d (completion: deduplicate configuration sections, 2019-08-13), but after both we still needed some sorting, de-duplicating and awk post-processing of the list. We can instead simply do the relevant parsing ourselves (we were doing most of it already), and call string_list_remove_duplicates() after already sorting the list, so the caller doesn't need to invoke "sort -u". This changes the output of the section list to emit lines like "alias" instead of "alias.". The dot suffix is better done as an argument to __gitcomp(). This means that we'll have the list_config_help() function do a bit more work, let's switch its "for_human" to passing a full "show_config", but as an enum type so we can have the compiler check what values we're expecting to get. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/help.c | 67 ++++++++++++++++++-------- contrib/completion/git-completion.bash | 21 ++++---- t/t0012-help.sh | 24 +++++++++ 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index 83f71d6765e..b33ef27ac79 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -38,7 +38,12 @@ static const char *html_path; static int show_all = 0; static int show_guides = 0; -static int show_config; +enum show_config_type { + SHOW_CONFIG_UNSET = 0, + SHOW_CONFIG_HUMAN, + SHOW_CONFIG_VARS, + SHOW_CONFIG_SECTIONS, +} show_config; static int verbose = 1; static unsigned int colopts; static enum help_format help_format = HELP_FORMAT_NONE; @@ -48,7 +53,10 @@ static struct option builtin_help_options[] = { OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")), OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")), OPT_BOOL('c', "config", &show_config, N_("print all configuration variable names")), - OPT_SET_INT_F(0, "config-for-completion", &show_config, "", 2, PARSE_OPT_HIDDEN), + OPT_SET_INT_F(0, "config-for-completion-vars", &show_config, "", + SHOW_CONFIG_VARS, PARSE_OPT_HIDDEN), + OPT_SET_INT_F(0, "config-for-completion-sections", &show_config, "", + SHOW_CONFIG_SECTIONS, PARSE_OPT_HIDDEN), OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN), OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"), HELP_FORMAT_WEB), @@ -73,7 +81,7 @@ struct slot_expansion { int found; }; -static void list_config_help(int for_human) +static void list_config_help(enum show_config_type type) { struct slot_expansion slot_expansions[] = { { "advice", "*", list_config_advices }, @@ -91,6 +99,8 @@ static void list_config_help(int for_human) const char **p; struct slot_expansion *e; struct string_list keys = STRING_LIST_INIT_DUP; + struct string_list keys_uniq = STRING_LIST_INIT_DUP; + struct string_list_item *item; int i; for (p = config_name_list; *p; p++) { @@ -121,34 +131,48 @@ static void list_config_help(int for_human) for (i = 0; i < keys.nr; i++) { const char *var = keys.items[i].string; const char *wildcard, *tag, *cut; + const char *dot = NULL; + struct strbuf sb = STRBUF_INIT; - if (for_human) { + switch (type) { + case SHOW_CONFIG_HUMAN: puts(var); continue; + case SHOW_CONFIG_SECTIONS: + dot = strchr(var, '.'); + break; + case SHOW_CONFIG_VARS: + break; + case SHOW_CONFIG_UNSET: + BUG("should not get SHOW_CONFIG_UNSET here"); } - wildcard = strchr(var, '*'); tag = strchr(var, '<'); - if (!wildcard && !tag) { - puts(var); + if (!dot && !wildcard && !tag) { + string_list_append(&keys_uniq, var); continue; } - if (wildcard && !tag) + if (dot) + cut = dot; + else if (wildcard && !tag) cut = wildcard; else if (!wildcard && tag) cut = tag; else cut = wildcard < tag ? wildcard : tag; - /* - * We may produce duplicates, but that's up to - * git-completion.bash to handle - */ - printf("%.*s\n", (int)(cut - var), var); + strbuf_add(&sb, var, cut - var); + string_list_append(&keys_uniq, sb.buf); + strbuf_release(&sb); + } string_list_clear(&keys, 0); + string_list_remove_duplicates(&keys_uniq, 0); + for_each_string_list_item(item, &keys_uniq) + puts(item->string); + string_list_clear(&keys_uniq, 0); } static enum help_format parse_help_format(const char *format) @@ -588,13 +612,16 @@ int cmd_help(int argc, const char **argv, const char *prefix) return 0; } - if (show_config) { - int for_human = show_config == 1; - - if (for_human) - setup_pager(); - list_config_help(for_human); - if (for_human) + switch (show_config) { + case SHOW_CONFIG_UNSET: + break; + case SHOW_CONFIG_HUMAN: + setup_pager(); + /* fallthrough */ + case SHOW_CONFIG_VARS: + case SHOW_CONFIG_SECTIONS: + list_config_help(show_config); + if (show_config == SHOW_CONFIG_HUMAN) printf("\n%s\n", _("'git help config' for more information")); return 0; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8108eda1e86..19b8a172878 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2503,7 +2503,14 @@ __git_config_vars= __git_compute_config_vars () { test -n "$__git_config_vars" || - __git_config_vars="$(git help --config-for-completion | sort -u)" + __git_config_vars="$(git help --config-for-completion-vars)" +} + +__git_config_sections= +__git_compute_config_sections () +{ + test -n "$__git_config_sections" || + __git_config_sections="$(git help --config-for-completion-sections)" } # Completes possible values of various configuration variables. @@ -2717,16 +2724,8 @@ __git_complete_config_variable_name () __gitcomp "$__git_config_vars" "" "$cur_" "$sfx" ;; *) - __git_compute_config_vars - __gitcomp "$(echo "$__git_config_vars" | - awk -F . '{ - sections[$1] = 1 - } - END { - for (s in sections) - print s "." - } - ')" "" "$cur_" + __git_compute_config_sections + __gitcomp "$__git_config_sections" "" "$cur_" "." ;; esac } diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 68e7f57470e..6d169ae3cbd 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -94,6 +94,30 @@ test_expect_success 'git help -c' ' test_cmp expect actual ' +test_expect_success 'git help --config-for-completion-vars' ' + git help -c >human && + grep -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" human | + sed -e "s/\*.*//" -e "s/<.*//" | + sort -u >human.munged && + + git help --config-for-completion-vars >vars && + test_cmp human.munged vars +' + +test_expect_success 'git help --config-for-completion-sections' ' + git help -c >human && + grep -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" human | + sed -e "s/\..*//" | + sort -u >human.munged && + + git help --config-for-completion-sections >sections && + test_cmp human.munged sections +' + test_expect_success 'generate builtin list' ' git --list-cmds=builtins >builtins '