From patchwork Sat Sep 11 19:09:00 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: 12486603 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.8 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 87D49C433F5 for ; Sat, 11 Sep 2021 19:10:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CF626108B for ; Sat, 11 Sep 2021 19:10:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233900AbhIKTLp (ORCPT ); Sat, 11 Sep 2021 15:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233817AbhIKTLl (ORCPT ); Sat, 11 Sep 2021 15:11:41 -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 3C254C061757 for ; Sat, 11 Sep 2021 12:10:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id u15so1767177wru.6 for ; Sat, 11 Sep 2021 12:10: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=yKOtTE4VdYJSOQFubwW3r0efBX9cH5DrpT3H43dQvbo=; b=OS7oaalkS/Y8sFVYbXyOnXsSRGVxMeWRGKZPi0Mvuvn5eUQGWxlOPXrDgpuRk/v7EX RwP2gfmtDAxvMXbo9vOEAy5ohenmCbpCVMDVK1FlkA12A7bmbQb3kMW+A/V8JPOfhg6t cLyOud8pQaMVx+IcJushkQfyvUZIqJVbsgnkMmCe59b80/XnhLgDIqMG6RFEasTIXOwh B6Jyu80I3d4MFKRWsLIWLW8UcjPv7AgYHq2YDjzkI3qperUAeJct3kaqMd8dYT2Ah6g2 kKhwTeR6Sl+LaR4E6e5YZEuc0FyPNE0NlLkT3Y8deaQc9q34qJK3LmkVVpF4+Z1Yv1R9 toUA== 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=yKOtTE4VdYJSOQFubwW3r0efBX9cH5DrpT3H43dQvbo=; b=hD2XiUsI5XzyyBw7VWiJ0hTor7Uzoek7ptNKCCsTR3I+6jWmsN1fjNrH7cOWXXurzT E5/VwH3zHRBogyK4ev92bCQqyDEm7v2dUWnWg+0Rfg64Sor516EQvCS5oJfaACeqrUH1 ofiBvM8Z4trKpVhxBa/6Seo2ZdrYRGulLjssjfe71uGXZQD45scrGzAQrSeSiedHNQj9 Qbn2byDu1hI0ImZMjnBxEkb3kiyRE9MKZlsIKsoXdmiPJhgKPtSxcQSra7xHNNK1Iu2k SdqlaHrk60Uq/a8J5r893/q00VsVJNRasHmj0J28yTyYcsWRMGb1T8fhV3X64xiqcEkt xP8g== X-Gm-Message-State: AOAM532vb4B+T/tKBkI/H02YxkzwWQ2Hy21wHnbj+DrrsfZ9u/jiCki1 E7qBSzfYAt+P7elJb4wnpb4VqQKjMdEMOQ== X-Google-Smtp-Source: ABdhPJx4m2Dgb0GZi2UVOBB0d8ljVug/O+G8XPZ8+m+rRfza09BtZNsh/Vy/b4bVQTARWFAzxvsl7A== X-Received: by 2002:a5d:4cc6:: with SMTP id c6mr3544333wrt.108.1631387426615; Sat, 11 Sep 2021 12:10:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/6] credential-cache{,--daemon}: don't build under NO_UNIX_SOCKETS Date: Sat, 11 Sep 2021 21:09:00 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the implementation of b5dd96b70ac (make credential helpers builtins, 2020-08-13) to not build these at all under NO_UNIX_SOCKETS. This is the easiest way to get rid of one out of two users of an obscure parse_options() API I'm trying to get rid of. It does mean that the goal of emitting a custom error message in b5dd96b70ac is being eliminated, but per [1] that seems to be an OK direction to go in. By not compiling it at all it won't be included in the "struct cmd_struct", and therefore will also be omitted from "--list-cmds=builtins". 1. https://lore.kernel.org/git/cover-v2-0.6-00000000000-20210910T153146Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 3 +++ builtin.h | 2 ++ builtin/credential-cache--daemon.c | 21 --------------------- builtin/credential-cache.c | 21 --------------------- git.c | 2 ++ 5 files changed, 7 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 429c276058d..ecde3367fa2 100644 --- a/Makefile +++ b/Makefile @@ -1086,8 +1086,10 @@ BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o BUILTIN_OBJS += builtin/config.o BUILTIN_OBJS += builtin/count-objects.o +ifndef NO_UNIX_SOCKETS BUILTIN_OBJS += builtin/credential-cache--daemon.o BUILTIN_OBJS += builtin/credential-cache.o +endif BUILTIN_OBJS += builtin/credential-store.o BUILTIN_OBJS += builtin/credential.o BUILTIN_OBJS += builtin/describe.o @@ -1693,6 +1695,7 @@ ifdef NO_INET_PTON endif ifdef NO_UNIX_SOCKETS BASIC_CFLAGS += -DNO_UNIX_SOCKETS + EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon else LIB_OBJS += unix-socket.o LIB_OBJS += unix-stream-server.o diff --git a/builtin.h b/builtin.h index 16ecd5586f0..9b3f173bd7c 100644 --- a/builtin.h +++ b/builtin.h @@ -140,8 +140,10 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix); int cmd_config(int argc, const char **argv, const char *prefix); int cmd_count_objects(int argc, const char **argv, const char *prefix); int cmd_credential(int argc, const char **argv, const char *prefix); +#ifndef NO_UNIX_SOCKETS int cmd_credential_cache(int argc, const char **argv, const char *prefix); int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix); +#endif int cmd_credential_store(int argc, const char **argv, const char *prefix); int cmd_describe(int argc, const char **argv, const char *prefix); int cmd_diff_files(int argc, const char **argv, const char *prefix); diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c index 4c6c89ab0de..7785412dea4 100644 --- a/builtin/credential-cache--daemon.c +++ b/builtin/credential-cache--daemon.c @@ -1,8 +1,5 @@ #include "builtin.h" #include "parse-options.h" - -#ifndef NO_UNIX_SOCKETS - #include "config.h" #include "tempfile.h" #include "credential.h" @@ -299,21 +296,3 @@ int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix) return 0; } - -#else - -int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix) -{ - const char * const usage[] = { - "git credential-cache--daemon [options] ", - "", - "credential-cache--daemon is disabled in this build of Git", - NULL - }; - struct option options[] = { OPT_END() }; - - argc = parse_options(argc, argv, prefix, options, usage, 0); - die(_("credential-cache--daemon unavailable; no unix socket support")); -} - -#endif /* NO_UNIX_SOCKET */ diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index e8a74157471..64942978650 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -1,8 +1,5 @@ #include "builtin.h" #include "parse-options.h" - -#ifndef NO_UNIX_SOCKETS - #include "credential.h" #include "string-list.h" #include "unix-socket.h" @@ -137,21 +134,3 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) return 0; } - -#else - -int cmd_credential_cache(int argc, const char **argv, const char *prefix) -{ - const char * const usage[] = { - "git credential-cache [options] ", - "", - "credential-cache is disabled in this build of Git", - NULL - }; - struct option options[] = { OPT_END() }; - - argc = parse_options(argc, argv, prefix, options, usage, 0); - die(_("credential-cache unavailable; no unix socket support")); -} - -#endif /* NO_UNIX_SOCKETS */ diff --git a/git.c b/git.c index 18bed9a9964..7c696e06ecf 100644 --- a/git.c +++ b/git.c @@ -513,8 +513,10 @@ static struct cmd_struct commands[] = { { "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG }, { "count-objects", cmd_count_objects, RUN_SETUP }, { "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT }, +#ifndef NO_UNIX_SOCKETS { "credential-cache", cmd_credential_cache }, { "credential-cache--daemon", cmd_credential_cache_daemon }, +#endif { "credential-store", cmd_credential_store }, { "describe", cmd_describe, RUN_SETUP }, { "diff", cmd_diff, NO_PARSEOPT }, From patchwork Sat Sep 11 19:09:01 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: 12486605 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.8 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 E6B26C433EF for ; Sat, 11 Sep 2021 19:10:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB386610A3 for ; Sat, 11 Sep 2021 19:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233919AbhIKTLs (ORCPT ); Sat, 11 Sep 2021 15:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233804AbhIKTLm (ORCPT ); Sat, 11 Sep 2021 15:11:42 -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 22953C06175F for ; Sat, 11 Sep 2021 12:10:29 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t8so2789747wrq.4 for ; Sat, 11 Sep 2021 12:10: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=509hFfgLXq5rsuWWiRmsRiQFHNvqLlTn3QulSzySEGQ=; b=ghAubXGHaxz7kc20LHIz0Xa5JC4W3KG9fIzH4/5ijkHx837u7lBPQ9wuDCuwkBX6YB tFwdWcvilSIGp9tvEdOVnv3OaDUCZCoIfDxskURs2dW5EXg6HGqXSEkl7SlMZyQyaS85 6+6rStZviq0ZeTV+pONuP+4eshpMEhtu6tcrPromkDCb33gCoY8Gs4jOnhvfnsG7UXNl sIZowcbJlGIdnH8UpPiL416fR6XNXIGeLCerpTWwmveP7dOjKv+u8fqxjBgi0Dp++jKb 5rGBzOL4NJm+nkNxelEQs0Ydb6dv65F7i79aGc6sahHPzH9nzsGA7bphI8oKysoVoMXX +wKw== 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=509hFfgLXq5rsuWWiRmsRiQFHNvqLlTn3QulSzySEGQ=; b=D16yD7fVSUxaRkgNBWxhnaw8WUgPFRmFXHgYMsUsu1gqbmSpyTKMRMaeix5w7nt8nu nJ28sTHfub/L9CO3pbIfxVkbkiGGGDzgaQEdswsQm1s0+E0TUwj0606xuLn8aRiLhwLw ls0z4sD6yfBG1XYuKXCGYJ2xmjGh9lawzZ5l42/5kmJQq2nJZTPuOolgKwTJnMSUNVL/ hrNSHDgktOFuFbVntg1xIX9Z9LzfgixsLRM1HTSp8Yf6x8VedztjkINqIc5a51RFfmoj UPuHLLjK+6MbrX2EjZNqOiFeGkbso4O9oveM0Xyxm2EcOkEkU+fdJuD/1njaQI5M9c4s a9xg== X-Gm-Message-State: AOAM5325R8OIa1ECT3zwqRmFb/Xz8atrVXDgetFjyKNRoeGADXmDVTke XPu+VI5OqyLDn8iwjKbCdpYRAJBzDot2/w== X-Google-Smtp-Source: ABdhPJziXv4H4ZuZUb0zMLbBF4keJaDTMvTy3XvSYwISIgVCw15TrKzqnBbPvgDnzRJumeSOu9MgMQ== X-Received: by 2002:adf:80eb:: with SMTP id 98mr4242212wrl.348.1631387427405; Sat, 11 Sep 2021 12:10:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/6] blame: replace usage end blurb with better option spec Date: Sat, 11 Sep 2021 21:09:01 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "git blame -h" output to be consistent with "git bundle -h"'s, i.e. before this we'd emit: $ git blame -h usage: git blame [] [] [] [--] are documented in git-rev-list(1) [...] Now instead of that we'll emit: $ git blame -h usage: git blame [] [] [] [--] [...] This makes it consistent with the usage spec used for "git bundle": $ git bundle -h usage: git bundle create [] [...] The use of this in "blame" dated back to 5817da01434 (git-blame: migrate to incremental parse-option [1/2], 2008-07-08), and the use in "bundle" to 2e0afafebd8 (Add git-bundle: move objects and references by archive, 2007-02-22). Once we get rid of this special case we can also use usage_msg_opt() to emit the error message we'd get on an invalid "-L " argument, which means we can get rid of the old-style "blame_usage" variable entirely. This makes the output friendlier, before we'd emit say: $ git blame -L1,2,3,4 Makefile usage: git blame [] [] [] [--] $ Now we'll instead emit: $ git blame -L1,2,3,4 Makefile fatal: Invalid -L parameter usage: git blame [] [] [] [--] [...] $ The "[...]" there elides the "git blame" option summary. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/blame.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 641523ff9af..e469829bc76 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -29,12 +29,8 @@ #include "refs.h" #include "tag.h" -static char blame_usage[] = N_("git blame [] [] [] [--] "); - static const char *blame_opt_usage[] = { - blame_usage, - "", - N_(" are documented in git-rev-list(1)"), + N_("git blame [] [] [] [--] "), NULL }; @@ -1107,7 +1103,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) nth_line_cb, &sb, lno, anchor, &bottom, &top, sb.path, the_repository->index)) - usage(blame_usage); + usage_msg_opt(_("Invalid -L parameter"), + blame_opt_usage, options); if ((!lno && (top || bottom)) || lno < bottom) die(Q_("file %s has only %lu line", "file %s has only %lu lines", From patchwork Sat Sep 11 19:09:02 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: 12486607 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.8 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,URIBL_BLOCKED,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 63363C433EF for ; Sat, 11 Sep 2021 19:10:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 470E86108B for ; Sat, 11 Sep 2021 19:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233938AbhIKTLw (ORCPT ); Sat, 11 Sep 2021 15:11:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233864AbhIKTLn (ORCPT ); Sat, 11 Sep 2021 15:11:43 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AD73C061574 for ; Sat, 11 Sep 2021 12:10:30 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so3889833wmq.1 for ; Sat, 11 Sep 2021 12:10: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=zgbq52nKtIjlI7AfAq29aPRtgmtqwNjH66dToxtx3yk=; b=VouKC0oWtwQXHEpflXkPz7ltCYL2IwKuNfae1on/5wM0RIAMz3+ybvLWJtXUxsQ3mO 8aBW1qtgkjgQbe36afXR95HuR/VVjbNiORdQLZHRhMGgWxZofe/fZX/YBRQv13OioiJP k5PQ9pCZwADNuv3y4uWuGykr2Dv//gH4pqqGVZqg4i54G8Qn40sbOKvKMjlTpEqFppVM 0uUGYF2P8LmQWNqlw8jdNReLJk1rReU9uL3Buoi9J8KRYUBQ58qUK9mTbpQDpDpU1izv mizSSJ6sV+AzsDZXpxmerki8dNgAwhK/88WWclZsrgZphY7REgh2/YhkUJYTKa0FxjW+ sO9w== 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=zgbq52nKtIjlI7AfAq29aPRtgmtqwNjH66dToxtx3yk=; b=nZ3nFvKl2Icr0znGeYgCJcegVfLXi1Ns29nvaPQZAzmHGVoLvZBEUID1Dw1WgwIbvw IA9FXthJi733gLTSQziEjGEpw8hy3bU4UrOcTy/onOabivHD/rQkr3xzL7HCKlIwaEI3 sKRiyJSnB8866VFKKa7eX7eVZucpkcFV2KZcimhrLrMWuUvwC55yaxt7plrTVSRK+sRi i6COJkiJxcfbbP7nr8akQG1kQbnUmFlDBEtuWku/4IGL7N+bU/2vd1cGR40Zw/L0NWWH RFQ/ArfJ+gdYyjncXwgwU+d3nwu3sA6DXo5BB0fRykodbmL26ZG5YMXBh9FpTtInCstU KM+A== X-Gm-Message-State: AOAM533vu2/by7I9VKjaaIozET963k8GicquGmi8VN0FWM6IKqrhivux A8ieFLUkR0zc5Q/WCLFZcf2JFp9aKQiFMA== X-Google-Smtp-Source: ABdhPJyE7yKuS358OLzSFxwqDDJkFYaf7e3DwCd48mJb89DHLSmeepDeUT6x5yCqiMNajCWQ/DamUA== X-Received: by 2002:a1c:4c14:: with SMTP id z20mr3782177wmf.82.1631387428244; Sat, 11 Sep 2021 12:10:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/6] parse-options: stop supporting "" in the usagestr array Date: Sat, 11 Sep 2021 21:09:02 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The strings in the the "usagestr" array have special handling for the empty string dating back to f389c808b67 (Rework make_usage to print the usage message immediately, 2007-10-14). We'll prefix all strings after the first one with "or: ". Then if we encountered a "" we'll emit all strings after that point verbatim without any "or: " prefixing. In the preceding commits we got rid of the two users of this undocumented part of the API. Let's remove it in preparation for improving the output emitted by usage_with_options_internal(). I think we might want to use this in the future, but in that case we'll be much better off with an API that emulates the non-parse_options() way that git.c does this. That git.c code uses a separate "git_usage_string" and "git_more_info_string". See b7d9681974e (Print info about "git help COMMAND" on git's main usage pages, 2008-06-06). By splitting the two up we can emit something in the middle, as indeed git.c does. I'd like our "git -h" info to be more helpful, and I'd also like parse_options() to handle the "git" command itself, because of the limitations of how this was done in usage_with_options_internal() we couldn't migrate a caller like git.c to parse_options(). So let's just remove this for now, it has no users, and once we want to do this again we can simply add another argument to the relevant functions, or otherwise hook into things so that we can print something at the end and/or middle. It's possible that this change introduce breakage somewhere. We'd only catch these cases at runtime, and the "git rev-parse --parseopt" command is used by shellscripts, see bac199b7b17 (Update git-sh-setup(1) to allow transparent use of git-rev-parse --parseopt, 2007-11-04). I've grepped the codebase for "OPTIONS_SPEC", "char.*\*.*usage\[\]" etc. I'm fairly sure there no outstanding users of this functionality. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rev-parse.c | 3 +++ parse-options.c | 8 +------- t/helper/test-parse-options.c | 2 -- t/t0040-parse-options.sh | 2 -- t/t1502-rev-parse-parseopt.sh | 34 ++++++++++++++++++---------------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 22c4e1a4ff0..aeebfd52805 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -436,7 +436,10 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) for (;;) { if (strbuf_getline(&sb, stdin) == EOF) die(_("premature end of input")); + if (!sb.len) + die(_("empty lines are not permitted before the `--' separator")); ALLOC_GROW(usage, unb + 1, usz); + if (!strcmp("--", sb.buf)) { if (unb < 1) die(_("no usage string given before the `--' separator")); diff --git a/parse-options.c b/parse-options.c index 2abff136a17..950a8279beb 100644 --- a/parse-options.c +++ b/parse-options.c @@ -924,18 +924,12 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx, fprintf(outfile, "cat <<\\EOF\n"); fprintf_ln(outfile, _("usage: %s"), _(*usagestr++)); - while (*usagestr && **usagestr) + while (*usagestr) { /* * TRANSLATORS: the colon here should align with the * one in "usage: %s" translation. */ fprintf_ln(outfile, _(" or: %s"), _(*usagestr++)); - while (*usagestr) { - if (**usagestr) - fprintf_ln(outfile, _(" %s"), _(*usagestr)); - else - fputc('\n', outfile); - usagestr++; } need_newline = 1; diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index 2051ce57db7..e00aef073b0 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -102,8 +102,6 @@ int cmd__parse_options(int argc, const char **argv) const char *prefix = "prefix/"; const char *usage[] = { "test-tool parse-options ", - "", - "A helper function for the parse-options API.", NULL }; struct string_list expect = STRING_LIST_INIT_NODUP; diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index ad4746d899a..2910874ece5 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -10,8 +10,6 @@ test_description='our own option parser' cat >expect <<\EOF usage: test-tool parse-options - A helper function for the parse-options API. - --yes get a boolean -D, --no-doubt begins with 'no-' -B, --no-fear be brave diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index b29563fc997..6badc650d64 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -6,8 +6,6 @@ test_description='test git rev-parse --parseopt' test_expect_success 'setup optionspec' ' sed -e "s/^|//" >optionspec <<\EOF |some-command [options] ... -| -|some-command does foo and bar! |-- |h,help show the help | @@ -41,8 +39,6 @@ EOF test_expect_success 'setup optionspec-no-switches' ' sed -e "s/^|//" >optionspec_no_switches <<\EOF |some-command [options] ... -| -|some-command does foo and bar! |-- EOF ' @@ -50,8 +46,6 @@ EOF test_expect_success 'setup optionspec-only-hidden-switches' ' sed -e "s/^|//" >optionspec_only_hidden_switches <<\EOF |some-command [options] ... -| -|some-command does foo and bar! |-- |hidden1* A hidden switch EOF @@ -62,8 +56,6 @@ test_expect_success 'test --parseopt help output' ' |cat <<\EOF |usage: some-command [options] ... | -| some-command does foo and bar! -| | -h, --help show the help | --foo some nifty option --foo | --bar ... some cool option --bar with an argument @@ -103,8 +95,6 @@ test_expect_success 'test --parseopt help output no switches' ' |cat <<\EOF |usage: some-command [options] ... | -| some-command does foo and bar! -| |EOF END_EXPECT test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_no_switches && @@ -116,8 +106,6 @@ test_expect_success 'test --parseopt help output hidden switches' ' |cat <<\EOF |usage: some-command [options] ... | -| some-command does foo and bar! -| |EOF END_EXPECT test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_only_hidden_switches && @@ -129,8 +117,6 @@ test_expect_success 'test --parseopt help-all output hidden switches' ' |cat <<\EOF |usage: some-command [options] ... | -| some-command does foo and bar! -| | --hidden1 A hidden switch | |EOF @@ -144,8 +130,6 @@ test_expect_success 'test --parseopt invalid switch help output' ' |error: unknown option `does-not-exist'\'' |usage: some-command [options] ... | -| some-command does foo and bar! -| | -h, --help show the help | --foo some nifty option --foo | --bar ... some cool option --bar with an argument @@ -282,4 +266,22 @@ test_expect_success 'test --parseopt --stuck-long and short option with unset op test_cmp expect output ' +test_expect_success 'test --parseopt help output hidden switches' ' + sed -e "s/^|//" >optionspec-trailing-line <<-\EOF && + |some-command [options] ... + | + | + |-- + |h,help show the help + EOF + + cat >expect <<-\EOF && + fatal: empty lines are not permitted before the `--'"'"' separator + EOF + + test_must_fail git rev-parse --parseopt -- -h >out < optionspec-trailing-line 2>actual && + test_must_be_empty out && + test_cmp expect actual +' + test_done From patchwork Sat Sep 11 19:09:03 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: 12486609 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.8 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 899DEC433F5 for ; Sat, 11 Sep 2021 19:10:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F38B6108B for ; Sat, 11 Sep 2021 19:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233783AbhIKTLz (ORCPT ); Sat, 11 Sep 2021 15:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233843AbhIKTLo (ORCPT ); Sat, 11 Sep 2021 15:11:44 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF13AC061756 for ; Sat, 11 Sep 2021 12:10:30 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id t8so2789801wrq.4 for ; Sat, 11 Sep 2021 12:10: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=ChLf81W3t4HKCng/soE8BIA499OOBLGo1cM4oJfuMyI=; b=jxFoSSeIr1Ftkt5jYEAIuH9NA/QUl6OeysBqT63MnKifdGwtBEpi2gqDi+1+vhj5mp DqQL0vJdW8vDR/NVscVwa1VYp9BbBIkLvnC6hqlJtg9Ae3xoj6N2s1388qUIvltnV0dL 79Nj8LpZLHEWS2uhU9rIc9GaCl6OuvLiM0d4L3dfDScHPgGVZHUcA+mG6LgTrPymw/BS yzizOvpuJBdezFMJwNTee36AT94FocBr2tg07Mtc9ExsCDOXEj2xw2NvAmZ/U373iqgP YKdEyuIDVePnb6GXre+d4nXYTgY5youGRWLkZHIXFfpjqL9roZ6CLJfShuQK2r3IFulT Qshg== 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=ChLf81W3t4HKCng/soE8BIA499OOBLGo1cM4oJfuMyI=; b=6UC/n+xyDB+M6Nb6HPJUMGFwZlYx6JaTD5oAU1i1Gk0C4FfbfZaq0uMuLXGBSNnf6t 4KRIa4ATYyCAXI2wELBy8EtT5NoL3KeeWPRYi75rVuXbMDlCXBwDgIauX+2PgesDV3sQ llKPIv2B0wIw3iUPOx01ItTX+iFfm2Zzhae5RJt0oL9piH/bGUzpyvmjLGASqIq9RH0s 6/mjrGyinK3II+il5u8SpZLrqeHXAwJrcSWuVMGFhF89R9RdsuJy4sErTlmNDXFNe0Qk 55CPBWXwEJQAnNFQMDUUCU+ACtIhepvmakf7oqu3jQ1EebxdH5dciHVjavz045F14F18 LfbA== X-Gm-Message-State: AOAM533P3C4XIYthDdDmD2ICbJQUqvmYdIyeKgsa5gYF/g9G1eKV/grd GMMEBZv/9byNZ+AmUH0GN7IzwSKbSPT3jA== X-Google-Smtp-Source: ABdhPJzO3p3geQmPy7qHoc8HR9gR2WGpUQypxGU++AOeGs0XUUDWIvaKjdY3LcROGK4stQFOB7+n1Q== X-Received: by 2002:adf:f884:: with SMTP id u4mr4104529wrp.411.1631387429207; Sat, 11 Sep 2021 12:10:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/6] built-ins: "properly" align continued usage output Date: Sat, 11 Sep 2021 21:09:03 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's "fix" various "git -h" output by "properly" aligning the output in cases where we continue usage output after a "\n". The "fix" and "properly" scare quotes are because this actually makes things worse in some cases, because e.g. in the case of "git tag -h" the "\t\t" effectively works around how parse-options.c aligns this output. But two wrongs don't make a right, let's "fix" this by making it worse temporarily, in anticipation of improving parse-options.c to handle this alignment. The issue is that we should have whitespace corresponding to the length of the command name here, e.g. in the case of "git ls-remote" it should be 14 characters, or the length of ""git ls-remote ". Instead we had 21 characters in builtin/ls-remote.c, those extra 7 characters are the length of "usage: " (and also " or:"). So in the C locale the resulting output aligns nicely: $ git ls-remote -h usage: git ls-remote [--heads] [--tags] [--refs] [--upload-pack=] [-q | --quiet] [--exit-code] [--get-url] [--symref] [ [...]] But that's fragile, we might not be under the C locale. We really should have parse-options.c itself add this padding. In a subsequent commit I'll make it do that. In the case of "tag" and "show-branch" and "stash save" the output was not properly aligned, although in the "git tag" case it was near-enough (aligned with the "-" in "git tag -l") to look good, assuming C locale & a tab-width of 8. In any case, let's align this in a way that looks obviously correct when looking at the source itself, and then improve parse-options.c itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-remote.c | 4 ++-- builtin/show-branch.c | 6 +++--- builtin/stash.c | 2 +- builtin/tag.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index f4fd823af83..318949c3d75 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -7,8 +7,8 @@ static const char * const ls_remote_usage[] = { N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=]\n" - " [-q | --quiet] [--exit-code] [--get-url]\n" - " [--symref] [ [...]]"), + " [-q | --quiet] [--exit-code] [--get-url]\n" + " [--symref] [ [...]]"), NULL }; diff --git a/builtin/show-branch.c b/builtin/show-branch.c index bea4bbf4680..082449293b5 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -11,9 +11,9 @@ static const char* show_branch_usage[] = { N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n" - " [--current] [--color[=] | --no-color] [--sparse]\n" - " [--more= | --list | --independent | --merge-base]\n" - " [--no-name | --sha1-name] [--topics] [( | )...]"), + " [--current] [--color[=] | --no-color] [--sparse]\n" + " [--more= | --list | --independent | --merge-base]\n" + " [--no-name | --sha1-name] [--topics] [( | )...]"), N_("git show-branch (-g | --reflog)[=[,]] [--list] []"), NULL }; diff --git a/builtin/stash.c b/builtin/stash.c index 8f42360ca91..45b19007d7c 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -85,7 +85,7 @@ static const char * const git_stash_push_usage[] = { static const char * const git_stash_save_usage[] = { N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" - " [-u|--include-untracked] [-a|--all] []"), + " [-u|--include-untracked] [-a|--all] []"), NULL }; diff --git a/builtin/tag.c b/builtin/tag.c index 065b6bf093e..6535ed27ee9 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -23,10 +23,10 @@ static const char * const git_tag_usage[] = { N_("git tag [-a | -s | -u ] [-f] [-m | -F ]\n" - "\t\t []"), + " []"), N_("git tag -d ..."), N_("git tag -l [-n[]] [--contains ] [--no-contains ] [--points-at ]\n" - "\t\t[--format=] [--merged ] [--no-merged ] [...]"), + " [--format=] [--merged ] [--no-merged ] [...]"), N_("git tag -v [--format=] ..."), NULL }; From patchwork Sat Sep 11 19:09:04 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: 12486611 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.8 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 DEBE7C433EF for ; Sat, 11 Sep 2021 19:10:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C906F6108B for ; Sat, 11 Sep 2021 19:10:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233890AbhIKTL5 (ORCPT ); Sat, 11 Sep 2021 15:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbhIKTLp (ORCPT ); Sat, 11 Sep 2021 15:11:45 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8408C061757 for ; Sat, 11 Sep 2021 12:10:31 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id m9so7837332wrb.1 for ; Sat, 11 Sep 2021 12:10: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=FvPtu2L10IXCUyXciVVSa2PSteuHFrM2C9k6MmBZTKo=; b=ZPm+MznhudE3YBhTXudP8IaHuOwF+w50yU3jSNet4jxmuUlMHcw0DTtVGqkuTsZgcR hnra6pLWhHnlnVIcdqdFiiomIRqMDeb0x60peo75Xz1+SmRvSTG9i3Ya1emJuA9SVrjg rhWT1ndXT4lSiuyxYah2yu7rXQrc63SofX1peagDZ7tduHNcLVj2xDh39/+kOvfe82mq 2mLlhl8DXG1DGyNqP8DOvnQ7kkef2XMJ4vuK8yfpa/8ELuUuhV/2q8TKFBa2oVkcuCma SUOcjqlhAtLxb21t/ry5sJqseKEgg0kRWddylFr9LDAGlPRfKiaTK+OhYoBsnNmI4ofx nV2A== 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=FvPtu2L10IXCUyXciVVSa2PSteuHFrM2C9k6MmBZTKo=; b=LR8vV2T4go7Rznoiwydja3yyFPncMyg+AKIUhIOVBOc58bRhQTE2R0RWiuVesk05O9 LZXM4r0ZK/Z4Fcl8HhiEC1lVo6aPDWzYOidwxKewItat2ByEkoOcoN7CNpvggmd5bRCA /Bz4yBMOu8LWTkolt3iFthyxKXO7zzbOLePfEEPBRr86EJz5bdvfMQkVhewoEM+tpQ/3 Q69RJPNinhiXV+F8KcvhzIvBwiWsvxgarMLnv3qpRc67gk4ENjVJs1Wsf5Vn7VBFseIZ tQcG1tixlt5M1q615++92PfVFDJB4/gqBcP96//wqbGBjDHrRZmMI4BdqqO7VQcC9qWG DZAg== X-Gm-Message-State: AOAM530APjKqErBuAdZ7vaeYW+WYHT9boj04r5bXZhc+W3fhh3Uv4wgF Iyp6AsP1PuboqwRogWU4TVFZDn4whe0Rmw== X-Google-Smtp-Source: ABdhPJyfrQJTKNbhRLtyZJkWxOBULbsh5q8ypEjO0k3pBhmGGLrcHHg8kH7KJYRe4N9Swa4CniLSsQ== X-Received: by 2002:adf:9d4c:: with SMTP id o12mr4223856wre.187.1631387430021; Sat, 11 Sep 2021 12:10:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 5/6] send-pack: properly use parse_options() API for usage string Date: Sat, 11 Sep 2021 21:09:04 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When "send-pack" was changed to use the parse_options() API in 068c77a5189 (builtin/send-pack.c: use parse_options API, 2015-08-19) it was made to use one very long line, instead it should split them up with newlines. Furthermore we were including an inline explanation that you couldn't combine "--all" and "", but unlike in the "blame" case this was not preceded by an empty string. Let's instead show that --all and can't be combined in the the usual language of the usage syntax instead. We can make it clear that one of the two options "--foo" and "--bar" is mandatory, but that the two are mutually exclusive by referring to them as "( --foo | --bar )". Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-send-pack.txt | 4 ++-- builtin/send-pack.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/git-send-pack.txt b/Documentation/git-send-pack.txt index 44fd146b912..be41f119740 100644 --- a/Documentation/git-send-pack.txt +++ b/Documentation/git-send-pack.txt @@ -9,10 +9,10 @@ git-send-pack - Push objects over Git protocol to another repository SYNOPSIS -------- [verse] -'git send-pack' [--all] [--dry-run] [--force] [--receive-pack=] +'git send-pack' [--dry-run] [--force] [--receive-pack=] [--verbose] [--thin] [--atomic] [--[no-]signed|--signed=(true|false|if-asked)] - [:] [...] + [:] (--all | ...) DESCRIPTION ----------- diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 729dea1d255..89321423125 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -17,10 +17,10 @@ #include "protocol.h" static const char * const send_pack_usage[] = { - N_("git send-pack [--all | --mirror] [--dry-run] [--force] " - "[--receive-pack=] [--verbose] [--thin] [--atomic] " - "[:] [...]\n" - " --all and explicit specification are mutually exclusive."), + N_("git send-pack [--mirror] [--dry-run] [--force]\n" + " [--receive-pack=]\n" + " [--verbose] [--thin] [--atomic]\n" + " [:] (--all | ...)"), NULL, }; From patchwork Sat Sep 11 19:09:05 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: 12486613 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.8 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 D66A5C433F5 for ; Sat, 11 Sep 2021 19:10:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE78A6108B for ; Sat, 11 Sep 2021 19:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbhIKTL6 (ORCPT ); Sat, 11 Sep 2021 15:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233842AbhIKTLp (ORCPT ); Sat, 11 Sep 2021 15:11:45 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E5BC061756 for ; Sat, 11 Sep 2021 12:10:32 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id w29so7056452wra.8 for ; Sat, 11 Sep 2021 12:10: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=syAJmUhreFzopqoYJhQcfitV/eI2y5YCAhJluEEmw7Y=; b=WAixBUP3ua8uJAXlHB2z6pU2N88ck1HYqZuCi0cDNhUPkW2tSUQmS2oC8Z1n/HW12q VTR5T0bs44nT8Gp5vIGqsF1cFBYlJ5+M5b0NShxD5Z9hI1u88GUv9ggAHuk93lPQK6B7 BiDnzz0ZgV1XUMDgrmuviXfuUbI+O48mI+GG4Ld9/A2CXaLCWZ33hlUWws11i58y1Wn/ 9ctS1jNhCRWa1D9Wo1GAa8ykXHlzAFGAd6TfxQ20uWHySrO+UIirkayiusRs6ZAKwWl7 hgYnZQ46urMnnDm0kfrnPDANhbIEL+KPHSWomonUCw7oQ2qZYwDu0mWHyw0lq1VFFh5D R7IA== 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=syAJmUhreFzopqoYJhQcfitV/eI2y5YCAhJluEEmw7Y=; b=XcZRI0Y/4duh+Rikar/ZyD3hbiBvIVS1ppVeIWIFES8Wwcd7i/zRJ0rSwyptJxliw3 Wl9JWykqbFFubR/QILc5VPTR+o6WeWjC/yf3juxVOkHkc9qZM/VtvES1ckWpY5G+pGu7 OV3GJFps2dF40hRa8vx1UiNMy+GPGDVpVeM80OJAIykDkqa9p1YmSZgQriIbcVcyJPTO w3oypgiOxOhS0EQfV3/YN+9qvoJMPEI2ruJlqGEXVZdUBpjX+WMmhI3+Pnbgc8392Q/3 SsB4pHx9cSMSGEk8daKr8RC4J5Vd3wWvNLJN8S8h4A9KU5Hatv2jNAO0YUYz+HpoBxki SfWA== X-Gm-Message-State: AOAM531jHwODskCtdVPpheyVwEuuwYV0JVGDZR3BSv+62+WPVpggVSkS EDt0wjngA6Oo7bVOS1gcJiLDHCRs5lm+kQ== X-Google-Smtp-Source: ABdhPJyxvHtxkTdKRu28Qqeagm1k4ea7nsdLA7OvCctK1FFM+ts1alHqhU60ydmJWbm2JmLEqSiXQQ== X-Received: by 2002:adf:fcca:: with SMTP id f10mr4340568wrs.304.1631387430888; Sat, 11 Sep 2021 12:10:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm2256822wmk.2.2021.09.11.12.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 12:10:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Carlo Arenas , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 6/6] parse-options: properly align continued usage output Date: Sat, 11 Sep 2021 21:09:05 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.995.ga5ea46173a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some commands such as "git stash" emit continued options output with e.g. "git stash -h", because usage_with_options_internal() prefixes with its own whitespace the resulting output wasn't properly aligned. Let's account for the added whitespace, which properly aligns the output. The "git stash" command has usage output with a N_() translation that legitimately stretches across multiple lines; N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] [-m|--message ]\n" [...] We'd like to have that output aligned with the length of the initial "git stash " output, but since usage_with_options_internal() adds its own whitespace prefixing we fell short, before this change we'd emit: $ git stash -h usage: git stash list [] or: git stash show [] [] [...] or: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all] [-m|--message ] [...] Now we'll properly emit aligned output. I.e. the last four lines above will instead be (a whitespace-only change to the above): [...] or: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all] [-m|--message ] [...] We could also go for an approach where we have the caller support no padding of their own, i.e. (same as the first example, except for the padding on the second line): N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" "[-u|--include-untracked] [-a|--all] [-m|--message ]\n" [...] But to do that we'll need to find the length of "git stash". We can discover that from the "cmd" in the "struct cmd_struct", but there might cases with sub-commands or "git" itself taking arguments that would make that non-trivial. Even if it was I still think this approach is better, because this way we'll get the same legible alignment in the C code. The fact that usage_with_options_internal() is adding its own prefix padding is an implementation detail that callers shouldn't need to worry about. Implementation notes: We could skip the string_list_split() with a strchr(str, '\n') check, but we'd then need to duplicate our state machine for strings that do and don't contain a "\n". It's simpler to just always split into a "struct string_list", even though the common case is that that "struct string_list" will contain only one element. This is not performance-sensitive code. This change is relatively more complex since I've accounted for making it future-proof for RTL translation support. Later in usage_with_options_internal() we have some existing padding code dating back to d7a38c54a6c (parse-options: be able to generate usages automatically, 2007-10-15) which isn't RTL-safe, but that code would be easy to fix. Let's not introduce new RTL translation problems here. I'm also adding a check to catch the mistake of needlessly adding a trailing "\n", such as: N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n" " [-u|--include-untracked] [-a|--all] []\n"), Or even a mistake like adding just one "\n" in a string with no other newlines: N_("git stash list []\n"), This catches the cases already tested for in cmd_parseopt(), but this covers the purely C API. As noted a preceding commit that added the die() to cmd_parseopt() I'm fairly confident that this will be triggered by no in-tree user I've missed. Signed-off-by: Ævar Arnfjörð Bjarmason --- parse-options.c | 65 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/parse-options.c b/parse-options.c index 950a8279beb..ff28869d2c9 100644 --- a/parse-options.c +++ b/parse-options.c @@ -917,19 +917,72 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx, FILE *outfile = err ? stderr : stdout; int need_newline; + const char *usage_prefix = _("usage: %s"); + /* + * The translation could be anything, but we can count on + * msgfmt(1)'s --check option to have asserted that "%s" is in + * the translation. So compute the length of the "usage: " + * part. We are assuming that the translator wasn't overly + * clever and used e.g. "%1$s" instead of "%s", there's only + * one "%s" in "usage_prefix" above, so there's no reason to + * do so even with a RTL language. + */ + size_t usage_len = strlen(usage_prefix) - strlen("%s"); + /* + * TRANSLATORS: the colon here should align with the + * one in "usage: %s" translation. + */ + const char *or_prefix = _(" or: %s"); + + /* + * TRANSLATORS: You should only need to translate this format + * string if your language is a RTL language (e.g. Arabic, + * Hebrew etc.), not if it's a LTR language (e.g. German, + * Russian, Chinese etc.). + * + * When a translated usage string has an embedded "\n" it's + * because options have wrapped to the next line. The line + * after the "\n" will then be padded to align with the + * command name, such as N_("git cmd [opt]\n<8 + * spaces>[opt2]"), where the 8 spaces are the same length as + * "git cmd ". + * + * This format string prints out that already-translated + * line. The "%*s" is whitespace padding to account for the + * padding at the start of the line that we add in this + * function. The "%s" is a line in the (hopefully already + * translated) N_() usage string, which contained embedded + * newlines before we split it up. + */ + const char *usage_continued = _("%*s%s"); + const char *prefix = usage_prefix; + if (!usagestr) return PARSE_OPT_HELP; if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL) fprintf(outfile, "cat <<\\EOF\n"); - fprintf_ln(outfile, _("usage: %s"), _(*usagestr++)); while (*usagestr) { - /* - * TRANSLATORS: the colon here should align with the - * one in "usage: %s" translation. - */ - fprintf_ln(outfile, _(" or: %s"), _(*usagestr++)); + struct string_list list = STRING_LIST_INIT_DUP; + unsigned int j; + + string_list_split(&list, _(*usagestr++), '\n', -1); + for (j = 0; j < list.nr; j++) { + const char *line = list.items[j].string; + + if (!*line) + BUG("empty or trailing line in usage string"); + + if (!j) + fprintf_ln(outfile, prefix, line); + else + fprintf_ln(outfile, usage_continued, + (int)usage_len, "", line); + } + string_list_clear(&list, 0); + + prefix = or_prefix; } need_newline = 1;