From patchwork Mon Aug 23 12:30: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: 12452675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86553C4320A for ; Mon, 23 Aug 2021 12:30:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 660A26137D for ; Mon, 23 Aug 2021 12:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236827AbhHWMbK (ORCPT ); Mon, 23 Aug 2021 08:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233755AbhHWMbJ (ORCPT ); Mon, 23 Aug 2021 08:31:09 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDDEC061575 for ; Mon, 23 Aug 2021 05:30:26 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id f10so10430287wml.2 for ; Mon, 23 Aug 2021 05:30:26 -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=eS96Q99bfUpICgKxez5/zucE8Gusp74fs94f0Yih1GY=; b=JNvTa4kcbKelC2nzV64pVSR4paiXbCcqKdFQ53LdnWDg5xrmXk740+dpimHefoppbv eTGIHTJ5hYyCnagDKz4ZCbfata4F9uhDC8iWgsI6IaMrUmqE93pAHgBLCgcvqU/oU/ut pKERgiP9cMCZB+6zoFX5V/whCutrebdZO2llEM/PUID3V/KxXW5ydEfpZ8CUNlzyTznf lt3YiHzpjCuZVlp/n23DgXNQ87WMYe1RtD19nDX0qZOBcyZDfwyZBDM2HvBvCfsmg+Ze z8PfU/FkrJu2POh9UGegEtu0r2IqgQxOHWFb0Ay5hMpvviF4ZVqCwX4KbpPssHpVntui lyEg== 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=eS96Q99bfUpICgKxez5/zucE8Gusp74fs94f0Yih1GY=; b=A2AWD5ugVFBrsgZ0704pDQabXQGoXfGhmtWaUhtRHVgMpmrg9pGpfpA5wX6lJXi5tC cgGhkZ7O/ZVX/hD4QNAbqJluZqa40g2atV+fK60/1POc0MbSUsVEHUHXipKXR82BoiHM 8WZqr6upZ1pQjMeH9C3hykRSvlEyRhHB06R/GQk9RSF2MdiVjKYRh1XOb8Mcdbn7ZQPW dCLWkc1jZsy4jU4/WnKP4UMVH/RKpatYF6BJCkgizMrHJZXOvQeTjlABvnwxDgx28AXV de8ofSL41J7Gx1LXKnOUWL6GD8SYWE8Ao/hKYVyFvokCSKA6SCTrF81SvDjCwXAvL6zm BPxQ== X-Gm-Message-State: AOAM531MG2zvot/wuF+gRVSmSTZX56PXI3e7U9ZOMhcij2uGeha+hD6o +XF8qdHT3W8Bu9flqFE3gOyAqXEe/MKlQRDe X-Google-Smtp-Source: ABdhPJzbvyADAB3KV8JzAzTGca6hnDJnfcso58Nl9iQHTlZXlbKveJXk91rHQQyG9Dt57eHG2Lt9PA== X-Received: by 2002:a05:600c:230c:: with SMTP id 12mr2236852wmo.41.1629721825251; Mon, 23 Aug 2021 05:30:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 1/7] commit-graph: define common usage with a macro Date: Mon, 23 Aug 2021 14:30:15 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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 Mon Aug 23 12:30: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: 12452677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EDF7C4338F for ; Mon, 23 Aug 2021 12:30:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 614E36138E for ; Mon, 23 Aug 2021 12:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236962AbhHWMbL (ORCPT ); Mon, 23 Aug 2021 08:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233755AbhHWMbK (ORCPT ); Mon, 23 Aug 2021 08:31:10 -0400 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 C588FC061575 for ; Mon, 23 Aug 2021 05:30:27 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id i6so2277741wrv.2 for ; Mon, 23 Aug 2021 05:30:27 -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=Y4nqLyUylM18RJa+zZi69IYzBmvhRXYaK1BbNK2tJus=; b=NDeQgKCKVhOehS2B59pPfx2y5KlFAkHrHAdtiQoLvAYyrPDtm5kUELr7Wbu3YzHqo1 RLURTXOMkPgf+Ldtmw8srY1oPaBot11H+W/3bm23DI7Sgp415LYqp7fwEmtx/nH6hcoy ++ea4v6KztEmoIkdWoPeNKwcuoqekRGnUisDTHLgOU8nSuSzgABhygcZnRVIaw6ArC2w +ww9XoeeoD2WMcsmk8Qi5doZ9WX8BO0DSn+OKHMOF2K98fbAUlBiQLoeQ9D5gqc1CAbx o1fAhyVA33s9N9oHyBZVN0IuX++69EATIyPzMFJwHMAkvlV+0HykCUJrJYu32UfnYWd9 pwsw== 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=Y4nqLyUylM18RJa+zZi69IYzBmvhRXYaK1BbNK2tJus=; b=hzK6hv8YoKJLVYIChwx3zt7mWkr8CQqdqBpO5KQs2rva2fwmwNI6zDYk4l883mFnHx tHGqEkgwv+2NBU3YMTvTuVdIe0OiulWNFqqMAIObUIaar8HaUoJI8h9oV++4Kgl0s/j6 w+jK5kUOWaRvVR8+j8GQmpsJAluOpsEfNEZnWL1l6JrmhSHzqcpJ7NiJEX+lWgFCctZi 7CknggAZlgXVRQB9DqRVjznpdJF773iig0WlM3fi5EVAQv1fWcTrb4EL6SUZ+SgNjah3 haDbo1H9GcFGO+8SZSdc7MpyX08yUHobGtUrQf56IzuSqKdxRyJ7raJdCiwSh6rxalvJ gJmQ== X-Gm-Message-State: AOAM533Ha5AFkGQHwqPkelr1EcVEzdnU7Zsj654N1VFo7BSJ6OzGOLCV JLN7ACtg0Xf1R2/rQAU1hK5yrUxJUaCu/P7R X-Google-Smtp-Source: ABdhPJwQgcx5R3mVa2JNpYcO5bdxbm0Q1dVI944Qd+xUwmc/keBd2kqxBkjydAqG3EwPEyrqkfQLHQ== X-Received: by 2002:a5d:58da:: with SMTP id o26mr13959042wrf.140.1629721826206; Mon, 23 Aug 2021 05:30:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 2/7] commit-graph: remove redundant handling of -h Date: Mon, 23 Aug 2021 14:30:16 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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 Mon Aug 23 12:30: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: 12452679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA558C432BE for ; Mon, 23 Aug 2021 12:30:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFB07604DB for ; Mon, 23 Aug 2021 12:30:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237046AbhHWMbN (ORCPT ); Mon, 23 Aug 2021 08:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236940AbhHWMbL (ORCPT ); Mon, 23 Aug 2021 08:31:11 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9658DC061575 for ; Mon, 23 Aug 2021 05:30:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id x12so26001565wrr.11 for ; Mon, 23 Aug 2021 05:30:28 -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=NPFxgggzbsmqdgg+j2gZfx6qsTT1pjjh1Kd79dU8ggo=; b=DYOlHM5D9ZmWkINQ9RhNErg81nXiOKF7rJ1rYgS2yBjyDtdjnYIKYvt01alFgZo+rp 31pW1LTzpQTpXQz/rKD1b/RC2d/NpkPCcut/EXw31K9Z9ha8COeCMW2v8Webo+MX5UbU LVL8HoHtxKJfa0plx/lsNbfuyTWP66SQx+vx5MfVfRVPdSnFe2BeG2kkL1JFmPhAXkAt 1dfJqIYAkTteFIPSBPFDMQhybkNfFu3jRkSgqMq7WPFsm8LLidQAtt2mZBPjxYb9KRks zfXBSBupAiLSTKg3OhY8Z6tTsMK8cimqazRUYYZA6gNiT3ZHNus8UtJQIkLPPQboyI6J ki6g== 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=NPFxgggzbsmqdgg+j2gZfx6qsTT1pjjh1Kd79dU8ggo=; b=YYvkH8xC3VE1vw1Fa79r9DFvP6enE5P8W4HlkDhBJOSpNk/To8h4f1yfrBArWAU4YF wxPErCjfDnSIw7HjFHdyyPtexUTtGt+UYNRPvOXtzHi0XYOzRGTYO3Z5uNPTJC/9BoSC FKPidixH3V6c4E0/8ie8rfmrstm5750IHdd+as/aNsDAD7RNdhYMDpJoKJWFA7pyFNT8 FJoo5x2Ywm9eM6v+d6EoFQHujBA2TLJeyKwzbNdlImmqzr027A1g+pDBKoFDC6aGtVzh bVmXZD6DVu8QsrjVrNsN9pCcRcaErqO2sr/aT8dhGmHG0TBo/hsWF0RZfqpsjVisx0vq +n/g== X-Gm-Message-State: AOAM533DmkARihbWhJ7Mhlu11q3opOIiwAbF4kd1tlHsVBcsYcE6HDoc BcuwiO0klIifWKF44ZHKzMicK5i0fzobhDlV X-Google-Smtp-Source: ABdhPJy7v128PM067Rj71YU5fcKaDrXJS2aHQ7mZOT6s51kAf8oamGdZF8R0eB7Vm46t2l7YEoDMbQ== X-Received: by 2002:adf:e6c5:: with SMTP id y5mr8391318wrm.198.1629721827004; Mon, 23 Aug 2021 05:30:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 3/7] commit-graph: use parse_options_concat() Date: Mon, 23 Aug 2021 14:30:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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 Mon Aug 23 12:30: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: 12452681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EA83C4338F for ; Mon, 23 Aug 2021 12:30:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 106576138E for ; Mon, 23 Aug 2021 12:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237111AbhHWMbO (ORCPT ); Mon, 23 Aug 2021 08:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236969AbhHWMbM (ORCPT ); Mon, 23 Aug 2021 08:31:12 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98661C061760 for ; Mon, 23 Aug 2021 05:30:29 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id u16so26048635wrn.5 for ; Mon, 23 Aug 2021 05:30:29 -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=9lp5unAvY43JpRlq0qN6DDJktOgftnOZWlrRnhbdyXM=; b=BqYgqO6vtFTlyyW1uxWLPa0+qj6taK5+p3MY/MHWn9V+y149uooh/3T14zKT676bvR 2H82gDURw+ZTRTV5dTQ3aKjIJYknGAAR29wKzMCeL9lprXMJWEsyeDF8GiLTmUxc33SC tCdLMSeGB7aRMeHPx5MKbUYdEw9WUtkA1InX7Wtyo+4Pwx26UqaGGKcTuUj+VDJcxp9Q lFUny5SZWTLVIlUTOyda3khNjc4JO++bFKC4CNey94pfPzQ4HUEiVARw+j5Q48L8OPod v69tzvLo5FrXU+ev6vGoQ7zoD/BbFo3cAAGFlLYIrEHqnOOcekycUwIuNWYZz1f+wqgy MlWA== 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=9lp5unAvY43JpRlq0qN6DDJktOgftnOZWlrRnhbdyXM=; b=HLu3Gl75TQd7MnaoL4p0R83yB+Wx+QvKb9vP42JuRPfJGKhhag06vpr3PpAbLgnzCh XTmVCR4BMLvQNvKPn5bY7/IBTE8Q1wr4GY5q1tj5TZeqnXAMRyn5cysLybUvbT51E93v 9PbEE1edFlg8eJtAHtU+wGKWYA/LZ/YX5yLhXqPsRsncX4d1buPLKlj/qrr8V47ARKhF E50UEjk2y7ELkRa2hZAXEYxcdp9AaQ8AqucxayHWIybi7e+qdY060XRrG0UbPZSiYKZF a+FfBga0X5nkvj0MV6EZEA7jEuYVK4MokPX3OBKWARWYSHf3XUkCQY0BHojCGKCIWqnA nplw== X-Gm-Message-State: AOAM531tZmQM6QLMywNP1ln6WTIhK5SwW8fPCFhYox+XF6YxWhcZICWg Q1styeLRWsj/5YC6kCTCfTtH0eU0URP9UimD X-Google-Smtp-Source: ABdhPJzREL3URetnba9k0XsqDdNJRt63Bl2L4K8H7pd2jJ5wjbk2fD3hxLoGdbt4Q+bXDkETVkCQWQ== X-Received: by 2002:adf:fd51:: with SMTP id h17mr10874977wrs.178.1629721828009; Mon, 23 Aug 2021 05:30:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 4/7] multi-pack-index: refactor "goto usage" pattern Date: Mon, 23 Aug 2021 14:30:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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) and 88617d11f9d (multi-pack-index: fix potential segfault without sub-command, 2021-07-19) to maintain the same brevity, but in a form that 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 --- 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 8ff0dee2ecb..649aa5f9ab2 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 { - error(_("unrecognized subcommand: %s"), argv[0]); + + error(_("unrecognized subcommand: %s"), argv[0]); usage: - usage_with_options(builtin_multi_pack_index_usage, - builtin_multi_pack_index_options); - } + usage_with_options(builtin_multi_pack_index_usage, + builtin_multi_pack_index_options); } From patchwork Mon Aug 23 12:30:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12452683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44DBAC432BE for ; Mon, 23 Aug 2021 12:30:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E647604DB for ; Mon, 23 Aug 2021 12:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237080AbhHWMbP (ORCPT ); Mon, 23 Aug 2021 08:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbhHWMbM (ORCPT ); Mon, 23 Aug 2021 08:31:12 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF1CC0613C1 for ; Mon, 23 Aug 2021 05:30:30 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id q11so26056601wrr.9 for ; Mon, 23 Aug 2021 05:30:30 -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=/k7XR1RTq0MsRi0MceWmd+PL+5wTKhx3oIzIjx55faU=; b=qtqUdiazYBk6kvhmMbzhMx3oasDDDqIVA9SsCetzqttw7oo4QlvMeVhpuWgq5LZU2l /sTDtkVuZdKOmZLu2LMCJ9eW8otabzbqrD45OCvdsTZIGXV6//IrnvQvrgrnDtjkfvo4 PrAhD/Ei0mDCdT50yN0PkNe8DUXYkJU1E9bz7eoJhG2LG8yrwtWg9gZBcC9ZwHPQtwy+ u6R94ZtbFCzI3RPahbqfHI1opwuPaQPca1wVNcmPjmw24qOUp0Jqgpwz8gUp+bkt2TTP jzKyXMCqShVW2vHziMqBFiSy9zOFuELtRLSGpmFmWeftyAOQBqKimeVvBC6htoq8t5Vp ggBg== 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=/k7XR1RTq0MsRi0MceWmd+PL+5wTKhx3oIzIjx55faU=; b=VNJYaE8NITMpB0rrdbkw348S6/A9l+3xKPWVGQm7NOv+xZ70m7ML/N1/p9ZRt3Z5qo QKtUJXJY/YeJcoh+i9qpot8qPECd04Bo7+JWW6kPfOSzivtkuYuEiXuOPGV3TGeg1FHi CWZdALEZgfSKAg1FES8ihVrw+UjxjQUCDOrWdYT+921r9rAEfq3U+//TacXVzvxHAK76 6lgreINtD/Y/Jjs6G9y8+AeiNSQswykdw/OVOX9EC5OJSLJL9Jn+BV/o8E+sL6sfK5HY uBT2XK9l8pnisL7OS8b1Lbke+fd1WDkETYtGb3peL9utTvlDGcwl32CF+ao1YCOOeT8O L+6w== X-Gm-Message-State: AOAM5317fxuiNNuyEWAvFUJLaKm87LDI8IIoKGo/XHqk8G55AOQec2tr pTuVRVNvAhzdI2256nC+d+/xX9UoFFTKbmCD X-Google-Smtp-Source: ABdhPJzAnplEPgZihVamQW4UA1/8fKT++NeRQLVwCaGf3G9wTZZLy6sRZ67YIsrz8DBxsJy0+MvbTQ== X-Received: by 2002:a5d:4010:: with SMTP id n16mr12976078wrp.378.1629721828719; Mon, 23 Aug 2021 05:30:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 5/7] commit-graph: early exit to "usage" on !argc Date: Mon, 23 Aug 2021 14:30:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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 Mon Aug 23 12:30:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12452685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0819C4338F for ; Mon, 23 Aug 2021 12:30:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8103C604DB for ; Mon, 23 Aug 2021 12:30:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237112AbhHWMbQ (ORCPT ); Mon, 23 Aug 2021 08:31:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237034AbhHWMbN (ORCPT ); Mon, 23 Aug 2021 08:31:13 -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 19338C061575 for ; Mon, 23 Aug 2021 05:30:31 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id d22-20020a1c1d16000000b002e7777970f0so190910wmd.3 for ; Mon, 23 Aug 2021 05:30:31 -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=R/vSMw9jtVSN51XI2ETTdUtRFTm2nWIpWxSGXYF6QTk=; b=LzEpPXLeAGgYOW1MUyF+RBZb4gP+4ORpVsYPYoLkFGqu6FRRA42ZxB4kz5co+KNxwQ 1lsiaLx6vPz6YIFOtI2Ln1Xehs8kOtQgYIpXiNww6G+4Xb7NZkUn5GMdAUtofhkjY81R o7N7BdOcmf9seLY6aH6P5J98W73j73Zldw0sYR1kX47EWFdNdI5ufiPa4wEXzsWISc2M e5i6FgcdZYyal852xRAVIIBLlfwNGIkIdMS/YMaqEWi7ee8EXM4w+ItTbTA3sQu9vSbN NR/gYgxoa34BnjEKfxx71U6FBkf+4WtT2syYsphgFExk9xAkIVdhXN6ML9UpjCrVheTq a5OQ== 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=R/vSMw9jtVSN51XI2ETTdUtRFTm2nWIpWxSGXYF6QTk=; b=Y5WJdJY85oaEpSkoMuOF23OnAETaka48yoI4Z6wwfZPGPaPrQogqDbpf0FR7Pj8HzW oHNpBCavhJIasVveXUT2hLRTUUHveybR8NWX1UCIeD8zCxHi8CkuGXASy7feOmubtYJj 3o5/jO1H9m9e5qhau/xO/GRB5tHETYYZylNzI0b3FQfj+pkWT8Xqv2N10epVaDKLqjHB bDAvlmuumHlxHhLk42uFVVxqco0x+QXQ0y5j+Va8pgQMsw2Gd1iYfHH6vcj9wHVTnjz3 SF/iBohyHiN2R/q9udyNaGfk4GWE+7e3GXPU7VTMxTvWHUR8f7W03GRBbf0lPw46kM/W aEoA== X-Gm-Message-State: AOAM533MRL8RL1BYnexzBbyjOUROaKdN9i/TRl4Ro5m2RNnuhaQDB8cd YuVx/DDWxD2fq/l0pgXGIND16qBjKegBesZY X-Google-Smtp-Source: ABdhPJyOCrFWz+TIo9ZxGCE4WLORYciDtGCsymREVM5XKL4EPSHUb2Xdw6XJy95Ic24LVw4sgW7iKA== X-Received: by 2002:a1c:7dd0:: with SMTP id y199mr16399407wmc.148.1629721829448; Mon, 23 Aug 2021 05:30:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 6/7] commit-graph: show usage on "commit-graph [write|verify] garbage" Date: Mon, 23 Aug 2021 14:30:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca 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 error on unknown leftover argv elements, in addition to the existing and implicit erroring via parse_options() on unknown options. We'd already error in cmd_commit_graph() on e.g.: git commit-graph unknown verify git commit-graph --unknown verify But here we're calling parse_options() twice more for the "write" and "verify" subcommands. We did not do the same checking for leftover argv elements there. 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 | 4 ++++ t/t5318-commit-graph.sh | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index bf34aa43f22..0457903f18f 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -105,6 +105,8 @@ static int graph_verify(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, builtin_commit_graph_verify_usage, 0); + if (argc) + usage_with_options(builtin_commit_graph_verify_usage, options); if (!opts.obj_dir) opts.obj_dir = get_object_directory(); @@ -262,6 +264,8 @@ static int graph_write(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, builtin_commit_graph_write_usage, 0); + 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" && From patchwork Mon Aug 23 12:30:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12452687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCB0C432BE for ; Mon, 23 Aug 2021 12:30:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF69F6137D for ; Mon, 23 Aug 2021 12:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237147AbhHWMbS (ORCPT ); Mon, 23 Aug 2021 08:31:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233755AbhHWMbO (ORCPT ); Mon, 23 Aug 2021 08:31:14 -0400 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 D6D46C061575 for ; Mon, 23 Aug 2021 05:30:31 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id f9-20020a05600c1549b029025b0f5d8c6cso13955998wmg.4 for ; Mon, 23 Aug 2021 05:30:31 -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=8EaX10NCT4qa6I+PTQB1H7ApmHQ2Awpjc/lp8Kbnehs=; b=O6iv7tkBMePm8kXrKwAPRVdiU7tB2rbVFcyC4YzXMzoo/HvE2WpkTHXm/Q2kNfs7C3 tqleCwlVd7ECfCZpyQc6wGA6mFSKaKqkkvUlAgZNm4pbWE2DDthrDgRdLcWdgaWXJaan omJNPUybUSw/SOvCR36XF9UTPRpBrR6nmt61tCvbEkkIDvJCRnRus3MjFpn9PjM8vM60 CtZIAF/p15GnzfIUOIfU4z1Op+HtfAywy5BsRScvzKnONoRA7yFtfJhwxpfOuwQefEuf LLneYDIWqqkSZZ4ivP/HxqQxdfncmeb1ySNj6Dc8OHylrNFBA38mu5YkrUAe1ntTkDOG vVWQ== 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=8EaX10NCT4qa6I+PTQB1H7ApmHQ2Awpjc/lp8Kbnehs=; b=tGzDWZY3qG7xxoMzWLM0lRJoaAK/xBEC47OIxnUrPFs5K2c20bn5dD8FztU69byn4m auIpKUVoGACP0r7+3u/mUqQoFQRhQI2XgWsWSfkqNIp+Egeb9xwcLQQ3gHE8t1oGyt35 61sGGW/W+fWbGmCIcMmCtB0vT5bIBY0NQYLjn5dxo1uEr6MwvAFdIVpc7a9BBl5L97Ra LY3fpwDzXtyMVEhw0sZeoM79MKGeLBSG1TH8F7Q727yYFVdkRckyhJ701CUWY8VEbzpa xA7o1Y16wCJN4kE6qDJxRWRoOIdrtAf2P6ION/C9jkRw3rMMvKZ/tutX14ziWKoz4FYM P+9A== X-Gm-Message-State: AOAM533WypcjipjTuDBFH9YkaSywg674xykhuFc/hCct5YfxSLWPAG8M gWDpMsnBthPYnGmhPijpUV3A3f7ohLFwB6hx X-Google-Smtp-Source: ABdhPJw3MOIDsGNs/LHN2iLqHSRSSZQYYLvovcseCf+nUrq3cDqhNLWLd1oBRq4ceabqlFBHAPf8bA== X-Received: by 2002:a7b:c3d6:: with SMTP id t22mr16248245wmj.117.1629721830204; Mon, 23 Aug 2021 05:30:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9sm14762430wrt.95.2021.08.23.05.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 05:30:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Taylor Blau , Andrei Rybak , =?utf-8?q?SZEDER_G=C3=A1bor?= , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 7/7] commit-graph: show "unexpected subcommand" error Date: Mon, 23 Aug 2021 14:30:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.662.gbc81f8cbdca In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Bring the "commit-graph" command in line with the error output and general pattern in cmd_multi_pack_index(). Let's test for that output, and also cover the same potential bug as was fixed in the multi-pack-index command in 88617d11f9d (multi-pack-index: fix potential segfault without sub-command, 2021-07-19). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 1 + t/t5318-commit-graph.sh | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 0457903f18f..21fc6e934b0 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -345,6 +345,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix) else if (argc && !strcmp(argv[0], "write")) return graph_write(argc, argv); + error(_("unrecognized subcommand: %s"), argv[0]); usage: usage_with_options(builtin_commit_graph_usage, builtin_commit_graph_options); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 09a2ccd2920..295c5bd94d2 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -6,10 +6,24 @@ 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 blah 2>err && test_expect_code 129 git commit-graph write verify ' +test_expect_success 'usage shown without sub-command' ' + test_expect_code 129 git commit-graph 2>err && + ! grep error: err +' + +test_expect_success 'usage shown with an error on unknown sub-command' ' + cat >expect <<-\EOF && + error: unrecognized subcommand: unknown + EOF + test_expect_code 129 git commit-graph unknown 2>stderr && + grep error stderr >actual && + test_cmp expect actual +' + test_expect_success 'setup full repo' ' mkdir full && cd "$TRASH_DIRECTORY/full" &&