From patchwork Mon Feb 15 18:41:14 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: 12089103 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 EEFB6C433DB for ; Mon, 15 Feb 2021 18:43:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B716E64E05 for ; Mon, 15 Feb 2021 18:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbhBOSnS (ORCPT ); Mon, 15 Feb 2021 13:43:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbhBOSmX (ORCPT ); Mon, 15 Feb 2021 13:42:23 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E33CC061756 for ; Mon, 15 Feb 2021 10:41:43 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id o24so10207936wmh.5 for ; Mon, 15 Feb 2021 10:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oRCZ9LjHpNXwaAnK7I3Kark9db4GMPEf4le7QOKY7Do=; b=VCNfScE9T4C9iAfg+KXUJa+QyDOFHhgBacUghKqYvDRZ9BjSQnaQIkU8XaZbWfB47g gqA+ivn6+5AifsIDoOIywrEmuq+RZtfZWO1Y2CXRh3T6vnLZrBOpJVCLjc/vFoZGICTg RDgAhAlMXfkqc/Csjs75uMiS+o/xTwQdDhBx3I4TZIcc3Dkh/vnrax+WRPJqcJkBdL8o HmtD67gHFT+Kk9RD4otvs7hlemW4CW/HobTmhuV4anklGudmvDW/SEFzZXvrkJ7oom5Z u7T36vQF+OVq0HD1iHeGlbJOxmpIzVyV3vIQpTEBnRy8fZ/8w71g7v717HU2SsLWWadG Zc5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oRCZ9LjHpNXwaAnK7I3Kark9db4GMPEf4le7QOKY7Do=; b=uV1XDMsRdAWmqLTP8g9Q5IEROjtoaezxTeQTuOJc4gBk84jdBuVoxb42GvpYvENYis AXGNEKtlqYrPweoIP12OwMQmU2DAhKs/VZzXiqg5W7WstNz/X1jdAY5fgdQ0c9nbLWB9 cPMDBvZD2ZpaY61Uin933b1umOdhShb+nzBVcy0xE62djO8i6qRHeLtPfbNldshHTb/9 RFOx+ozZ4G3Kjh6TMfAEify9ZPj94mr8wPLNdML7s0CVbiUI4QOaCbU6WMob7f3nGdQW 1Zw0Bh+4WzJYeu7BenP8PJnDU9d0W8Kc/mlnhi7J/wxLmO1/OejEWwfOzVKQCcvEO3o2 LUMw== X-Gm-Message-State: AOAM533MxRVsWJEr8wE0+EPzatGhmM6JGk+50nEVWsoitxem57jtKn0X aKrvX1Lwvsz5evaUvp7pGOnLxV2MEDfyPA== X-Google-Smtp-Source: ABdhPJyHoooRzC+Zh5I5sxlb3Y1IhXLktIrHacfYs6m+ILKsywPlflGwr22TzmG86xrSG5Xp5drb4Q== X-Received: by 2002:a05:600c:2056:: with SMTP id p22mr218238wmg.12.1613414501828; Mon, 15 Feb 2021 10:41:41 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v12sm11258979wrv.69.2021.02.15.10.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 10:41:41 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , dstolee@microsoft.com, =?utf-8?q?SZEDER_G=C3=A1bor?= , peff@peff.net, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/5] commit-graph: define common usage with a macro Date: Mon, 15 Feb 2021 19:41:14 +0100 Message-Id: <20210215184118.11306-2-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <87r1lhb6z7.fsf@evledraar.gmail.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Share the usage message between these three variables by using a macro. Before this new options needed to copy/paste the usage information, see e.g. 809e0327f5 (builtin/commit-graph.c: introduce '--max-new-filters=', 2020-09-18). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index cd86315221..c3fa4fde3e 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -9,26 +9,27 @@ #include "progress.h" #include "tag.h" -static char const * const builtin_commit_graph_usage[] = { - N_("git commit-graph verify [--object-dir ] [--shallow] [--[no-]progress]"), - N_("git commit-graph write [--object-dir ] [--append] " - "[--split[=]] [--reachable|--stdin-packs|--stdin-commits] " - "[--changed-paths] [--[no-]max-new-filters ] [--[no-]progress] " - ""), +static const char * builtin_commit_graph_verify_usage[] = { +#define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \ + N_("git commit-graph verify [--object-dir ] [--shallow] [--[no-]progress]") + BUILTIN_COMMIT_GRAPH_VERIFY_USAGE, NULL }; -static const char * const builtin_commit_graph_verify_usage[] = { - N_("git commit-graph verify [--object-dir ] [--shallow] [--[no-]progress]"), +static const char * builtin_commit_graph_write_usage[] = { +#define BUILTIN_COMMIT_GRAPH_WRITE_USAGE \ + N_("git commit-graph write [--object-dir ] [--append] " \ + "[--split[=]] [--reachable|--stdin-packs|--stdin-commits] " \ + "[--changed-paths] [--[no-]max-new-filters ] [--[no-]progress] " \ + "") + BUILTIN_COMMIT_GRAPH_WRITE_USAGE, NULL }; -static const char * const builtin_commit_graph_write_usage[] = { - N_("git commit-graph write [--object-dir ] [--append] " - "[--split[=]] [--reachable|--stdin-packs|--stdin-commits] " - "[--changed-paths] [--[no-]max-new-filters ] [--[no-]progress] " - ""), - NULL +static char const * const builtin_commit_graph_usage[] = { + BUILTIN_COMMIT_GRAPH_VERIFY_USAGE, + BUILTIN_COMMIT_GRAPH_WRITE_USAGE, + NULL, }; static struct opts_commit_graph { From patchwork Mon Feb 15 18:41:15 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: 12089105 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 D538DC433E6 for ; Mon, 15 Feb 2021 18:43:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB83D64E13 for ; Mon, 15 Feb 2021 18:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbhBOSnX (ORCPT ); Mon, 15 Feb 2021 13:43:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhBOSmY (ORCPT ); Mon, 15 Feb 2021 13:42:24 -0500 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 18A06C0613D6 for ; Mon, 15 Feb 2021 10:41:44 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id n10so10258659wmq.0 for ; Mon, 15 Feb 2021 10:41:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F9IBskYvuRMaNYBuJ9lxjAVzqx3mm5wwkHChR5jOkS4=; b=FFrSc9wmFr6pG98INpE3AwNR9ICm6hVSrU9nrrELsGsp56sdH4q3I30xmX4lpr62Cc yh35fuNVRUWOnNyUapFr5iG3vIgI4sR+a0Dw0BQ38R5sZZV1dNnJNDjoeC8mKyckixc0 0QHN13+UsDxKn+shjPmNquavfJaKhElBpXfZG0MT3Ig58YnT5BteePjZW/nSI0AvuWld JwNnJhih/UURq5EfizTsBOJIrXB2BW/3uJKB7BR2Vi9PhnLCeSS2Q1tYdxJ1PBFyQwXD eOzaPRc9RvEZPVbqZxr/HNyi0PI2myb57EDUatwmbEU3Si8x8tXc/uVryT30XJuKQMlU 1koQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F9IBskYvuRMaNYBuJ9lxjAVzqx3mm5wwkHChR5jOkS4=; b=MLcsgiUJq+WFpbAgtw04bWCdC5wkF8eg3KayEs2xqkNcOdeT43AUSrO6AfWdaqommn EFTQG2zaB/11jcyHJjLSrfmGPoST1T8dxHy10+3rAgstX/GyjrW5dV4m7qpyMZpwU9XT MRrd+VWIsUGx0SoEGAlxjWmIDI9uBqZgrw1heuQKvvguZn3BTocuXP+QxjdIphEMdpwH r6xuvJb18GoSYgLZhHt+052qkB6puG3KupyRPKzgMG24UTe/i8z2LM5/PZNkH9SD645w 1IkdkiEn0qy1Pm9BQ6WO+JqhdP6M3lr7JNPWyPdAWh/hYO/G9sKnQ3mWwLDBEBIetszw b/3A== X-Gm-Message-State: AOAM530s/tNBHyY1X8n7QO70Gh/hO7jSXNXAcJ4ett5v3mY+fVvHxio1 LRQv09L2Vu9TMT6XqUDTjhyYI0av8wf2DA== X-Google-Smtp-Source: ABdhPJzEHD+F60P1MaHE6Ii7GNlDILzhi0uW1RCZH8zcmytiyUCZZH1jNpFkRlAHJWTHbgVMyTz5hw== X-Received: by 2002:a7b:c256:: with SMTP id b22mr194246wmj.108.1613414502578; Mon, 15 Feb 2021 10:41:42 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v12sm11258979wrv.69.2021.02.15.10.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 10:41:42 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , dstolee@microsoft.com, =?utf-8?q?SZEDER_G=C3=A1bor?= , peff@peff.net, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/5] commit-graph: remove redundant handling of -h Date: Mon, 15 Feb 2021 19:41:15 +0100 Message-Id: <20210215184118.11306-3-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <87r1lhb6z7.fsf@evledraar.gmail.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If we don't handle the -h option here like most parse_options() users we'll fall through and it'll do the right thing for us. I think this code added in 4ce58ee38d (commit-graph: create git-commit-graph builtin, 2018-04-02) was always redundant, parse_options() did this at the time, and the commit-graph code never used PARSE_OPT_NO_INTERNAL_HELP. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 4 ---- t/t5318-commit-graph.sh | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index c3fa4fde3e..baead04a03 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -319,10 +319,6 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix) OPT_END(), }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_commit_graph_usage, - builtin_commit_graph_options); - git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, builtin_commit_graph_options, diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 2ed0c1544d..567e68bd93 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -5,6 +5,11 @@ test_description='commit graph' GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 +test_expect_success 'usage' ' + test_expect_code 129 git commit-graph -h 2>err && + ! grep error: err +' + test_expect_success 'setup full repo' ' mkdir full && cd "$TRASH_DIRECTORY/full" && From patchwork Mon Feb 15 18:41:16 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: 12089109 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 0FD37C433DB for ; Mon, 15 Feb 2021 18:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2CF964E05 for ; Mon, 15 Feb 2021 18:44:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231342AbhBOSng (ORCPT ); Mon, 15 Feb 2021 13:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbhBOSmZ (ORCPT ); Mon, 15 Feb 2021 13:42:25 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12137C061786 for ; Mon, 15 Feb 2021 10:41:45 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id o10so4678200wmc.1 for ; Mon, 15 Feb 2021 10:41:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x9AiFw8miDGnjxIVOobuKc943zd2SsqJUqGjL4CbUds=; b=uZFyvBumXmgHbtqeXyvyZ1s7ULhUTVAZyJg5vR47yVwJ4fVSlncITb3ZZfgN4swxpv aiJgpecvjLJAx6f4h7/SVI91eWr2gLlErp/rQOM0I8cKjKCSm/J1HeTs5l0462zit1ip pYHO2MasQ/uGqhuzdp2JT55JZUQSULLsSt4IXuMBnR+5IinWXkPuahEK5aL5Wp4Z6xhN JoTEl95mTaQm+tZFYZu87ufOVSYsSypE10BB8QVQ01HIujku6pBRUcDmTumDYohCWoJL JJfMBWZR7Y5KKqZgB9jEXkPHbrm4hr6FlxLzvIn8hsTRGaHe6V7Q1wDxI30BgPFJCkPF 6bPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x9AiFw8miDGnjxIVOobuKc943zd2SsqJUqGjL4CbUds=; b=AMEhBU1eFSEu08CuevDl1W6utYQaAvrEoEIhlTx/K1c63xZZxrX5QGyBFkDTuokdTm /IAHJFy05kEu8LW4XjkfcEg2DftC4Vx/TIY74YmxaGGlHzDJKaVhd8mbTI45NaO990Vu fq+WOpklnjyG2+4XVujLZom5JuC/6lpyDE2f+CoVOvr9h608+enjhf7YrL0kFSehxuEk MCpysqvsFayqK+b0yf17R2PWXkbYYIdkctcfWHjCYiQ+murSBEj1Rx4buIUl3/NltnIg jhxOgJtMN0sN4aq0IIGk/k/aVj319LcNIcR/0nYYYM2CJCqy8JySi16HCYdN1bXO5DZV u7yw== X-Gm-Message-State: AOAM5333P/5rP8Ibv4zmxPOx5YyyuL4PxMK72sZGzXPQhYcTKS5FEnH6 iRqPWLSSZ7CPEt0XmMnl2Y4kT9KAavf21Q== X-Google-Smtp-Source: ABdhPJxOziTnrTunui2cRfroE6wslUy5swukQR8Dkdh1NzOFPf21Qz9++MJt7EP+4X0elYWq28Nsfw== X-Received: by 2002:a1c:f31a:: with SMTP id q26mr158461wmq.119.1613414503490; Mon, 15 Feb 2021 10:41:43 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v12sm11258979wrv.69.2021.02.15.10.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 10:41:42 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , dstolee@microsoft.com, =?utf-8?q?SZEDER_G=C3=A1bor?= , peff@peff.net, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/5] commit-graph: use parse_options_concat() Date: Mon, 15 Feb 2021 19:41:16 +0100 Message-Id: <20210215184118.11306-4-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <87r1lhb6z7.fsf@evledraar.gmail.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make use of the parse_options_concat() so we don't need to copy/paste common options like --object-dir. This is inspired by a similar change to "checkout" in 2087182272 (checkout: split options[] array in three pieces, 2019-03-29). A minor behavior change here is that now we're going to list both --object-dir and --progress first, before we'd list --progress along with other options. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: SZEDER Gábor Signed-off-by: Taylor Blau --- builtin/commit-graph.c | 43 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index baead04a03..a7718b2025 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -44,6 +44,21 @@ static struct opts_commit_graph { int enable_changed_paths; } opts; +static struct option *add_common_options(struct option *prevopts) +{ + struct option options[] = { + OPT_STRING(0, "object-dir", &opts.obj_dir, + N_("dir"), + N_("the object directory to store the graph")), + OPT_BOOL(0, "progress", &opts.progress, + N_("force progress reporting")), + OPT_END() + }; + struct option *newopts = parse_options_concat(options, prevopts); + free(prevopts); + return newopts; +} + static struct object_directory *find_odb(struct repository *r, const char *obj_dir) { @@ -75,22 +90,20 @@ static int graph_verify(int argc, const char **argv) int fd; struct stat st; int flags = 0; - + struct option *options = NULL; static struct option builtin_commit_graph_verify_options[] = { - OPT_STRING(0, "object-dir", &opts.obj_dir, - N_("dir"), - N_("the object directory to store the graph")), OPT_BOOL(0, "shallow", &opts.shallow, N_("if the commit-graph is split, only verify the tip file")), - OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")), OPT_END(), }; + options = parse_options_dup(builtin_commit_graph_verify_options); + options = add_common_options(options); trace2_cmd_mode("verify"); opts.progress = isatty(2); argc = parse_options(argc, argv, NULL, - builtin_commit_graph_verify_options, + options, builtin_commit_graph_verify_usage, 0); if (!opts.obj_dir) @@ -205,11 +218,8 @@ static int graph_write(int argc, const char **argv) int result = 0; enum commit_graph_write_flags flags = 0; struct progress *progress = NULL; - + struct option *options = NULL; static struct option builtin_commit_graph_write_options[] = { - OPT_STRING(0, "object-dir", &opts.obj_dir, - N_("dir"), - N_("the object directory to store the graph")), OPT_BOOL(0, "reachable", &opts.reachable, N_("start walk at all refs")), OPT_BOOL(0, "stdin-packs", &opts.stdin_packs, @@ -220,7 +230,6 @@ static int graph_write(int argc, const char **argv) N_("include all commits already in the commit-graph file")), OPT_BOOL(0, "changed-paths", &opts.enable_changed_paths, N_("enable computation for changed paths")), - OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")), OPT_CALLBACK_F(0, "split", &write_opts.split_flags, NULL, N_("allow writing an incremental commit-graph file"), PARSE_OPT_OPTARG | PARSE_OPT_NONEG, @@ -236,6 +245,8 @@ static int graph_write(int argc, const char **argv) 0, write_option_max_new_filters), OPT_END(), }; + options = parse_options_dup(builtin_commit_graph_write_options); + options = add_common_options(options); opts.progress = isatty(2); opts.enable_changed_paths = -1; @@ -249,7 +260,7 @@ static int graph_write(int argc, const char **argv) git_config(git_commit_graph_write_config, &opts); argc = parse_options(argc, argv, NULL, - builtin_commit_graph_write_options, + options, builtin_commit_graph_write_usage, 0); if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1) @@ -312,12 +323,8 @@ static int graph_write(int argc, const char **argv) int cmd_commit_graph(int argc, const char **argv, const char *prefix) { - static struct option builtin_commit_graph_options[] = { - OPT_STRING(0, "object-dir", &opts.obj_dir, - N_("dir"), - N_("the object directory to store the graph")), - OPT_END(), - }; + struct option *no_options = parse_options_dup(NULL); + struct option *builtin_commit_graph_options = add_common_options(no_options); git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, From patchwork Mon Feb 15 18:41: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: 12089107 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 2A68FC433E0 for ; Mon, 15 Feb 2021 18:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB31260202 for ; Mon, 15 Feb 2021 18:44:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbhBOSnz (ORCPT ); Mon, 15 Feb 2021 13:43:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbhBOSm0 (ORCPT ); Mon, 15 Feb 2021 13:42:26 -0500 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 D57B0C061788 for ; Mon, 15 Feb 2021 10:41:45 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id l17so7020703wmq.2 for ; Mon, 15 Feb 2021 10:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OhmRgVhh+2U3JbAOPK2kv2BKguDIUQsYRGPfRdh/z28=; b=IPi498Kb+PLKuWvxH7OJHGgI8Wu8cYw3OBIfFPsALmnNoMWpn5jZX8EW/n+lAEDsqv myt2PF8f2AhmaJlKF/9LGkn7WGH70A/rCbztb+XvYbjz6V7exSThmj05C6q9BUGUAqLn FA+rtnx0ZsY6szOfVz9EzEP4W1w2BG+2ArB364vQoWeNbHspFG/1r/VJyk+oi2qz4LHG nI02kMg4ZORcxi2LXH1Ibvr/GCm966BivHiIeRbJ4rQjxLCr8LCmDVkRxGgqs8Sind/l 6Q6Ww5zM2e2Tl4UpN4PNRNDQtsaIeOrk1lHDoR5CghHPBqyOavjHJl2TU6ifqdBuwQ8J FlEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OhmRgVhh+2U3JbAOPK2kv2BKguDIUQsYRGPfRdh/z28=; b=cLk5a0YYDDmHpf4ic+Ohp7p+np0hy8UxcO/zASCZkdWC+Oyv29SV9hv1rhUPHPkGAz RcZUvfD9GE+80Urh3uhl8Iew0EGkfTX4fgxW4DHPDdmaGcQfTigdiCg2Qs2wRTilitQf kSuU6WLaAfGZH8H8VdL6t9MEK+TRSt67XjuLiGcJZk4XttHdzvFEDNMxL6DyC5HbGXJh 3fwAq1ufM4QNdi8tIviQG6WJP1fRA76knIEeN6qOATeUehqGCckm3PE2bPYGbgZ5uT3z y3kyRo24zD70KGfR+mZbN8o+fV10VfLtOVvPo95wOdNXloWQTKc0kb2ZO8gC25XrL+kz BlkQ== X-Gm-Message-State: AOAM530HGA9ZTPp+VT/6DuHTjCrght7c8ACShZjtsCVStqGGppOsVVqB ebcRVimqm/OEFtu1rDzkUVhR+VO0ORSzmw== X-Google-Smtp-Source: ABdhPJwW1ZWhNLAfSJVP64IVU8s6QmDk/mkNNc7pitsIWOzv6t68yDxS5BuZR+O1dthZuX0lSeXPiw== X-Received: by 2002:a1c:2d87:: with SMTP id t129mr163751wmt.121.1613414504343; Mon, 15 Feb 2021 10:41:44 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v12sm11258979wrv.69.2021.02.15.10.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 10:41:43 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , dstolee@microsoft.com, =?utf-8?q?SZEDER_G=C3=A1bor?= , peff@peff.net, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/5] commit-graph: refactor dispatch loop for style Date: Mon, 15 Feb 2021 19:41:17 +0100 Message-Id: <20210215184118.11306-5-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <87r1lhb6z7.fsf@evledraar.gmail.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org I think it's more readable to have one if/elsif/else chain here than the code this replaces. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index a7718b2025..66fbdb7cb1 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -334,13 +334,11 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix) save_commit_buffer = 0; - if (argc > 0) { - if (!strcmp(argv[0], "verify")) - return graph_verify(argc, argv); - if (!strcmp(argv[0], "write")) - return graph_write(argc, argv); - } - - usage_with_options(builtin_commit_graph_usage, - builtin_commit_graph_options); + if (argc && !strcmp(argv[0], "verify")) + return graph_verify(argc, argv); + else if (argc && !strcmp(argv[0], "write")) + return graph_write(argc, argv); + else + usage_with_options(builtin_commit_graph_usage, + builtin_commit_graph_options); } From patchwork Mon Feb 15 18:41: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: 12089111 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 49719C433E0 for ; Mon, 15 Feb 2021 18:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E1C260202 for ; Mon, 15 Feb 2021 18:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbhBOSos (ORCPT ); Mon, 15 Feb 2021 13:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbhBOSnf (ORCPT ); Mon, 15 Feb 2021 13:43:35 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95008C06178A for ; Mon, 15 Feb 2021 10:41:46 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id v1so10151854wrd.6 for ; Mon, 15 Feb 2021 10:41:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wgn004G3xcRSnJBx6EUVAXcvT7DfGNah5ap9esCamJE=; b=eaYwQ0o2nQyTjLD0oy1tgpI+75Kwbw4z/uS5fF9tVQ9Nmnwq9hUHxxOthYscQreXzV KkNneDQLQwthG81LC25MYVVkqimTVAPJZa2c7o9IqPTt5KXAqT8XSZWsGCcF3/bdiKUB UsDKI1uaVGh2ZUgYi3bgFEQak2v8zieHgBTNNEBuhmVvQ5XGL94fgdf5+aMsD0X+mlX7 UG8L0Zl9mqnU5xhELW9yHtp0bBdKc9lcoxV7P1SNNrSMrLOsNh1lntI/Cz2N0Own0QYd ZK0bYJQFiMaRFLw6lgWHSAkMvk1fUgqhJtc8TFdSPWExGon1OFY3+HOmnxa9uVWHISBb yfYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wgn004G3xcRSnJBx6EUVAXcvT7DfGNah5ap9esCamJE=; b=jqvr62rCUm1E0GJvK5RPif+7NunD8jymTUr2RTYTgcwEmFjq8OxaTbr7tmhKI0AuKJ bj5HB02ME0E5Ncao87qJ2cUQr/q9RcxkopH+C9RXWVzH7apR9xLNxmE0nijtyFOi5QjW GO7pO+tQ9izSnCWgqbMq/5N+phHL9bhzS3IlKGUifCzRbikp1JDOykx5YyekTlEeK3aT 3R6Rpt/Uc2wPIOyq37SJh19a/e6Ie5AbdYOy3jZ/ImQ59hPXO/UbWkkTiaijhusVX6pu t0LTCFKkC/j2KWsDnLiEUSsYvdXKLq8YcR2Mv9Sw9U6M6Am5gmH59ZOHEB6CHyypvAX1 VsSw== X-Gm-Message-State: AOAM530viMVuJwKmnpg+MPPhPT8QyN9mvnPNPRlW9VrhG+6MsIIeb+fq NpaZGW3XZALexlG3eYyVdoZMcAjVBrZNwg== X-Google-Smtp-Source: ABdhPJx4uj8CXKiKS338AEnfhHArjGPPBy9SqmstKn9TxE8sYeP37mmQHB/EEIP4Rm20B21/wMKT/w== X-Received: by 2002:adf:f2c1:: with SMTP id d1mr20329461wrp.345.1613414505087; Mon, 15 Feb 2021 10:41:45 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v12sm11258979wrv.69.2021.02.15.10.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 10:41:44 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , dstolee@microsoft.com, =?utf-8?q?SZEDER_G=C3=A1bor?= , peff@peff.net, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/5] commit-graph: show usage on "commit-graph [write|verify] garbage" Date: Mon, 15 Feb 2021 19:41:18 +0100 Message-Id: <20210215184118.11306-6-avarab@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 In-Reply-To: <87r1lhb6z7.fsf@evledraar.gmail.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the parse_options() invocation in the commit-graph code to make sense. We're calling it twice, once for common options parsing, and then for the sub-commands. But we never checked if we had something leftover in argc in "write" or "verify", as a result we'd silently accept garbage in these subcommands. Let's not do that. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 10 ++++++++-- t/t5318-commit-graph.sh | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 66fbdb7cb1..cb57771026 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -104,7 +104,10 @@ static int graph_verify(int argc, const char **argv) opts.progress = isatty(2); argc = parse_options(argc, argv, NULL, options, - builtin_commit_graph_verify_usage, 0); + builtin_commit_graph_verify_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_commit_graph_verify_usage, options); if (!opts.obj_dir) opts.obj_dir = get_object_directory(); @@ -261,7 +264,10 @@ static int graph_write(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, - builtin_commit_graph_write_usage, 0); + builtin_commit_graph_write_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_commit_graph_write_usage, options); if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1) die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs")); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 567e68bd93..3f1c6dbc8f 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -7,7 +7,9 @@ GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 test_expect_success 'usage' ' test_expect_code 129 git commit-graph -h 2>err && - ! grep error: err + ! grep error: err && + test_expect_code 129 git commit-graph write blah && + test_expect_code 129 git commit-graph write verify ' test_expect_success 'setup full repo' '