From patchwork Sun Jul 18 07:58: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: 12384171 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 D4959C636CB for ; Sun, 18 Jul 2021 07:58:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D1A66113D for ; Sun, 18 Jul 2021 07:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230446AbhGRIBP (ORCPT ); Sun, 18 Jul 2021 04:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbhGRIBN (ORCPT ); Sun, 18 Jul 2021 04:01:13 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC612C061764 for ; Sun, 18 Jul 2021 00:58:15 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso8965727wmc.1 for ; Sun, 18 Jul 2021 00:58:15 -0700 (PDT) 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=7BebBrT1z13jZy4/OeyjVgLYbjRLRxnHQ74riD+1XFQ=; b=GKVTDlHaUBcD2C5dKn48uLqhxK0l/F1xQmdEwsKbv/ij6QoK01/zRK3moSrttryU0p Wyzlk3YsSrEFkR4P4k816NoBp5Sz3PeB723clS1L139txB71oC2NDloPjDA/YEsCRGr+ u4q4bjjGaLe6bylTSuZhfWGUiDEEdP/hcR/Y1iQCBPjzrIZR+TbaviBODL2qaLILTTvD eOTd207CZ6A4HnyPQGPuoXx19AU391WrvBQ4lEr7AdCQMvffn4uVUOvcWytva/I02ODt 4f5EykMzdJLFWesNAlUHumvu9eASyadBTZlfVu2QbIoSe1dwCpG1kTCQCg6BfkwZpSdc XXwA== 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=7BebBrT1z13jZy4/OeyjVgLYbjRLRxnHQ74riD+1XFQ=; b=bLOugB2v9GcZjnJmhY5aq/clgf7b/AKnvHPHL5DSDBArZepQUnj53CJeVP+k16O1oJ lZeicg0gJ9ZOGNCKtk27M8OImuJQtrYiaFMznx8qc/C8k5Jewzq0xSpA6X7XUAHQkilK PwlXhuMMu2P/it/XtwN4yhvsgA3qe3tMoaJTfJaJgYUgS3hfmm2OqmySznOs1l5iYILC 5AIIAIgWNpQX029ZW4jLpue4SVfDAWoTT7KD/6mmtt9hdqe6vo3l2UJYeM2zG+nFxDU0 s8a9JzZaS/uunR5rqElLeDcwpNhH0WCP7zUdW25g/uXMWD0oQFij0U4gmxx5Jm2dyMYu ywog== X-Gm-Message-State: AOAM531cjdD6Igv/WHXqyi9DSPRVR3O0HBIiVRG9OCLIcqUKJZS0Cs1/ Av4meSmmqna38TQ8I9zHH0oOTAJgtis= X-Google-Smtp-Source: ABdhPJwTWTThRx3KTNs4rf9KG7SBw9k+GmNrlqJYOSVl4OgXZ4UCu1P/K9HnBrjWuung4ipgcIMGgQ== X-Received: by 2002:a7b:ce05:: with SMTP id m5mr26673332wmc.64.1626595094145; Sun, 18 Jul 2021 00:58:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w3sm15904685wrt.55.2021.07.18.00.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 00:58:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v2 1/5] commit-graph: define common usage with a macro Date: Sun, 18 Jul 2021 09:58:05 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.873.g94a0c75983d In-Reply-To: References: 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). See b25b727494f (builtin/multi-pack-index.c: define common usage with a macro, 2021-03-30) for another use of this pattern (but on-list this one came first). 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 cd863152216..c3fa4fde3e4 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 Sun Jul 18 07:58:06 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: 12384169 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,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 DEDD7C636C8 for ; Sun, 18 Jul 2021 07:58:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF4D661181 for ; Sun, 18 Jul 2021 07:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbhGRIBQ (ORCPT ); Sun, 18 Jul 2021 04:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbhGRIBO (ORCPT ); Sun, 18 Jul 2021 04:01:14 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82286C061762 for ; Sun, 18 Jul 2021 00:58:16 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id q18-20020a1ce9120000b02901f259f3a250so8470928wmc.2 for ; Sun, 18 Jul 2021 00:58:16 -0700 (PDT) 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=Faxj3kQNzn2u6POh0UyjzFW/5xS59b0bu1X8MpZrKqQ=; b=qWCEj/Sm9ABPEI3QHd+arnQxTniwtBp19LcjCgyiKV8HwCAxvgQBdcNmHszCF4taYi OFNw+P2q8GAkPHT+SjgMVxl5Tb2aw/J/kwWXul7jf3Lc2uBcpsnvN1B3GQYguPO0OTFH qdNwFJgLoIAP25a4bg4FCNSGdU1wZBVVKxLe95CFh9D8O4tK+R0bSHT/tU6DyR+1LFv2 pejlRNqIwBMZzYiFPOH8leojH3IgBU5llN06fhRPZ26nHpfBV1IQwf4DXyr08gwp8A2E xkrXBg4s43+1jIdaIG5KwI6HM3DCPFyAK4ecsR0V6l5tWUX7k9oLgaOAcrr2V7TuKuml 2Rpg== 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=Faxj3kQNzn2u6POh0UyjzFW/5xS59b0bu1X8MpZrKqQ=; b=QBKl7heI+3PnMoKbsd/rsgeCrviP9ac5KsW1OPyC/v/Pmr8k+sd8NWDAYmMuQacJHD KT6YrIsgA/zkm0sDKkj344+RRZhMFjVMRWlhv/mIVKytFeQ0Jg0LE3xkP5dlSKDELaHd w8aK2RC+m0RBnI7w9xhRvEyQVXh05TfWfx/B+dQqLZpvnEQhXXKVoBQGHGgDCrf2Dei3 BoLxs5Itnn4JCwuPpMtX1yb7ChffJpsPjzq5GlqTEY+Wlkh5isGymoPc43+hji3mNU6x sEYKPcunZlNG77Va3SILyQ6DPvJFeAuMulgASdIZCHJ3X4W3CRWiIcwf1OrPy1vxaEan ZU2w== X-Gm-Message-State: AOAM531ZJQ59a/7sCXFzYKJxByvc7ae3PamPPsdBj0+xDHLFTI+xe6Wm 1A2XO/Kqa+ME2tq/0k9qel+5iwEzQGX8dg== X-Google-Smtp-Source: ABdhPJxAE5FWWnH7V7U9UDmlyFOHaZG/oYQ5/arxfhrS2XRSsCs8zhikLd8nGp99G5pNGAjMvpldag== X-Received: by 2002:a1c:790e:: with SMTP id l14mr25313364wme.119.1626595094942; Sun, 18 Jul 2021 00:58:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w3sm15904685wrt.55.2021.07.18.00.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 00:58:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v2 2/5] commit-graph: remove redundant handling of -h Date: Sun, 18 Jul 2021 09:58:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.873.g94a0c75983d In-Reply-To: References: 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 c3fa4fde3e4..baead04a03b 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 af88f805aa2..5fccce95724 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 Sun Jul 18 07:58:07 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: 12384173 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 EB830C636CD for ; Sun, 18 Jul 2021 07:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9A9861179 for ; Sun, 18 Jul 2021 07:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbhGRIBS (ORCPT ); Sun, 18 Jul 2021 04:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbhGRIBP (ORCPT ); Sun, 18 Jul 2021 04:01:15 -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 37A6EC061762 for ; Sun, 18 Jul 2021 00:58:17 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id b14-20020a1c1b0e0000b02901fc3a62af78so10790369wmb.3 for ; Sun, 18 Jul 2021 00:58:17 -0700 (PDT) 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=ZH5QINsK1mL1+JJQ+Ys8lLQMOPyZFa/VFhit+5CLixo=; b=Ab12d36QAmuGQ/szrpTxLQSbe0Py0TJP9ZqaOnI5ROh/VxqEBRHsOpHuNVaEd1GBhZ LXABCxfOB96R9QST+X/Rh6ba5SpTQeeXojvT0zDR819mrTfITZK4RAljpb+1FJrbzq3f vs7WOK5D04kmK3UGDkaepjniZVf4fnVAOHeQUo5FICgFFotR1janehCUyHw2DwV9vml7 2/3jAmzMLsHq17CpXsVVtffEV+ggD4vyh0jDV81b1z5ggqwqLOTmO6oP1guG3GaNVKoI d52Aj8j/Y6PujIriMvxypx6PNZJR1jtH50vZppmdmx8yuFPd5hJ6OT4hKc+I1X2uWk1Q nnAQ== 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=ZH5QINsK1mL1+JJQ+Ys8lLQMOPyZFa/VFhit+5CLixo=; b=ZQaqzsB9EX5rzOqjHB8BQKIupVxozcz9UBWZGP1syKK0V9/3RS16p1bthbLNx6UOuV AOWqAT/A3m4VAhWaLxl4g2PhGYYXNCoFpTVADkDa2B8q9d/v1qvwRyNyuN/l+GS1DLZ1 6J1GOLkjN/A+tPobYLOTz5sJx+c0dgHowHWhrFvm4HzxcAI8fJwGNSxQyZYmWPPIfZVG usgf+PGdeQ9QMDWIaxnrth6Uye7XL+CyN8B1yfMkUhdvWHQlrZWdrduTGaMBDs6v5DjH 34K0K708f1A7YsVYAs1NjH5ZL/fuHkwSII7RPFo3nXFGhUBXiUAg6E9p4vu74YV+4/8M T1qg== X-Gm-Message-State: AOAM530W9vEHybfpZ5/2ao00J2nc8tM7xCLJw0M3JciKKFNOBq7zKP/J mPTAlGSOLmMoNqvu6ZfGNhYWQ6yeZ+5jEw== X-Google-Smtp-Source: ABdhPJxsaapgvvy7TZMjyIbbnVN9KK9+uxVG0uaZLHsxFJFg2LCEUxDasLEVSVsZv47n3RXm39s6wA== X-Received: by 2002:a05:600c:cb:: with SMTP id u11mr19530831wmm.66.1626595095607; Sun, 18 Jul 2021 00:58:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w3sm15904685wrt.55.2021.07.18.00.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 00:58:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v2 3/5] commit-graph: use parse_options_concat() Date: Sun, 18 Jul 2021 09:58:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.873.g94a0c75983d In-Reply-To: References: 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 --- builtin/commit-graph.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index baead04a03b..ff125adf2d5 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) { @@ -77,20 +92,18 @@ static int graph_verify(int argc, const char **argv) int flags = 0; 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(), }; + struct option *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) @@ -207,9 +220,6 @@ static int graph_write(int argc, const char **argv) struct progress *progress = 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(), }; + struct option *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 Sun Jul 18 07:58:08 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: 12384175 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 8D1DEC636CA for ; Sun, 18 Jul 2021 07:58:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 685536113D for ; Sun, 18 Jul 2021 07:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231222AbhGRIBT (ORCPT ); Sun, 18 Jul 2021 04:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbhGRIBQ (ORCPT ); Sun, 18 Jul 2021 04:01:16 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6236C061764 for ; Sun, 18 Jul 2021 00:58:17 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso8965742wmc.1 for ; Sun, 18 Jul 2021 00:58:17 -0700 (PDT) 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=H0/pq5ELG1v1AddUu0d034ambNU6TsAVgAEVaPkEce4=; b=QD55wopE41EMhuhA2vWgfwEWNaZ6BX4fLKCxggDI/aq7e/CL5twGyQvHpm0gBdC8Fn vM4j3YOYV/KH4vmkaPtKUs/NccXzxjmRil9JWYnUJufFu6x0lds9hg8ls8hvDwJZILHH tvpXWI26RYEgx9nPqFKMrzus6/8jwiUhjpydRTUjb6VN6ot6MHM4PqLHmbMk4PgL7y1+ SLezCHkZ4EpLFKeAUh47P45KfPx2NnLiiRdsC21vpUAY0nT5Ue5SgRAvpKOUL4HbfO4q dxvSE3ZPSy4iu520nrnTrTvNIajN0hNXezdsTCU8g05n6ZJvmloRtnhAYpNReMs3ekRe Dg5w== 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=H0/pq5ELG1v1AddUu0d034ambNU6TsAVgAEVaPkEce4=; b=KTbBirGH8IE41s8bHvC6im0yjJdDqF1mcT4DG1X0wx7RdXxzcEzpQn6adI1gpPwz9Y TH81xdTvK7nDBzocEdJYBOANE5wS5J0AI3J+AVqzYImKP/8PGtKeUoNwEEdGnN0LhSWu S5skRLc1yvs7qojLqJw0MNc2rHm4Pee4YHNTJukafbbDeOC00nbaX3TepT/lkfNsvfj3 N8wlGVV668XkFCHx9KmrTDn4cSf5GJAe3znODNfBXGbSBTH2foDBotVLK7jeUXzBA8Pq yn9sM161GTsnLLADcBnwQkDeZNbJxJAtRamGDRT6O7DwQUisoCpJZ5LGiV1DsOXw/TkY zlCQ== X-Gm-Message-State: AOAM5310kNfGeFA/t8iOZ1vxwDGj5WUtUSXxN4n4+URtu/R52q4fh8fq KvIkGt9spomuZSCrjAN2LS0Z3+Vjtc2n5A== X-Google-Smtp-Source: ABdhPJwirWMy/Q1fHbxjfTB08w4pLWnJ4D8akuyze9gbD4fVlipIWL+5L5ccS49TIbNZER+7aLQRnw== X-Received: by 2002:a1c:9d46:: with SMTP id g67mr26477378wme.188.1626595096302; Sun, 18 Jul 2021 00:58:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w3sm15904685wrt.55.2021.07.18.00.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 00:58:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v2 4/5] commit-graph: early exit to "usage" on !argc Date: Sun, 18 Jul 2021 09:58:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.873.g94a0c75983d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rather than guarding all of the !argc with an additional "if" arm let's do an early goto to "usage". This also makes it clear that "save_commit_buffer" is not needed in this case. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index ff125adf2d5..16d2c517e72 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -331,16 +331,17 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix) builtin_commit_graph_options, builtin_commit_graph_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc) + goto usage; 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); - } + if (!strcmp(argv[0], "verify")) + return graph_verify(argc, argv); + else if (argc && !strcmp(argv[0], "write")) + return graph_write(argc, argv); +usage: usage_with_options(builtin_commit_graph_usage, builtin_commit_graph_options); } From patchwork Sun Jul 18 07:58:09 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: 12384177 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 0636AC636CB for ; Sun, 18 Jul 2021 07:58:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC56461179 for ; Sun, 18 Jul 2021 07:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbhGRIBU (ORCPT ); Sun, 18 Jul 2021 04:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbhGRIBR (ORCPT ); Sun, 18 Jul 2021 04:01:17 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849E3C061762 for ; Sun, 18 Jul 2021 00:58:18 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l7so17483892wrv.7 for ; Sun, 18 Jul 2021 00:58:18 -0700 (PDT) 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=HcInMiKy6QIwPB9pu0S7hvC/P2xtfp/7oo4vUwvPHxI=; b=SSocmmtRS5DVlVaAoSIxE9KTD56ZFG74J3MXkhmVoy1n1ELWvCdeeXdzYziJYu0J9O 7T9M4gpJs0SXmIjTluiAH3X8Abn1tAAYGZFu0GVlRN3dqbQ4wWKkkFFAOdYro7OgQ+fr AG8lpNUiKtkw6c7XTalhszMSEdM8InqXjUoKMjCnUfYgrOG88vsaQIzP9SZ2Yx9PVbHF jqvWVzHr4yQHxOdupWGAflXJ+tRywuOQpD2wfj7yBIL1D/7Z6CwGBvvwr/J/KXeOOyFx CL2nIXhRo6rqsKspJ7se7CoPwG8Ag0/k2kB0ZjI9DuuiMOj0Y/rgFxMcFgGmxJRwp6gt 1wHg== 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=HcInMiKy6QIwPB9pu0S7hvC/P2xtfp/7oo4vUwvPHxI=; b=crmA2SFUFOEEqisT5YruklN6Daf4+mjm8FXspjcxeM0FZsIggoXo/YDBcAeBYZPnho 9v4yFysDsfCf+jYSvanCA9FUpIDJYDeLmzefQB8q7Hu+hpOfi2aIlrBQtLKhyqlfcGOG 1q911yN8PXTEucme/7f1++CoBD6SE60UiK9SAUuoCFQFH1203XcuL+c8AxE1r69QrjPJ X1Hg1V+qi7YMB5tFMELWWO1eVdpsJqrWs9w4MbUEfB804x9/xWRY0ue53NOYGFAqXQEJ poQRWG84sPrETYoMbpCvRvNrS+6RikOTApCQ1TDW505gx3BlmNcRx3mXRCYbLCy2pYhn 9wpw== X-Gm-Message-State: AOAM530zjLujuy5kSgDNG9+8AfD5fwk8RF0G/PTYpNsTnDjsAuxuHVYG 72O2HDiA5kZfmCbTOh68Da9jp0W7FeyuBA== X-Google-Smtp-Source: ABdhPJzfNHKhO5uOB3hRQRnMuc3f4YezMHR+Utc1W5poROK/CFtZf3/zR0B+iENc1ibMaxMGRXnsYQ== X-Received: by 2002:a05:6000:156c:: with SMTP id 12mr22940117wrz.400.1626595097000; Sun, 18 Jul 2021 00:58:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w3sm15904685wrt.55.2021.07.18.00.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 00:58:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v2 5/5] commit-graph: show usage on "commit-graph [write|verify] garbage" Date: Sun, 18 Jul 2021 09:58:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.873.g94a0c75983d In-Reply-To: References: 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 16d2c517e72..bb3e767db33 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 5fccce95724..5cf07a6dded 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' '