From patchwork Tue Jul 20 11:39:40 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: 12388069 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 5CE39C07E9B for ; Tue, 20 Jul 2021 11:40:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38CD661029 for ; Tue, 20 Jul 2021 11:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236024AbhGTK7y (ORCPT ); Tue, 20 Jul 2021 06:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234672AbhGTK71 (ORCPT ); Tue, 20 Jul 2021 06:59:27 -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 47068C061574 for ; Tue, 20 Jul 2021 04:40:05 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id f9so25630587wrq.11 for ; Tue, 20 Jul 2021 04:40:05 -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=VZ2EUNo9uPQsosjVpZ9cN4m5uape3nl0KcyFzD4FU2o=; b=PwVs4uFP6yssoY4L182OHWNbgBr9T6uovdPhaYiWYYw15t5a6d/0PoKEaphrqLGZv3 YVrCudHXH/q/h1OXCdc8ybCko9Tf5DGUWMBT7U9548ZJzo8oOBQuvA+5xVoOipO1uX57 YtK7CekKi34J1enxZIR4u3GNCGnENQhbpEJTrABgfn0isPbiif5Ct0JrPQ6a/yAu7h7T 6iaDUMOvRPz4Rm81InyX22u8RYrVXLBac6CWAlVCiO+LrtN8FYjtpXQo7yiHN0O4O0UP T+LZFcrVCtwVLRgzCgevMTxmiYg2lQJpadPxIhX24DXpNhHFxiFEGZalBoY/CmUKSmrZ XKlg== 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=VZ2EUNo9uPQsosjVpZ9cN4m5uape3nl0KcyFzD4FU2o=; b=tk/rrQcGE63wiyGkdLttvxTMKZw8Eu89T1eQFMM7olO7gfbAeHxoF/5vGKu/s5jnGm wtZUakndOI5FePJtdS4uBxQfwXa8uoj0Uk+GyVr3hXeU4Ke4XY8tKyza7gYx+V9o8WDb buFx4CIegd1M2axfqbREyoeVJK+a406Wg4aoOQUrt4lzPo3nt1JJqNcC/eZQ62+LRKCV I1guPWt+j2dn/DVFMPXxqRGrGUhf+ktmfiA/GkGCBSIhjWVJWIb0iJ7PW1XgoTG2uGPp sd7wdVyJSN/NNq0qHdL9nc3kBIXF4C5L34CjgGK9pqXAsFH5pde+LQO8Iue1e9UGccE5 OqhQ== X-Gm-Message-State: AOAM531+pJgvpa7xBoQPvd+N47s6hjgLhxxS94YhJXNO0sxC1TrZK2Wx Ou+b0wkJmOX8I1DHCVxUaRWe9UybkyVKWA== X-Google-Smtp-Source: ABdhPJwNcEB0EfJx+DndVbhLAPZ/HWpBnnI/JssjgJ4HZous6ixVHJIGRPc1gWk561j4+gGrTca/DQ== X-Received: by 2002:a5d:4812:: with SMTP id l18mr35842945wrq.68.1626781203652; Tue, 20 Jul 2021 04:40:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/6] commit-graph: define common usage with a macro Date: Tue, 20 Jul 2021 13:39:40 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf 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 | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index cd863152216..5af3cd7178f 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -9,26 +9,29 @@ #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] " - ""), +#define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \ + N_("git commit-graph verify [--object-dir ] [--shallow] [--[no-]progress]") + +#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] " \ + "") + +static const char * builtin_commit_graph_verify_usage[] = { + 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[] = { + 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 Tue Jul 20 11:39:41 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: 12388071 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 48945C07E9B for ; Tue, 20 Jul 2021 11:40:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 315DC610FB for ; Tue, 20 Jul 2021 11:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbhGTK76 (ORCPT ); Tue, 20 Jul 2021 06:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236431AbhGTK71 (ORCPT ); Tue, 20 Jul 2021 06:59:27 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15CA1C061766 for ; Tue, 20 Jul 2021 04:40:06 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k4so25633589wrc.8 for ; Tue, 20 Jul 2021 04:40:06 -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=1N/+jHSzN5qPgpwQ3/t5A8jSh4+PXGQsWz0aHk9tjF8=; b=uJ6mKynStiZP1nZL1P5qPxS09FKTyua/ERn+rUmvm31XwKMeKtIK3CYvcwjKp+k3Bi uJDrspUoQ6yGjm3TCdOWbAlHNBI5csPBhomShimkMxMdKoS1koL22y4LOVpzlztK3q0P T0lnMIhuP5qheILOuXTVboV3lpdk9NOXoa3UXybJLfhTJoIIoScB7ksK+x7eH2jv2SW7 ODYDxr9JczrekxJXWIKD7kOfXV3pJ8jkZkgmYWWWBDWJxGhq1rBRqwvf9JULacW3wDrk Go9tAN/n1y7qEcX49sd6DMxeRjbYIMacCZCdPbmdcH9G9+pXl9OODFWqyy6dqjMrc4FA uxCg== 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=1N/+jHSzN5qPgpwQ3/t5A8jSh4+PXGQsWz0aHk9tjF8=; b=PZ391KKPkJVaCh9l//2I0ZqA86O9vUVrkj3591Ki60TOaZDn9D1yAnsgxJlEwaLkmH I4cbBUw0Oux6A1brJO76rBFnBTzubN4qAKMgON5z4sLWTkNMaBI9qvLRGS7P/ZgBcJOa CGXcUyWjwgac47sMEhqRgeePZHmaxSmvvZmc0vgi9Eyxv3FWrY9Skc0ALN01EGAUGlFl lu+Cq29Z4s64MC0PlcwjTHJPSsBTDufBfcf0bza++YOD1KRCph7QKUtCF2zX3H58qCMo wD7uczDeKrRqlE01AETPERrbfYzizQ3IIHN6Ouzivnzby8g/2IJXP8/Lx9hoU61PD1Rj 9RJw== X-Gm-Message-State: AOAM531cKn5fFM3ruHZjNHf0x3zpDzRS7bdHacA2mG28E2gNT3Cqsvzi I1tw6j/4Szg84++Ra94+C6AbzpDnT6j4Bg== X-Google-Smtp-Source: ABdhPJzFP2WcPg7ddz8ZYJ9SIQSnrYW6faqnzMnU3oYwwYu0q9Ms2Ygz8doIFIo8dGpGjHFDFxyxkw== X-Received: by 2002:adf:eec5:: with SMTP id a5mr34821233wrp.317.1626781204483; Tue, 20 Jul 2021 04:40:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/6] commit-graph: remove redundant handling of -h Date: Tue, 20 Jul 2021 13:39:41 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf 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. We don't need a test for this, it's tested by the t0012-help.sh test added in d691551192a (t0012: test "-h" with builtins, 2017-05-30). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 5af3cd7178f..3cf18dc5345 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -321,10 +321,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, From patchwork Tue Jul 20 11:39:42 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: 12388073 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 06E10C07E95 for ; Tue, 20 Jul 2021 11:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6C1C6113C for ; Tue, 20 Jul 2021 11:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236461AbhGTLAk (ORCPT ); Tue, 20 Jul 2021 07:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236471AbhGTK73 (ORCPT ); Tue, 20 Jul 2021 06:59:29 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6478C061767 for ; Tue, 20 Jul 2021 04:40:06 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r11so25622440wro.9 for ; Tue, 20 Jul 2021 04:40:06 -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=tjUJV4naweGoHAw6GWtAUNF1QdMatwY4PNcC7RelCEc=; b=rDG9EFGR7QzUF+b5czDejk6I+CQC+70GMAHrm1KDOo0Vgw1NziZmyvzg9OrPS1X0CC cJD637/yg3tNRMMqvfIu4Qc5J0yNHk7We/RsFSnosSmEHe9Fs69kauUxGJjQsXQ7BEuL TG9vqi9j+FAy8e/K8LCXl6OvX9b93IQkZkXRFzef0Pg8tgonWFFqT3B5PuQSEDLoKaE0 qGlLNbL+vrLhrLCUtvlbePPHdA4UB/2G2mffkeCiqfgBUbSAxFRx9Bshj3ljzBCAqTrJ U6oDwCWcYZVKwfj+mC8u9kjNRjXf287oKnQqirt3SPC2M2kr5MBcvxOV71K1C1lzq9ft jKKA== 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=tjUJV4naweGoHAw6GWtAUNF1QdMatwY4PNcC7RelCEc=; b=umVfnMsZrd5lOcj84MiRhg/UpRBnaiNbCEERft7fPZut0WqN5JNaiIsxqygY6LeVYp mAZOPqNB5MhW6RIxFLIf5oWLxQcRfxAPhVKawUzUSPMyO9oMUp9aCYk2MrSkLMLh0xKo 55hjWA4O/WOiuJDfg8giTo97vQt2MCqXc1jBM6TdbsZggY6rWaB352hg57xHBnkTT0Ul mbQnsoidjLKojezuVgxwe6URHvHEmYZPaDJLkWxbQdqhtyeQyfT2nupRwyKS3wayrDEY MQb/Q16N8mbzReGQY3FWTVVRGD6KKSDCY4Ve5nBp33KilgPW1fGKe4xUEGYDEQfn7WIT Vyew== X-Gm-Message-State: AOAM532WNBECdDMQouMrZjDuZeMGAobNvmn82uiGtEkYY3xgyrqt9n90 j3Hz742+gNvLVTIRqqZVlJVY9Kx+MjeLWA== X-Google-Smtp-Source: ABdhPJykASa7Cu36ZabrOes5FFQoEo8Ti+/4Y2SbWumFtbGpMXIlfLxCotlKNCzWiI5hL1Gk2qvt0w== X-Received: by 2002:adf:f54c:: with SMTP id j12mr36237250wrp.109.1626781205258; Tue, 20 Jul 2021 04:40:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:04 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/6] commit-graph: use parse_options_concat() Date: Tue, 20 Jul 2021 13:39:42 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf 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), and the same pattern in the multi-pack-index command, see 60ca94769ce (builtin/multi-pack-index.c: split sub-commands, 2021-03-30). 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. Co-authored-by: Taylor Blau Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 3cf18dc5345..6e49184439f 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -46,6 +46,20 @@ static struct opts_commit_graph { int enable_changed_paths; } opts; +static struct option common_opts[] = { + 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() +}; + +static struct option *add_common_options(struct option *to) +{ + return parse_options_concat(common_opts, to); +} + static struct object_directory *find_odb(struct repository *r, const char *obj_dir) { @@ -79,20 +93,17 @@ 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 = add_common_options(builtin_commit_graph_verify_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) @@ -109,6 +120,7 @@ static int graph_verify(int argc, const char **argv) die_errno(_("Could not open commit-graph '%s'"), graph_name); FREE_AND_NULL(graph_name); + FREE_AND_NULL(options); if (open_ok) graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb); @@ -209,9 +221,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, @@ -222,7 +231,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, @@ -238,6 +246,7 @@ static int graph_write(int argc, const char **argv) 0, write_option_max_new_filters), OPT_END(), }; + struct option *options = add_common_options(builtin_commit_graph_write_options); opts.progress = isatty(2); opts.enable_changed_paths = -1; @@ -251,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) @@ -307,6 +316,7 @@ static int graph_write(int argc, const char **argv) result = 1; cleanup: + FREE_AND_NULL(options); string_list_clear(&pack_indexes, 0); strbuf_release(&buf); return result; @@ -314,12 +324,7 @@ 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 *builtin_commit_graph_options = common_opts; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, From patchwork Tue Jul 20 11:39:43 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: 12388075 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 BC09EC07E95 for ; Tue, 20 Jul 2021 11:42:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A617C6113C for ; Tue, 20 Jul 2021 11:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237017AbhGTLBO (ORCPT ); Tue, 20 Jul 2021 07:01:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236545AbhGTK7a (ORCPT ); Tue, 20 Jul 2021 06:59:30 -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 7F0C9C061768 for ; Tue, 20 Jul 2021 04:40:07 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id f9so25630720wrq.11 for ; Tue, 20 Jul 2021 04:40:07 -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=FFtkIu6h9h/31fzI/EXMc0altkrixdwUaXJuhNdbORs=; b=IC/Xw1fC9zJRK9UsRs0ye+kjSF07kvv+mLTG8+j7VldEOJa0RXN5VQFMdDJ5baErkf W3Ncowh2H5S6vfjqpZYEXDIwS9h1o0GBJ7kUyVvwTE0dlHXn8rnhB9Dm9EvSoHFUpOUB TZydcd4fiGkg1eWs0nG+PpJ2Q9WPmMj+z/IjJELfpxBdA+NhxLJoWYi0qd+e5rl5lJ2g Ir5otUivQJElhW1sqvEAE4DVtHdAiXwHyH5X6C7MGEb1W/Z5kuhv60SStm65hz4Y0OQS tSeasnMj1Eo1GRp58w4ANoIkdoQVlyTd8PL5sNLDz4uXnc6mycCGW9gkVQ5l8uMe6p/m DGdg== 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=FFtkIu6h9h/31fzI/EXMc0altkrixdwUaXJuhNdbORs=; b=Q+BEfIYv9edzF2MqlKfrm02J75lS6+1ce13NwmKT5vaRpvdecAhaaZH/G3jFxxAUY8 +ntL+M+maF3W3WX8n5p8GNlTmLKPPwpb+vNtCe81lis0fpAnekuVqQ2ZbNVlo+HqEifx Lc0OAR4JpO78OaIq0rFabA3EDrKn7FPFBYduaZbe8rnCnT1jdHcx1HPR82fR9YWqYbh7 hEVjjqJF6PBW0Am0RCQjxqmcrCDX7X+5UsiUt/bJ8xJe3UqoXtduP3DYJzPK8gAgyUvu ragfKJzVih92XDXEKHa5N0RWz6BJwMGxIrUNGEnBjg1VhXlcpUQoCspeYqsB+WjtJHYo +v+w== X-Gm-Message-State: AOAM530MjVXKAFlJAZG2ZCS/uVWSBod4mbdLDx/K5pZRObsk27rrZJHh gMhYZMdbD7VKs+Rp0wNdT/sW4Hu+5VnH9A== X-Google-Smtp-Source: ABdhPJyBu+s80qR1eAf1ydU8zL+I/cnoPRRP/OBAsYa9Yk9/ZhGeFSQuuu8vyz1PIrhK73xnqB9nig== X-Received: by 2002:a5d:4a85:: with SMTP id o5mr34956668wrq.410.1626781205933; Tue, 20 Jul 2021 04:40:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/6] multi-pack-index: refactor "goto usage" pattern Date: Tue, 20 Jul 2021 13:39:43 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the "goto usage" pattern added in cd57bc41bbc (builtin/multi-pack-index.c: display usage on unrecognized command, 2021-03-30) to maintain the same brevity, but doesn't run afoul of the recommendation in CodingGuidelines about braces: When there are multiple arms to a conditional and some of them require braces, enclose even a single line block in braces for consistency[...] Let's also change "argv == 0" to juts "!argv", per: Do not explicitly compare an integral value with constant 0 or '\0', or a pointer value with constant NULL[...] I'm changing this because in a subsequent commit I'll make builtin/commit-graph.c use the same pattern, having the two similarly structured commands match aids readability. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 5d3ea445fdb..2952388a8eb 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -164,7 +164,7 @@ int cmd_multi_pack_index(int argc, const char **argv, if (!opts.object_dir) opts.object_dir = get_object_directory(); - if (argc == 0) + if (!argc) goto usage; if (!strcmp(argv[0], "repack")) @@ -175,10 +175,9 @@ int cmd_multi_pack_index(int argc, const char **argv, return cmd_multi_pack_index_verify(argc, argv); else if (!strcmp(argv[0], "expire")) return cmd_multi_pack_index_expire(argc, argv); - else { + usage: - error(_("unrecognized subcommand: %s"), argv[0]); - usage_with_options(builtin_multi_pack_index_usage, - builtin_multi_pack_index_options); - } + error(_("unrecognized subcommand: %s"), argv[0]); + usage_with_options(builtin_multi_pack_index_usage, + builtin_multi_pack_index_options); } From patchwork Tue Jul 20 11:39:44 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: 12388079 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 4AEBAC07E9B for ; Tue, 20 Jul 2021 11:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35D0661029 for ; Tue, 20 Jul 2021 11:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237469AbhGTLCH (ORCPT ); Tue, 20 Jul 2021 07:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236848AbhGTK7d (ORCPT ); Tue, 20 Jul 2021 06:59:33 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E5EC0613DB for ; Tue, 20 Jul 2021 04:40:08 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id k4so25633736wrc.8 for ; Tue, 20 Jul 2021 04:40:08 -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=1MzRfzyqaVG9jzGJaiPUefdLQUsQ4UTbCbgFCyLTvks=; b=to9hbBJxRsikIIhwob6ct7YY8hQgI7ED6J9JW/dl9FpmDq85MyFaJBdSrF79L8QuxS h+BVcHP5viyL36AnbUNvuLFEkl690UvYmrL/5I72RdGJRzwDmfX1yjdV9OEpgyJccQ6/ VD2eqL93wU6NYoDEk579HT5AwUeD9aI0Ai+t5FIZtJLVe6PdHQKaG+BET6vZaTMGKUEq l4hKbeO88BYK8pv9S5KMSa/y1p/xqNoe927qaOSElfLZQoSnflcshEl2ojLID0VWS0kc N7nDE96PUYnLW+GfVR9Onji0TlFO+2fCQAXJKiHiJpvg+RHG36yUmV+C7qRyT2Us33Bb caCQ== 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=1MzRfzyqaVG9jzGJaiPUefdLQUsQ4UTbCbgFCyLTvks=; b=XdUf0n59tKLQbQ4NlLCOH74R1Kv2x1FdiMCl3xnq9J4SYl+aqL7cEw6OJ5Olu8qOd0 itNYFqiyI7fsaI36zb1fZstJZOMXFSMIIvInP1Z/VFG3OtcQw7Y/WmoQYWW75Ef1KmsS uJYLUQ9Q6luXfvDIjhnwAzDywo6vnn5UUvec+B8uJOzgzy4bxcXDEfUoX0d5dSnhNLJh DVsJk1XVx5Jt5P/KUa4bz71MT+keGwApd0/13ThgzsBSem0XFNDcvnv4sm3Yo0IkPgYY 6EHv3nsAfDronVtCCji4NJcnTLevCkp2BxHnzfh6b6RkwSZG6TlPfc5KqDDfQVjxtFx6 mehw== X-Gm-Message-State: AOAM530DIgqUpf/SCkU/es+dTeh25QeghSbAmZaJcxtdNaJVeMqJFAyU mcXau9kKNfJo1WoSJRsDPv+1gpAh7743Rw== X-Google-Smtp-Source: ABdhPJzR6+9GBO2EGP2GXS40lZ4818rq6vfl2aTGRpSZKvsHPpgSNiU6T+K+lf9rEKdEOz3Ozzoc/w== X-Received: by 2002:a5d:6850:: with SMTP id o16mr34276159wrw.319.1626781206686; Tue, 20 Jul 2021 04:40:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 5/6] commit-graph: early exit to "usage" on !argc Date: Tue, 20 Jul 2021 13:39:44 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf 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 6e49184439f..bf34aa43f22 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 Tue Jul 20 11:39:45 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: 12388077 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 C6A99C07E95 for ; Tue, 20 Jul 2021 11:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACE5961029 for ; Tue, 20 Jul 2021 11:42:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235368AbhGTLBy (ORCPT ); Tue, 20 Jul 2021 07:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236401AbhGTK7l (ORCPT ); Tue, 20 Jul 2021 06:59:41 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55136C0613DD for ; Tue, 20 Jul 2021 04:40:09 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so1305763wms.1 for ; Tue, 20 Jul 2021 04:40:09 -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=waP9c37Y2qR6tqt2P4b7cAqOtDg1FvYNwdRKPb1sN2I=; b=AOSzgBPvC0AkcztyJoAIcBeNKn4f0RqjN4A1MN+f3on1LZs6GFFrhz6SWyCTLOlqj0 c46JL245hLnCzXwwN7OYzWXUG8bSfxLETO5u9vKH9jz0tHJMTC841oZWFmO60cgUiWT2 xM9EztY/kel/7UeKJkV0dQMmtotOnuVbXsTswyohiEMaM5uxiTeWOuOU2Q5s9EyuxSy/ j7awZYXhA6DDiq6/LrdmoaTBEy2h0AwK/zZo0A0ZOxpLqDu3D45Khwjjfz4v1YfOxBAB JkcslluU5gTnDKbu1VsU6ELugUXZoOAtmmnxUiVQyr+ej8aGIhr5x+9msJ3wt8zierv7 F7Xw== 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=waP9c37Y2qR6tqt2P4b7cAqOtDg1FvYNwdRKPb1sN2I=; b=FXm+R29TMymcgJXwf6zfPicRqhobhRQeJTWCjWaWLTF9B9le9A6+P8CDNCMdI2qxXB HN7weOAyQ44BFLxEQCsihP5UzLpCkX449Aowd1wWGfE4NI2Ul90EhkPiQKGxlwXjqAbC Y4u2LkxpKemhyBY5C/HgCVkNa/P7zHt747yY64gtHLk/CVuEC3D1vbyS91+dLSenhtvY ln8HCK/na13o8whGluDxRjjy72ttGBvVbweysmsG7DG7ofFhZqytXB9kbuM8EMw7krrg Ywf2x4Wn+H9ZWFc3NypvEU7jP5hR/Am0tbl4mG8eeExcBszqB+EpjWeqiyemuUN872Pz ImwA== X-Gm-Message-State: AOAM533Deif+1mP7qQYcMkalPbkjnIrtzczOLAAVdRUX9GnMPrU/mE5X GFEfeFLR3pQMJS68ndV27NjgTNItUlF28w== X-Google-Smtp-Source: ABdhPJwqmKej4wjTk+KpINY/8ViFmu6m2BKIqzGqNY1MKSy4hZrzItBe4cPbhV8q1YlE6k+rv98+Jg== X-Received: by 2002:a05:600c:1d04:: with SMTP id l4mr23844311wms.130.1626781207697; Tue, 20 Jul 2021 04:40:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y66sm19683595wmy.39.2021.07.20.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 04:40:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 6/6] commit-graph: show usage on "commit-graph [write|verify] garbage" Date: Tue, 20 Jul 2021 13:39:45 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf 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 | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index bf34aa43f22..88cbcb5a64f 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 af88f805aa2..09a2ccd2920 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 write blah && + test_expect_code 129 git commit-graph write verify +' + test_expect_success 'setup full repo' ' mkdir full && cd "$TRASH_DIRECTORY/full" &&