From patchwork Mon Feb 15 21:01:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12089177 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B30BCC433E0 for ; Mon, 15 Feb 2021 21:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85B7B64DF0 for ; Mon, 15 Feb 2021 21:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229895AbhBOVCX (ORCPT ); Mon, 15 Feb 2021 16:02:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbhBOVCW (ORCPT ); Mon, 15 Feb 2021 16:02:22 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFF70C0613D6 for ; Mon, 15 Feb 2021 13:01:41 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id q85so7604401qke.8 for ; Mon, 15 Feb 2021 13:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EWKQAPQYWkmrYzu/165SRPVqylKwo41lj7IqdytbI/E=; b=gqVBjixVZoA7qFSxjeWYgtBmGobSkLWkQCH0h7UQOq33iVFJ3dur6NCQEkAmtam9Wy WYD6g0IwMhhHQpDfcVoQkHDzow2EiFeIwE90WamuWr0ccP3UmI3GKI1NwKFocY7sYDf/ 4uojnvkCoEDAxhfAKsCmtn3ggEC6zHk7p5rxk/fdiFrcQeogfjyUc8tDczI5GEF9pyTR sCaY6iej/2pqk9mo/pTdKkGY3vIdfiRnBZ20vhx0EzZM9flIfs2QN1Vw+pT1R02dbWsx wa/xPWsLegqCXvwjpHPgBIHkecxMRAN+ubaOs9Z0KzuLf4N33LE9cW8B6QYB/c0AbXXh vb3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EWKQAPQYWkmrYzu/165SRPVqylKwo41lj7IqdytbI/E=; b=JbtiGvIj05ndUUUBFsEjsgqpghP2uyi2zzegOE4gyMHlXgG0hVXzdzDM7gbtxPNX44 kVBG1OrXBaUCqdPaPSJTXI7LGjepcdQuid/vmtCdGKh/hAQG6UQ4Qq/YfgqtAEXI/Ppx EpoXWRaejk8f8ej7twtCsNDGBjS5Od+JZ86Y5rMt13WX4JUA6/XhI2uC+3t3VKt4hojZ Z0ICF6QFhDCYxvgbHjlqrne33x1EuBHNOltvh5Lae/JVkJBfm/zWwZlW7BgGoM0+Ra7c XhD9WtTDPBD31idbs4yO/5gQ1K/nvlu+Ert5qvLUc+y5zEXYltQierYlAPKda3ooQWBp FOMQ== X-Gm-Message-State: AOAM532KPpCrUHGuuttl8TNnylJ+wykvNxagwldJ2G2ymqEAXjkjnhpq G6atY6ePn8HIVtRudPSaI6xH8QXPumf7HP4E X-Google-Smtp-Source: ABdhPJxr6VGbfYoaZYRAD87srR978/5VPD53JYCbnfI2kNHoSQ9sGwEWc1xJGfIFuJs6Y1BeEsg6kg== X-Received: by 2002:a37:5d2:: with SMTP id 201mr7283310qkf.263.1613422900865; Mon, 15 Feb 2021 13:01:40 -0800 (PST) Received: from localhost ([2605:9480:22e:ff10:808e:e46a:5ad1:bdf0]) by smtp.gmail.com with ESMTPSA id o17sm12155343qtl.47.2021.02.15.13.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 13:01:40 -0800 (PST) Date: Mon, 15 Feb 2021 16:01:38 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, peff@peff.net, dstolee@microsoft.com, szeder.dev@gmail.com, gitster@pobox.com Subject: [PATCH v2 1/4] builtin/multi-pack-index.c: inline 'flags' with options Message-ID: <15c5acf3e03337f9b04b4c99591fb54dc4546771.1613422804.git.me@ttaylorr.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Subcommands of the 'git multi-pack-index' command (e.g., 'write', 'verify', etc.) will want to optionally change a set of shared flags that are eventually passed to the MIDX libraries. Right now, options and flags are handled separately. Inline them into the same structure so that sub-commands can more easily share the 'flags' data. Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 5bf88cd2a8..4a0ddb06c4 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -14,13 +14,12 @@ static struct opts_multi_pack_index { const char *object_dir; unsigned long batch_size; int progress; + unsigned flags; } opts; int cmd_multi_pack_index(int argc, const char **argv, const char *prefix) { - unsigned flags = 0; - static struct option builtin_multi_pack_index_options[] = { OPT_FILENAME(0, "object-dir", &opts.object_dir, N_("object directory containing set of packfile and pack-index pairs")), @@ -40,7 +39,7 @@ int cmd_multi_pack_index(int argc, const char **argv, if (!opts.object_dir) opts.object_dir = get_object_directory(); if (opts.progress) - flags |= MIDX_PROGRESS; + opts.flags |= MIDX_PROGRESS; if (argc == 0) usage_with_options(builtin_multi_pack_index_usage, @@ -55,16 +54,16 @@ int cmd_multi_pack_index(int argc, const char **argv, if (!strcmp(argv[0], "repack")) return midx_repack(the_repository, opts.object_dir, - (size_t)opts.batch_size, flags); + (size_t)opts.batch_size, opts.flags); if (opts.batch_size) die(_("--batch-size option is only for 'repack' subcommand")); if (!strcmp(argv[0], "write")) - return write_midx_file(opts.object_dir, flags); + return write_midx_file(opts.object_dir, opts.flags); if (!strcmp(argv[0], "verify")) - return verify_midx_file(the_repository, opts.object_dir, flags); + return verify_midx_file(the_repository, opts.object_dir, opts.flags); if (!strcmp(argv[0], "expire")) - return expire_midx_packs(the_repository, opts.object_dir, flags); + return expire_midx_packs(the_repository, opts.object_dir, opts.flags); die(_("unrecognized subcommand: %s"), argv[0]); } From patchwork Mon Feb 15 21:01:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12089183 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 C482CC433E6 for ; Mon, 15 Feb 2021 21:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D59F64DE0 for ; Mon, 15 Feb 2021 21:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbhBOVCg (ORCPT ); Mon, 15 Feb 2021 16:02:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbhBOVCZ (ORCPT ); Mon, 15 Feb 2021 16:02:25 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B3BC061786 for ; Mon, 15 Feb 2021 13:01:45 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id q8so3732225qvx.11 for ; Mon, 15 Feb 2021 13:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=V4a9UY5s40LlGymKW7WgX8xoLwzSyTJIIO9ypByJRAw=; b=VkhaewwxHW70dWgR5AFLHGIxe1Xo5ZJsunF42B9+G19lW/wVmzeNxYzmq5WmE9jJwI xjYKvbA504TdulHjs91C5U2LFIJvDEl8vEoeL+qIBwgzsrAFBuXk5tU6bBk7LIjspgNl Nyh6jvbbx4twxX0mIACZQmF9opklidha482A+T5oqdZBHMzEbsNf782jGR5N3b5xuzPv 9A4JK/a0ThEs5zT4Bm4puNwQSQd3L64l99+WNbWDEexnMG+xAdYE+FzicsiKQaF/7u7X ZX4HRdt86kTeyW/pNsTkrgGd8NvPs/iIyktBjHWVLNerBywFDA5c1LYTMleSsVNylmOr wIXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=V4a9UY5s40LlGymKW7WgX8xoLwzSyTJIIO9ypByJRAw=; b=pvxKerD9MgTUaDVCyyLQ4niMQAsSE6frEyK435//4en0zhMYOr0SWHU89kIFMyNrPV Psa1Cld+cuIi5Z8RSezhd9TLouOy6mw5VYIRKBPt2LwTjVdg6FTsZsntQbVEZ0fh+OuK 3bA7gtIYSbCCGkcV+k/uelXgxS+5tH0agySsnBXSS9qCm/S56FY1KsFhHqtvT8rArSU6 0B+97fXmUV1A/5h6uHVbc9kq+gF1QdugWotl5qy0ifoDcaBucfzWVrhee8XEKhrlgWoA +VjxaABtOy1HJqrqUzc3zImwh+T0MRsWJq+5NXYMpYKzaAL3lBf/KMKMoaq20rUqf6Ik NrxQ== X-Gm-Message-State: AOAM531nhCUlNn7GMOAjIfXJF23pzftPrwsgEZcw3Yf4tcPri29T5Bsf /Bi8ve8HdDI01Dxm7tTuPm3+v4NSPP1M6J4Z X-Google-Smtp-Source: ABdhPJxyaMTnUW42DGWW1XMZu41vjz0iPP3SgwAGdD9BUfCWIvQC3wIwMkZLJ5ES7fhq8NxczOU2uA== X-Received: by 2002:a0c:f1c2:: with SMTP id u2mr16790749qvl.34.1613422904477; Mon, 15 Feb 2021 13:01:44 -0800 (PST) Received: from localhost ([2605:9480:22e:ff10:808e:e46a:5ad1:bdf0]) by smtp.gmail.com with ESMTPSA id j124sm12751544qkf.113.2021.02.15.13.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 13:01:44 -0800 (PST) Date: Mon, 15 Feb 2021 16:01:42 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, peff@peff.net, dstolee@microsoft.com, szeder.dev@gmail.com, gitster@pobox.com Subject: [PATCH v2 2/4] builtin/multi-pack-index.c: don't handle 'progress' separately Message-ID: References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that there is a shared 'flags' member in the options structure, there is no need to keep track of whether to force progress or not, since ultimately the decision of whether or not to show a progress meter is controlled by a bit in the flags member. Manipulate that bit directly, and drop the now-unnecessary 'progress' field while we're at it. Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 4a0ddb06c4..c70f020d8f 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -13,7 +13,6 @@ static char const * const builtin_multi_pack_index_usage[] = { static struct opts_multi_pack_index { const char *object_dir; unsigned long batch_size; - int progress; unsigned flags; } opts; @@ -23,7 +22,7 @@ int cmd_multi_pack_index(int argc, const char **argv, static struct option builtin_multi_pack_index_options[] = { OPT_FILENAME(0, "object-dir", &opts.object_dir, N_("object directory containing set of packfile and pack-index pairs")), - OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")), + OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS), OPT_MAGNITUDE(0, "batch-size", &opts.batch_size, N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), OPT_END(), @@ -31,15 +30,14 @@ int cmd_multi_pack_index(int argc, const char **argv, git_config(git_default_config, NULL); - opts.progress = isatty(2); + if (isatty(2)) + opts.flags |= MIDX_PROGRESS; argc = parse_options(argc, argv, prefix, builtin_multi_pack_index_options, builtin_multi_pack_index_usage, 0); if (!opts.object_dir) opts.object_dir = get_object_directory(); - if (opts.progress) - opts.flags |= MIDX_PROGRESS; if (argc == 0) usage_with_options(builtin_multi_pack_index_usage, From patchwork Mon Feb 15 21:01:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12089181 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 5768CC43381 for ; Mon, 15 Feb 2021 21:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C63C64DEC for ; Mon, 15 Feb 2021 21:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbhBOVCh (ORCPT ); Mon, 15 Feb 2021 16:02:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhBOVC2 (ORCPT ); Mon, 15 Feb 2021 16:02:28 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB71C06178A for ; Mon, 15 Feb 2021 13:01:48 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id h8so7628612qkk.6 for ; Mon, 15 Feb 2021 13:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=By4ZDw+6iwX13Ip2dovM5NjuD4lu7Lq1pVXXR7wZA+M=; b=aQudvNzIYSlWhFxd+Rp04v2iLIAI9Cqu/UjeUezHsdzNM/XAWHk1vnsnyloAeicX24 MPGn8+9Eq8QrJODVNmUqwNq/kaZNu6J13bMzmMhtVOsilu9unYPfniOcLM/p9ET7tDtn KfZSPFyTjyGlOBimu6s/K0eDRjJG0P59hmVlrL/5V46lWB6YfchuOycABa9jL7zc85Qj cVNrZgx4kETZBuhV79LcBB2R83WmM42oNYsv7jdwehnLva5cEFUp9eDrKP89fT4TveUm Hr0TI8guDJgNKrA6oZ0j3MgLdAbzvReZyog6EHjqdSmDzY2STu/CcA4trbAN+Aw97NQy U1Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=By4ZDw+6iwX13Ip2dovM5NjuD4lu7Lq1pVXXR7wZA+M=; b=jIAw1nvjP1cX3TFYovN8wnurEhhNVLAIDbDDonwgS5hP6MeIFkAVFYle8O3ozylfos IrvuvVRBJs4zHxkgvP49igaOT8drhXSmBOvHxy4QathHqy8VQN28o/SaEajeEiV8vnTR 5xvIE8SHY9ywZ2PNMTMtBU6sELUtuEJAxksA8eqhcW92rUThQWGTtIyygaKm3OPv2thP hgIntw9Ei/4tjgdPvFkdJRT7KgtLRapM3raIQo5Nqgq1QvBbQ3OxCpb7WxFQcPGTQ5Op OG/+ed1aJe1oxhlpA4UVKmjK41MV6ZOnIiKCTrtHrpA7z8UxGAjSdO+iCbLBEuBHEoCq NGyQ== X-Gm-Message-State: AOAM530ubTEi6Qsit2sCZPR+o/VSK+gENQmNus22n6vAzRfCtMM7Xy6C aLq+Wx69TRmVjspMd6NMK5O41lEqi4IDCDjx X-Google-Smtp-Source: ABdhPJySLrYCPaZqasxhAeLunbqWLUSkbDbk48A2V57pp6xKCgPfwsKVcJ04Kk+NzBVnqY65ZGtnZQ== X-Received: by 2002:a37:a8cc:: with SMTP id r195mr16246694qke.151.1613422907617; Mon, 15 Feb 2021 13:01:47 -0800 (PST) Received: from localhost ([2605:9480:22e:ff10:808e:e46a:5ad1:bdf0]) by smtp.gmail.com with ESMTPSA id d1sm11618242qtq.94.2021.02.15.13.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 13:01:47 -0800 (PST) Date: Mon, 15 Feb 2021 16:01:46 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, peff@peff.net, dstolee@microsoft.com, szeder.dev@gmail.com, gitster@pobox.com Subject: [PATCH v2 3/4] builtin/multi-pack-index.c: define common usage with a macro Message-ID: References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Factor out the usage message into pieces corresponding to each mode. This avoids options specific to one sub-command from being shared with another in the usage. A subsequent commit will use these #define macros to have usage variables for each sub-command without duplicating their contents. Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index c70f020d8f..eea498e026 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -5,8 +5,23 @@ #include "midx.h" #include "trace2.h" +#define BUILTIN_MIDX_WRITE_USAGE \ + N_("git multi-pack-index [] write") + +#define BUILTIN_MIDX_VERIFY_USAGE \ + N_("git multi-pack-index [] verify") + +#define BUILTIN_MIDX_EXPIRE_USAGE \ + N_("git multi-pack-index [] expire") + +#define BUILTIN_MIDX_REPACK_USAGE \ + N_("git multi-pack-index [] repack [--batch-size=]") + static char const * const builtin_multi_pack_index_usage[] = { - N_("git multi-pack-index [] (write|verify|expire|repack --batch-size=)"), + BUILTIN_MIDX_WRITE_USAGE, + BUILTIN_MIDX_VERIFY_USAGE, + BUILTIN_MIDX_EXPIRE_USAGE, + BUILTIN_MIDX_REPACK_USAGE, NULL }; From patchwork Mon Feb 15 21:01:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12089185 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 690D4C4332B for ; Mon, 15 Feb 2021 21:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FBEF64DF0 for ; Mon, 15 Feb 2021 21:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbhBOVCk (ORCPT ); Mon, 15 Feb 2021 16:02:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbhBOVCd (ORCPT ); Mon, 15 Feb 2021 16:02:33 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1DAEC061788 for ; Mon, 15 Feb 2021 13:01:51 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id x14so7652176qkm.2 for ; Mon, 15 Feb 2021 13:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=/b52xhIUWI7qN7nCecignICrg1moxxqCSViEAWPuqHk=; b=t2gh6gLFHPFgn8GUNASvZF7aybMgZktktVGMKNxRWUEneKOZRBN512fcFHkPC0IPaK qSv43+H+E3/FJsD6/YLmrl4rblMzckLbeaRAwZr+/tbUYBvreEJlUGxokN8R00H0oRzx ZcJ3kjYtC21gO6+hRGRi8EM7UOQKuPbPSGXbwvgbtTNzOqvrcX043h+/6V/FhBkNaW2N sxLovdWF1K4SOFXUXbBO0IjXGZg4WYNrGZHPqucbevjX1FicSAjLGJCW5aKXDZIb0V6h G0zRV/doQNHTCOkPVMBOu1syMrtgXoHhONCTprz+47xzq/PcUrZp1a8LeEyeqDf7KCC0 Tj2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=/b52xhIUWI7qN7nCecignICrg1moxxqCSViEAWPuqHk=; b=kzms+9mMyxBDSiNegA9e+6NIyKdkZCXjdydJW9ifYRHpYdNG778paJysfisRcdSrKu S/FV99ASGHTvU40e3Z6mzNIYwr4whg9iG5/BkRN4T8o/Oc7Pm+Ta1LbCGMxMdZeTDqFC O3aVD0F1MB6A4q679/rsAfRxx2cd8Enkc08Ba1+97YEUBvFDsQmlPqfy21fMd7cMAJWc xlBA6ol/DAk9SAD8Oe1wYHzw5GeixB5basKgPRTYaZNKNudy0WeAnvCDVyTrhu7zyarS Sxdo8W0CwDjoM/u9O3SMDHJDUA3wg2fL9BHtKvFfrN233ChS3uvHHwe/PdCA/fRV7J0U kDaA== X-Gm-Message-State: AOAM531S97B0eup3WU+TFmHdl8ecbk3oCLXkldHgEOiILhDTqfh1QAtv n2V4X0OUPVMS3yxlBORY4qhkUCAOG61YrbOf X-Google-Smtp-Source: ABdhPJxqQxwQ3rdXIHyl6lD/PjkKzaijOk5zB2YLix7rMDUImqdLFTQoxeBapq2b1nRA+VIqAuKZZQ== X-Received: by 2002:a37:b346:: with SMTP id c67mr16682784qkf.212.1613422910901; Mon, 15 Feb 2021 13:01:50 -0800 (PST) Received: from localhost ([2605:9480:22e:ff10:808e:e46a:5ad1:bdf0]) by smtp.gmail.com with ESMTPSA id t71sm12754191qka.86.2021.02.15.13.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 13:01:50 -0800 (PST) Date: Mon, 15 Feb 2021 16:01:49 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, peff@peff.net, dstolee@microsoft.com, szeder.dev@gmail.com, gitster@pobox.com Subject: [PATCH v2 4/4] builtin/multi-pack-index.c: split sub-commands Message-ID: <16f33e41388ed431f70e09ef68717bd30fbee67f.1613422804.git.me@ttaylorr.com> References: <87r1lhb6z7.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Handle sub-commands of the 'git multi-pack-index' builtin (e.g., "write", "repack", etc.) separately from one another. This allows sub-commands with unique options, without forcing cmd_multi_pack_index() to reject invalid combinations itself. This comes at the cost of some duplication and boilerplate. Luckily, the duplication is reduced to a minimum, since common options are shared among sub-commands due to a suggestion by Ævar. (Sub-commands do have to retain the common options, too, since this builtin accepts common options on either side of the sub-command). Roughly speaking, cmd_multi_pack_index() parses options (including common ones), and stops at the first non-option, which is the sub-command. It then dispatches to the appropriate sub-command, which parses the remaining options (also including common options). Unknown options are kept by the sub-commands in order to detect their presence (and complain that too many arguments were given). Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 131 ++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 25 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index eea498e026..caf0248a98 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -5,17 +5,33 @@ #include "midx.h" #include "trace2.h" +static char const * const builtin_multi_pack_index_write_usage[] = { #define BUILTIN_MIDX_WRITE_USAGE \ N_("git multi-pack-index [] write") + BUILTIN_MIDX_WRITE_USAGE, + NULL +}; +static char const * const builtin_multi_pack_index_verify_usage[] = { #define BUILTIN_MIDX_VERIFY_USAGE \ N_("git multi-pack-index [] verify") + BUILTIN_MIDX_VERIFY_USAGE, + NULL +}; +static char const * const builtin_multi_pack_index_expire_usage[] = { #define BUILTIN_MIDX_EXPIRE_USAGE \ N_("git multi-pack-index [] expire") + BUILTIN_MIDX_EXPIRE_USAGE, + NULL +}; +static char const * const builtin_multi_pack_index_repack_usage[] = { #define BUILTIN_MIDX_REPACK_USAGE \ N_("git multi-pack-index [] repack [--batch-size=]") + BUILTIN_MIDX_REPACK_USAGE, + NULL +}; static char const * const builtin_multi_pack_index_usage[] = { BUILTIN_MIDX_WRITE_USAGE, @@ -31,25 +47,99 @@ static struct opts_multi_pack_index { unsigned flags; } opts; -int cmd_multi_pack_index(int argc, const char **argv, - const char *prefix) +static struct option common_opts[] = { + OPT_FILENAME(0, "object-dir", &opts.object_dir, + N_("object directory containing set of packfile and pack-index pairs")), + OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS), + OPT_END(), +}; + +static struct option *add_common_options(struct option *prev) { - static struct option builtin_multi_pack_index_options[] = { - OPT_FILENAME(0, "object-dir", &opts.object_dir, - N_("object directory containing set of packfile and pack-index pairs")), - OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS), + struct option *with_common = parse_options_concat(common_opts, prev); + free(prev); + return with_common; +} + +static int cmd_multi_pack_index_write(int argc, const char **argv) +{ + struct option *options = common_opts; + + argc = parse_options(argc, argv, NULL, + options, builtin_multi_pack_index_write_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_multi_pack_index_write_usage, + options); + + return write_midx_file(opts.object_dir, opts.flags); +} + +static int cmd_multi_pack_index_verify(int argc, const char **argv) +{ + struct option *options = common_opts; + + argc = parse_options(argc, argv, NULL, + options, builtin_multi_pack_index_verify_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_multi_pack_index_verify_usage, + options); + + return verify_midx_file(the_repository, opts.object_dir, opts.flags); +} + +static int cmd_multi_pack_index_expire(int argc, const char **argv) +{ + struct option *options = common_opts; + + argc = parse_options(argc, argv, NULL, + options, builtin_multi_pack_index_expire_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_multi_pack_index_expire_usage, + options); + + return expire_midx_packs(the_repository, opts.object_dir, opts.flags); +} + +static int cmd_multi_pack_index_repack(int argc, const char **argv) +{ + struct option *options; + static struct option builtin_multi_pack_index_repack_options[] = { OPT_MAGNITUDE(0, "batch-size", &opts.batch_size, N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), OPT_END(), }; + options = parse_options_dup(builtin_multi_pack_index_repack_options); + options = add_common_options(options); + + argc = parse_options(argc, argv, NULL, + options, + builtin_multi_pack_index_repack_usage, + PARSE_OPT_KEEP_UNKNOWN); + if (argc) + usage_with_options(builtin_multi_pack_index_repack_usage, + options); + + return midx_repack(the_repository, opts.object_dir, + (size_t)opts.batch_size, opts.flags); +} + +int cmd_multi_pack_index(int argc, const char **argv, + const char *prefix) +{ + struct option *builtin_multi_pack_index_options = common_opts; + git_config(git_default_config, NULL); if (isatty(2)) opts.flags |= MIDX_PROGRESS; argc = parse_options(argc, argv, prefix, builtin_multi_pack_index_options, - builtin_multi_pack_index_usage, 0); + builtin_multi_pack_index_usage, + PARSE_OPT_STOP_AT_NON_OPTION); if (!opts.object_dir) opts.object_dir = get_object_directory(); @@ -58,25 +148,16 @@ int cmd_multi_pack_index(int argc, const char **argv, usage_with_options(builtin_multi_pack_index_usage, builtin_multi_pack_index_options); - if (argc > 1) { - die(_("too many arguments")); - return 1; - } - trace2_cmd_mode(argv[0]); if (!strcmp(argv[0], "repack")) - return midx_repack(the_repository, opts.object_dir, - (size_t)opts.batch_size, opts.flags); - if (opts.batch_size) - die(_("--batch-size option is only for 'repack' subcommand")); - - if (!strcmp(argv[0], "write")) - return write_midx_file(opts.object_dir, opts.flags); - if (!strcmp(argv[0], "verify")) - return verify_midx_file(the_repository, opts.object_dir, opts.flags); - if (!strcmp(argv[0], "expire")) - return expire_midx_packs(the_repository, opts.object_dir, opts.flags); - - die(_("unrecognized subcommand: %s"), argv[0]); + return cmd_multi_pack_index_repack(argc, argv); + else if (!strcmp(argv[0], "write")) + return cmd_multi_pack_index_write(argc, argv); + else if (!strcmp(argv[0], "verify")) + return cmd_multi_pack_index_verify(argc, argv); + else if (!strcmp(argv[0], "expire")) + return cmd_multi_pack_index_expire(argc, argv); + else + die(_("unrecognized subcommand: %s"), argv[0]); }