From patchwork Fri Jul 9 11:06:12 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: 12367131 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=-16.0 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 B9378C07E9C for ; Fri, 9 Jul 2021 11:06:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D2E1613D3 for ; Fri, 9 Jul 2021 11:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230178AbhGILJG (ORCPT ); Fri, 9 Jul 2021 07:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbhGILJF (ORCPT ); Fri, 9 Jul 2021 07:09:05 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05541C0613E5 for ; Fri, 9 Jul 2021 04:06:22 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso8826179wmh.4 for ; Fri, 09 Jul 2021 04:06:21 -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=3bl5vpgO0StejHxCXebJzTyc0cDL+doDztpEgk4TVGQ=; b=Hse4onRKRI01LP9/nK526DpeZ+7D34BX22EMiByNxG7hNX87hwf+8Hz4zmMJgvIEa3 HpB9wxfs1S8iPWUx2lHIH5NQ7vEqMgSXs9yF64VoL0/a/EfOb9OlS2ePSOKXrHyfnkW1 ZrnEPre3YUdgQaM/yDgrui6XiZDwXjxw7EpnbOvuNR4bGXzEAhhGhmb8u72w/ISmTMTw V1GHzwnEbFD7b0tKPBRyN/SBfX2qoxfq2TOjw10s57f3FYVlsD8Tg14U+p98shiMX+Sp ohrSSM4y9Uz/RZYRUaup+MxHqgm/Kd+olWbyiwJKQ6iD0bk+a+UBzMaPiPsCZmOKhLs1 mfqw== 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=3bl5vpgO0StejHxCXebJzTyc0cDL+doDztpEgk4TVGQ=; b=PdzLyIHcg9wJY4qJ0gYtatjY+RHvbku0ogCKCAIKyiHphh9FzOQu09SHInm1kUVvfH 2YpSnEKo1QeG7E94AXNCdaNXScgzekC99VV3EOx2MY1a6XP10iP1QLcAZfX8mHUsCx4x GyBS4lvCHwCW+SZ5qxSvpOXoXpMi70ofYWXSKoIkhQyhfY9nC5QLpgtpfBB3Bnm0L4xQ c47UllUbZ4+rJY0aMetBtePfCKjNkTKM18+XktVQBJ1GiBoIPEv7Lc4BrD43zywMxghM xozZLOQGCGNul6HbvQOYjuWjiL9dBE5GEQdSiYceeMkkGtZnr1ZhkVCmdLYsl+GoiveW 53jQ== X-Gm-Message-State: AOAM531sITmbBmQNrcoRQ2pZHmesKAeBe69NiIFgZbPXGmWPEx8OXATw PwF7yU+AMT8UxwOXYEiX3rZEDR22BArB/A== X-Google-Smtp-Source: ABdhPJxSu2cQzZpG4y4QPcf3NzvuDY4Xfl3EMbgbV3P/YhDqippWl9I53Z0YEIvlBbc8nnZE2AF70A== X-Received: by 2002:a7b:c8d2:: with SMTP id f18mr5634080wml.135.1625828780464; Fri, 09 Jul 2021 04:06:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a4sm4978167wru.55.2021.07.09.04.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 04:06:19 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , Emily Shaffer , Jonathan Tan , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 1/5] upload-pack: run is_repository_shallow() before setup_revisions() Date: Fri, 9 Jul 2021 13:06:12 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the is_repository_shallow() added in b790e0f67cd (upload-pack: send shallow info over stdin to pack-objects, 2014-03-11) to above setup_revisions(). Running is_repository_shallow() before setup_revisions() doesn't matter now, but in subsequent commits we'll make the code that followed setup_revisions() happen inside a callback in that function. This isolated change documents that re-arranging this part of the code is OK in isolation. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index df49f656b96..3639d0379ed 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3774,11 +3774,12 @@ static void get_object_list(int ac, const char **av) repo_init_revisions(the_repository, &revs, NULL); save_commit_buffer = 0; - setup_revisions(ac, av, &revs, &s_r_opt); /* make sure shallows are read */ is_repository_shallow(the_repository); + setup_revisions(ac, av, &revs, &s_r_opt); + save_warning = warn_on_object_refname_ambiguity; warn_on_object_refname_ambiguity = 0; From patchwork Fri Jul 9 11:06:13 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: 12367135 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=-16.0 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 62DE6C07E9B for ; Fri, 9 Jul 2021 11:06:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4213161249 for ; Fri, 9 Jul 2021 11:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbhGILJJ (ORCPT ); Fri, 9 Jul 2021 07:09:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbhGILJH (ORCPT ); Fri, 9 Jul 2021 07:09:07 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38E66C0613DD for ; Fri, 9 Jul 2021 04:06:23 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v5so11638550wrt.3 for ; Fri, 09 Jul 2021 04:06:23 -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=EY77LNxSBLgxi9S5FrLjsJr++ryDedrMnTamY1nOacU=; b=V4D0BtjCeToM/NHgq3t/MjiML1kZ4v68rOQXJo96lGptXpE5Hgwijzt/oHEWn7+8Mk HgvMYwGG+iJga06uE+CryV+6hMJwuQVxFC9SBtDHYsm6t1pABh4L+Y8eOd3ZAOd2Kzam a4wX3czmaccIY/V30WQ5N1IACx/s5cmMiqShDqwnGRQvQMTnB46RsxXhPeZ4aP5qNiHH 9sEf+BC4wNd9ke/tysIoiBpd3i5S9Rv0kA1XOIgtpDPdLV9ZkbS63CxfqNKZe6+RIceu 2QrekmQ2VfUBN5C9Kfwh8+te2etOZtXb30oJe1/J9Ge2r5upWAcuc4DfOpFzbMG2Leyp VYqw== 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=EY77LNxSBLgxi9S5FrLjsJr++ryDedrMnTamY1nOacU=; b=hvoUTNURTuyyIojWV8u4NCKy5WwABX7DXrwRdSe9BDT48Nxzg0Ns1cqRXVHCcxyu73 bUcsEtC/+zLaRBdhq7p+IDn0/nexkt8zDXpkDcNQybnlE0FeeOFY0Va31IweoCMtff3D hlR86HBqXRx44DXqvmfp0lsSqZgFG9MjsZqGec4J/CO1I1/rid3MYkdUv5J/uPn3zax+ PK+IAzlhqL8RLgnXpXgFgG4TN/1uDcYKsY08p2Of9rdV6r06ubLu9W6d5BrljTX8ho+p xqkzOvXZjEPiTUdwP+w1qovatvjPgErFzDn/QibaZVdpB+T39E8YWZ/7eGSSBp+OFIWi ToPQ== X-Gm-Message-State: AOAM5336mYja3sIpdZWe4BMEi9DBiT9i9qEmoF3Ng3QvFvXQ+NYpJq/I fpt8kWrponcW+vI2lhvDkTXIR15W9HqiFA== X-Google-Smtp-Source: ABdhPJy006DvfrXtbx8Yn9Yl/LvLfavSUGT7u2f4LcyJ5hUXdDDbg7KPm7xHATA+FPzF8CglTnpXgw== X-Received: by 2002:adf:f90d:: with SMTP id b13mr30955073wrr.336.1625828781540; Fri, 09 Jul 2021 04:06:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a4sm4978167wru.55.2021.07.09.04.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 04:06:20 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , Emily Shaffer , Jonathan Tan , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 2/5] revision.h: refactor "disable_stdin" and "read_from_stdin" Date: Fri, 9 Jul 2021 13:06:13 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the two "disable_stdin" and "read_from_stdin" flags to an enum, in preparation for a subsequent commit adding more flags. The interaction between these is more subtle than they might appear at first sight, as noted in a12cbe23ef7. "read_stdin" is not the inverse of "disable_stdin", rather we read stdin if we see the "--stdin" option. The "read" is intended to understood as "I've read it already", not "you should read it". Let's avoid this confusion by using "consume" and "consumed" instead, i.e. a word whose present and past tense isn't the same. See 8b3dce56508 (Teach --stdin option to "log" family, 2009-11-03) where we added the "disable_stdin" flag, and a12cbe23ef7 (rev-list: make empty --stdin not an error, 2018-08-22) for the addition of the "read_from_stdin" flag. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 4 ++-- builtin/blame.c | 2 +- builtin/diff-tree.c | 2 +- builtin/rev-list.c | 2 +- revision.c | 13 ++++++++----- revision.h | 23 ++++++++++++++++++++--- sequencer.c | 4 ++-- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 0b2d886c81b..3a6c8455b47 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1355,7 +1355,7 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm repo_init_revisions(the_repository, &rev_info, NULL); rev_info.diff = 1; rev_info.abbrev = 0; - rev_info.disable_stdin = 1; + rev_info.stdin_handling = REV_INFO_STDIN_IGNORE; rev_info.show_root_diff = 1; rev_info.diffopt.output_format = DIFF_FORMAT_PATCH; rev_info.no_commit_id = 1; @@ -1390,7 +1390,7 @@ static void write_index_patch(const struct am_state *state) fp = xfopen(am_path(state, "patch"), "w"); repo_init_revisions(the_repository, &rev_info, NULL); rev_info.diff = 1; - rev_info.disable_stdin = 1; + rev_info.stdin_handling = REV_INFO_STDIN_IGNORE; rev_info.no_commit_id = 1; rev_info.diffopt.output_format = DIFF_FORMAT_PATCH; rev_info.diffopt.use_color = 0; diff --git a/builtin/blame.c b/builtin/blame.c index 641523ff9af..c9f66c58c46 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1061,7 +1061,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) argv[argc - 1] = "--"; } - revs.disable_stdin = 1; + revs.stdin_handling = REV_INFO_STDIN_IGNORE; setup_revisions(argc, argv, &revs, NULL); if (!revs.pending.nr && is_bare_repository()) { struct commit *head_commit; diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index f33d30d57bf..fc548ebe166 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -122,7 +122,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) die(_("index file corrupt")); opt->abbrev = 0; opt->diff = 1; - opt->disable_stdin = 1; + opt->stdin_handling = REV_INFO_STDIN_IGNORE; memset(&s_r_opt, 0, sizeof(s_r_opt)); s_r_opt.tweak = diff_tree_tweak_rev; diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 7677b1af5a4..524632ba328 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -651,7 +651,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && !revs.pending.nr) && - !revs.rev_input_given && !revs.read_from_stdin) || + !revs.rev_input_given && !revs.consumed_stdin) || revs.diff) usage(rev_list_usage); diff --git a/revision.c b/revision.c index cddd0542a65..f30b9d40af4 100644 --- a/revision.c +++ b/revision.c @@ -2742,14 +2742,17 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s } if (!strcmp(arg, "--stdin")) { - if (revs->disable_stdin) { + switch (revs->stdin_handling) { + case REV_INFO_STDIN_IGNORE: argv[left++] = arg; continue; + case REV_INFO_STDIN_CONSUME_ON_OPTION: + if (revs->consumed_stdin) + die("--stdin given twice?"); + read_revisions_from_stdin(revs, &prune_data); + revs->consumed_stdin = 1; + continue; } - if (revs->read_from_stdin++) - die("--stdin given twice?"); - read_revisions_from_stdin(revs, &prune_data); - continue; } if (!strcmp(arg, "--end-of-options")) { diff --git a/revision.h b/revision.h index 5c5510d4220..a942b1250ad 100644 --- a/revision.h +++ b/revision.h @@ -86,6 +86,11 @@ struct rev_cmdline_info { struct oidset; struct topo_walk_info; +enum rev_info_stdin { + REV_INFO_STDIN_CONSUME_ON_OPTION, + REV_INFO_STDIN_IGNORE, +}; + struct rev_info { /* Starting list */ struct commit_list *commits; @@ -114,9 +119,22 @@ struct rev_info { int rev_input_given; /* - * Whether we read from stdin due to the --stdin option. + * How should we handle seeing --stdin? + * + * Defaults to REV_INFO_STDIN_CONSUME_ON_OPTION where we'll + * attempt to read it if we see the --stdin option. + * + * Can be set to REV_INFO_STDIN_IGNORE to ignore the --stdin + * option. + */ + enum rev_info_stdin stdin_handling; + + /* + * Did we read from stdin due to stdin_handling == + * REV_INFO_STDIN_CONSUME_ON_OPTION and seeing the --stdin + * option? */ - int read_from_stdin; + int consumed_stdin:1; /* topo-sort */ enum rev_sort_order sort_order; @@ -216,7 +234,6 @@ struct rev_info { date_mode_explicit:1, preserve_subject:1, encode_email_headers:1; - unsigned int disable_stdin:1; /* --show-linear-break */ unsigned int track_linear:1, track_first_time:1, diff --git a/sequencer.c b/sequencer.c index 0bec01cf38e..4e73bd79d69 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3377,7 +3377,7 @@ static int make_patch(struct repository *r, log_tree_opt.abbrev = 0; log_tree_opt.diff = 1; log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH; - log_tree_opt.disable_stdin = 1; + log_tree_opt.stdin_handling = REV_INFO_STDIN_IGNORE; log_tree_opt.no_commit_id = 1; log_tree_opt.diffopt.file = fopen(buf.buf, "w"); log_tree_opt.diffopt.use_color = GIT_COLOR_NEVER; @@ -4513,7 +4513,7 @@ static int pick_commits(struct repository *r, log_tree_opt.diff = 1; log_tree_opt.diffopt.output_format = DIFF_FORMAT_DIFFSTAT; - log_tree_opt.disable_stdin = 1; + log_tree_opt.stdin_handling = REV_INFO_STDIN_IGNORE; if (read_oneliner(&buf, rebase_path_orig_head(), 0) && !get_oid(buf.buf, &orig) && From patchwork Fri Jul 9 11:06:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12367141 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=-16.0 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 6F875C07E9E for ; Fri, 9 Jul 2021 11:06:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 418B361249 for ; Fri, 9 Jul 2021 11:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbhGILJP (ORCPT ); Fri, 9 Jul 2021 07:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbhGILJH (ORCPT ); Fri, 9 Jul 2021 07:09:07 -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 3B0B8C0613E5 for ; Fri, 9 Jul 2021 04:06:24 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id k32so2872783wms.4 for ; Fri, 09 Jul 2021 04:06:24 -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=1tpPHUUpA5JrhaSpICu2+SS+EJCrGrqK303GIk4lIAc=; b=XEau2KZWVxta+DTxWjmK6nUIuXcWOknoNik0K1Zx6Mzeq5bBT+h1KYyG/kwuNYx8Qa SyZGcrQ92TDyfwX/dFoUB3RpiRKRRn1gSXsmzWCVHHNicLYm22YZylV6GHF3V1L9bfgk L/qok34pmWFThDqe+ITpLitg9d+71V3SsKQOLQtWQviY8iWSNrIZtepE9H7XVf7tz8dl 4RQ1v2bn9XR/uqgKwdYlkkpaUbS1A0TiT7ElOGKRGxYloSR8V0oyU+4lLqhDxgKJugdc eihovg58Sqc1/cCfPeM+g9Nvo+7c0hi1DYV+NE6aKLLdlkGEJN5Zvfcv8zYQVjjud+pE Q4Lg== 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=1tpPHUUpA5JrhaSpICu2+SS+EJCrGrqK303GIk4lIAc=; b=c9lCQa71OBJb0mH4UZiW6SAkHu94yu0KW/sN73dYldkKoQmnRubZE/2G3OY21eBA+H 0DpVUnlb6e7xaIyB+krFr1D6sjQHXS+DNA8TX25Jq/Jespfpd63pZYVspS/zEHpAVzBW 80TWHx1XGXmnQ/ziCTgWiyHXs+V5AX2EYhYaw2fgPbpJ6AoOg4CbPsBoOwynUI5fZv70 eKu6tEHg4MdQUF+SMxUQG78xcfgrk0uGAs+4zrfGoFrJUSEbk89qufRfsYgJz6mo0Bjq aVi9Q8U+g7Ux8OkcpvRKy0VyUbGMQCQ63Z/gU2ydxz7+NlnLhc8brHaKLTYRabc/cktH W53Q== X-Gm-Message-State: AOAM532mKUSZbOhibApDIzSuQJBxxN8xsMis1006qBsEtu3o/9LB/EWf BnHV+lmRCDVv8BxCHtxoclSZPZxYuw8K7g== X-Google-Smtp-Source: ABdhPJyQ3nmKAufNKGqTqT8APv88VJdT9ouLPNvkNYUJN1uBwgOmGSO+wGlCRvIeS5kqy5Wyly3tWQ== X-Received: by 2002:a1c:790e:: with SMTP id l14mr10765329wme.119.1625828782591; Fri, 09 Jul 2021 04:06:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a4sm4978167wru.55.2021.07.09.04.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 04:06:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , Emily Shaffer , Jonathan Tan , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 3/5] revision.[ch]: add a "handle_stdin_line" API Date: Fri, 9 Jul 2021 13:06:14 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extend the rev_info stdin parsing API to support hooking into its read_revisions_from_stdin() function, in the next commit we'll change the the custom stdin parsing in pack-objects.c to use it.. For that use-case adding API is barely justified. We'll be able to make the handle_revision_arg() static in exchange for it, and we'll avoid the duplicate dance around setting "save_warning" and "warn_on_object_refname_ambiguity", but we could just continue to do that ourselves in builtin/pack-objects.c The real reason to add this is for a change not part of this series. We'll soon teach "git bundle create" to accept revision/refname pairs on stdin, and thus do away with the limitation of it being impossible to create bundles with ref tips that don't correspond to the state of the current repository. I.e. this will work: $ printf "e83c5163316f89bfbde7\trefs/heads/first-git-dot-git-commit\n" | git bundle create initial.bundle --stdin As well as things like: $ git for-each-ref 'refs/remotes/origin' | sed 's!\trefs/remotes/origin/!\trefs/heads/!' | git bundle create origin.bundle --stdin In order to do that we'll need to modify the lines we consume on stdin revision.c (which bundle.c uses already), and be assured that that stripping extra bundle-specific data from them is the only change in behavior. That change will be much more complex if bundle.c needs to start doing its own stdin parsing again outside of revision.c, it was recently converted to use revision.c's parsing in 5bb0fd2cab5 (bundle: arguments can be read from stdin, 2021-01-11) Signed-off-by: Ævar Arnfjörð Bjarmason --- revision.c | 22 ++++++++++++++++++++++ revision.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/revision.c b/revision.c index f30b9d40af4..557b7f113a9 100644 --- a/revision.c +++ b/revision.c @@ -2120,6 +2120,19 @@ static void read_revisions_from_stdin(struct rev_info *revs, int len = sb.len; if (!len) break; + + if (revs->handle_stdin_line) { + enum rev_info_stdin_line ret = revs->handle_stdin_line( + revs, &sb, revs->stdin_line_priv); + + switch (ret) { + case REV_INFO_STDIN_LINE_PROCESS: + break; + case REV_INFO_STDIN_LINE_CONTINUE: + continue; + } + } + if (sb.buf[0] == '-') { if (len == 2 && sb.buf[1] == '-') { seen_dashdash = 1; @@ -2743,6 +2756,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s if (!strcmp(arg, "--stdin")) { switch (revs->stdin_handling) { + case REV_INFO_STDIN_ALWAYS_READ: case REV_INFO_STDIN_IGNORE: argv[left++] = arg; continue; @@ -2791,6 +2805,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s } } + /* + * We're asked to ALWAYS_READ from stdin, but no --stdin + * option (or "consumed_stdin" would be set). + */ + if (!revs->consumed_stdin && + revs->stdin_handling == REV_INFO_STDIN_ALWAYS_READ) + read_revisions_from_stdin(revs, &prune_data); + if (prune_data.nr) { /* * If we need to introduce the magic "a lone ':' means no diff --git a/revision.h b/revision.h index a942b1250ad..52241c84c5b 100644 --- a/revision.h +++ b/revision.h @@ -89,8 +89,17 @@ struct topo_walk_info; enum rev_info_stdin { REV_INFO_STDIN_CONSUME_ON_OPTION, REV_INFO_STDIN_IGNORE, + REV_INFO_STDIN_ALWAYS_READ, }; +enum rev_info_stdin_line { + REV_INFO_STDIN_LINE_PROCESS, + REV_INFO_STDIN_LINE_CONTINUE, +}; + +typedef enum rev_info_stdin_line (*rev_info_stdin_line_func)( + struct rev_info *revs, struct strbuf *line, void *stdin_line_priv); + struct rev_info { /* Starting list */ struct commit_list *commits; @@ -126,6 +135,9 @@ struct rev_info { * * Can be set to REV_INFO_STDIN_IGNORE to ignore the --stdin * option. + * + * Set it to REV_INFO_STDIN_ALWAYS_READ if there's always data + * on stdin to be read, even if no --stdin option is provided. */ enum rev_info_stdin stdin_handling; @@ -136,6 +148,24 @@ struct rev_info { */ int consumed_stdin:1; + /* + * When reading from stdin (see "stdin_handling" above) define + * a handle_stdin_line function to consume the lines. + * + * - Return REV_INFO_STDIN_LINE_PROCESS to continue + * revision.c's normal processing of the line (after + * possibly munging the provided strbuf). + * + * - Return REV_INFO_STDIN_LINE_CONTINUE to indicate that the + * line is fully processed, moving onto the next line (if + * any) + * + * Use the "stdin_line_priv" to optionally pass your own data + * around. + */ + rev_info_stdin_line_func handle_stdin_line; + void *stdin_line_priv; + /* topo-sort */ enum rev_sort_order sort_order; From patchwork Fri Jul 9 11:06: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: 12367137 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=-16.0 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 0D5EEC07E99 for ; Fri, 9 Jul 2021 11:06:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6ECF613D6 for ; Fri, 9 Jul 2021 11:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230367AbhGILJN (ORCPT ); Fri, 9 Jul 2021 07:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbhGILJJ (ORCPT ); Fri, 9 Jul 2021 07:09:09 -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 1F664C0613DD for ; Fri, 9 Jul 2021 04:06:25 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id g16so1720184wrw.5 for ; Fri, 09 Jul 2021 04:06:25 -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=OVP+he5IQw5W/Xm+I1uQ6X/4pF3ZsGTO5va8vdSRmiE=; b=RHpayUNu6HJBDPFWMFPKSR5R+z5CWiKuHIO/TeGiMexpRhZ3sQjySbcyikmKi9M80F qtW6nF0hviHPoEB0ptb2Z4YSYVXV9E2g5xG6jeI/xEDKQyer9E80rC0cdj7V3jqHAaQX sp2+oH5SZ4AIz9SCKCCirwvbm7U9u+YqL5lNpv7KmAGTQuxDEMWAto6ppBNK+7GWDmpD o7ARzH746PwZ7c/hOy46tUHRZEpz2GfmpGjzoYpDF2/jtnpQF8H5VwCcicQ36uipYmV7 mvHdsEZbtqC9GXp4a+6bmKjNDWXzlb0JMpXnT8aw1okyRpfA/dv62zFTitdtHv7MweJV ke6g== 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=OVP+he5IQw5W/Xm+I1uQ6X/4pF3ZsGTO5va8vdSRmiE=; b=Nh2HVddtX5NqL50/gr7KI69aK+gIjldLEJwzmeYjNzuEu4yfW8YXzjPbvPWRwoRSCX 4S1i03OtBf4fuUqvQLU1J8LoqL2Nhji7/kt4TEf02ynk2PFpQLE0ns+uNAoJoIDJNMMB 4I+UD+FZEv9cbHgiYZh07jYc6bl2xWtPZ1B3cdRf1i7baW5yM5eE4V2JWrWQVuzyFF9v joTq29sPeIlZGz9Tw3xPs4Fbj0U4hIHyL3ihrlAkeFaN/o7kymM4McgPDFJoXJiHQk/+ vuLZOW8+vGd4jhDeA7U8TWgfr3+UVefq1RlwWOlNg9jCfBq1ZV+dOrtX6xS/LOkAd48N XYog== X-Gm-Message-State: AOAM530jKX6Gxof5Lapcd/ZFVzzZjWWRxQUkFlPiiKdo5LtSwFYLh6uT IYD85witblPRRdPNDenmJ7mP2PYw9bOQng== X-Google-Smtp-Source: ABdhPJyo7rDJfSpgmnNpmcZcVYwAGStTn2lNZgE7UwFVec6aTT+TD7R7AsroXNq6IxNKK6vzOd/OcQ== X-Received: by 2002:adf:ea08:: with SMTP id q8mr39969321wrm.297.1625828783381; Fri, 09 Jul 2021 04:06:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a4sm4978167wru.55.2021.07.09.04.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 04:06:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , Emily Shaffer , Jonathan Tan , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 4/5] pack-objects.c: do stdin parsing via revision.c's API Date: Fri, 9 Jul 2021 13:06:15 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the new "handle_stdin_line" API in revision.c to parse stdin in pack-objects.c, instead of using custom pack-objects.c-specific code to do so. This means that we can remove the "if (len && line[len - 1] == '\n')" check, it's now redundant to using strbuf_getline(), and we get to skip the whole "warn_on_object_refname_ambiguity" dance. The read_revisions_from_stdin() function in revision.c we're now using does it for us. The pack-objects.c code being refactored away here was first added in Linus's c323ac7d9c5 (git-pack-objects: create a packed object representation., 2005-06-25). Later on rev-list started doing similar parsing in 42cabc341c4 (Teach rev-list an option to read revs from the standard input., 2006-09-05). That code was promoted to a more general API in 1fc561d169a (Move read_revisions_from_stdin from builtin-rev-list.c to revision.c, 2008-07-05). Since then the API in revision.c has received improvements that have been missed here. E.g. the arbitrary limit of 1000 bytes was removed in 63d564b3002 (read_revision_from_stdin(): use strbuf, 2009-11-20), and it moved to a more simpler strbuf API in 6e8d46f9d4b (revision: read --stdin with strbuf_getline(), 2015-10-28). For now we've just made setup_revisions() loop over stdin for us, but the callback we define makes no use of REV_INFO_STDIN_LINE_PROCESS. We still need to call handle_revision_arg() ourselves because we'd like to call it with different flags. This very light use of the API will be further refined in a subsequent commit, for now we're just doing the bare minimum to move this existing code over to the new callback pattern without any functional changes, and making it as friendly to "git show -w" and "the --color-moved-ws=allow-indentation-change" mode as possible. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 63 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 3639d0379ed..595adc89c12 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3762,15 +3762,40 @@ static void mark_bitmap_preferred_tips(void) } } +static enum rev_info_stdin_line get_object_list_handle_stdin_line( + struct rev_info *revs, struct strbuf *line_sb, void *stdin_line_priv) +{ + int *flags = stdin_line_priv; + char *line = line_sb->buf; + + if (*line == '-') { + if (!strcmp(line, "--not")) { + *flags ^= UNINTERESTING; + write_bitmap_index = 0; + return REV_INFO_STDIN_LINE_CONTINUE; + } + if (starts_with(line, "--shallow ")) { + struct object_id oid; + if (get_oid_hex(line + 10, &oid)) + die("not an object name '%s'", line + 10); + register_shallow(the_repository, &oid); + use_bitmap_index = 0; + return REV_INFO_STDIN_LINE_CONTINUE; + } + die(_("not a rev '%s'"), line); + } + if (handle_revision_arg(line, revs, *flags, REVARG_CANNOT_BE_FILENAME)) + die(_("bad revision '%s'"), line); + return REV_INFO_STDIN_LINE_CONTINUE; +} + static void get_object_list(int ac, const char **av) { struct rev_info revs; struct setup_revision_opt s_r_opt = { .allow_exclude_promisor_objects = 1, }; - char line[1000]; int flags = 0; - int save_warning; repo_init_revisions(the_repository, &revs, NULL); save_commit_buffer = 0; @@ -3778,39 +3803,11 @@ static void get_object_list(int ac, const char **av) /* make sure shallows are read */ is_repository_shallow(the_repository); + revs.stdin_handling = REV_INFO_STDIN_ALWAYS_READ; + revs.handle_stdin_line = get_object_list_handle_stdin_line; + revs.stdin_line_priv = &flags; setup_revisions(ac, av, &revs, &s_r_opt); - save_warning = warn_on_object_refname_ambiguity; - warn_on_object_refname_ambiguity = 0; - - while (fgets(line, sizeof(line), stdin) != NULL) { - int len = strlen(line); - if (len && line[len - 1] == '\n') - line[--len] = 0; - if (!len) - break; - if (*line == '-') { - if (!strcmp(line, "--not")) { - flags ^= UNINTERESTING; - write_bitmap_index = 0; - continue; - } - if (starts_with(line, "--shallow ")) { - struct object_id oid; - if (get_oid_hex(line + 10, &oid)) - die("not an object name '%s'", line + 10); - register_shallow(the_repository, &oid); - use_bitmap_index = 0; - continue; - } - die(_("not a rev '%s'"), line); - } - if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME)) - die(_("bad revision '%s'"), line); - } - - warn_on_object_refname_ambiguity = save_warning; - if (use_bitmap_index && !get_object_list_from_bitmap(&revs)) return; From patchwork Fri Jul 9 11:06: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: 12367139 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=-16.0 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 10C47C07E9B for ; Fri, 9 Jul 2021 11:06:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBAD5613D3 for ; Fri, 9 Jul 2021 11:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230354AbhGILJM (ORCPT ); Fri, 9 Jul 2021 07:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhGILJK (ORCPT ); Fri, 9 Jul 2021 07:09:10 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29904C0613E6 for ; Fri, 9 Jul 2021 04:06:26 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id f9so5953892wrq.11 for ; Fri, 09 Jul 2021 04:06: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=B+DNXButuOBdEvKdaFxjbJE4nqjN/iN+Op5W0J7rrvg=; b=io41VrxbuLgrCvOgONmHP2B68MgnTJBOxDxh13JiRBhcOrcSmeZrQpMEIL0rvTc4i2 1V5xxoRVUSab4Gh2hMM7rnpkrSyMznXVb4DvzmARtXI0ciL8G95+R1Kz+E1TRYkdNZU6 ey7i9Cut3lkXVaKj/zSdmFpvnRCELC0rvot9leE/9xcGR72hfBA8QquIldjxnuQPZeIg rxUd4ywuaFuWoxJB1Swfz/ABrGgHxKW5u0FUFRCiOJsr2CfJCe7t4S7IqmjT8A1U4FUK V4VP+FvMo98m4whaMuhnBq7dYDKLzU1e6p+9FYskhFxN33VeZ7nG5y0pULiZ/TYWeRDO IPCw== 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=B+DNXButuOBdEvKdaFxjbJE4nqjN/iN+Op5W0J7rrvg=; b=cO8RmGH+0cUEPUyVgRpPqeZGwFeL5E55Zw7TtEGo4y2YYW8L4CcvHGxk2B3tajihq5 8pQ2qIkHovehCZn2BMMQmpGpkKw1UdwrIySCA4gYjgCRn8Uti+hvVAuwsuTkxq+JhW3g gGrdpkK2zaaK9h1laDgImjhRq+RIqkri/+zGnYpuAR5mOjaCT92xNFH4/ZIkwzohdfXC 4H9YGX6TknIoabUz90b7Bokx14TqyYdnqCIe22OWUvV3ut2T2BByy8ZmJJuZfYysPWhQ M9u2mTkYp+hiL378i7Z4QE9//cL9F7Idv8pSxp33KYphHgLTKk/G3HtA0MtmzQ1diT/Q HHwQ== X-Gm-Message-State: AOAM530xpdCJaPTU0A/5Dk/KqJQ5A1AMXSMNr2/UFeYGhn1+vNAKmril yc12b6mijjCGZJlljAUp7SBO0D4ea3FfGA== X-Google-Smtp-Source: ABdhPJwBgiF1ywvFRNybnlYpqgRcJLFq4IxqqthPfIBlomWnrlvsQmCyuXWuipztta72JiM8fe4KrQ== X-Received: by 2002:a05:6000:44:: with SMTP id k4mr820018wrx.174.1625828784460; Fri, 09 Jul 2021 04:06:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a4sm4978167wru.55.2021.07.09.04.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 04:06:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , Emily Shaffer , Jonathan Tan , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 5/5] pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESS Date: Fri, 9 Jul 2021 13:06:16 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the work started in the preceding commit of porting pack-objects.c over to the new handle_stdin_line callback pattern. The common case for the users of this API is to do some of their own parsing or munging, and then have handle_revision_arg() handle the rest. The existing users of the --stdin parsing always wanted a flag of "0" to be passed to handle_revision_arg(), but pack-objects.c wants to set custom flags. Let's support this common case by having a "revarg_flags" member in the "rev_info" struct. This allows us to return REV_INFO_STDIN_LINE_PROCESS in the new get_object_list_handle_stdin_line() instead of REV_INFO_STDIN_LINE_CONTINUE, as read_revisions_from_stdin() will now pass down the right flag for us. I considered making the "--not" parsing be another flag handled by the revision.c API itself, but since there's only one caller who wants this, and the "write_bitmap_index = 0" case is more specific than marking things UNINTERESTING I think it's better to handle it with a more general mechanism. These changes means that we can make the handle_revision_arg() function static. Now that the only external user of the API has been migrated over to the callback mechanism nothing external to revision.c needs to call handle_revision_arg() anymore. That handle_revision_arg() function was made public in a combination of 5d6f0935e6d (revision.c: allow injecting revision parameters after setup_revisions()., 2006-09-05) and b5d97e6b0a0 (pack-objects: run rev-list equivalent internally., 2006-09-04). This change leaves the briefly-used in preceding commits "void *stdin_line_priv" without any in-tree user, as builtin/pack-objects.c could be ported over to our new "revarg_flags" common case. I'm leaving that "void *stdin_line_priv" in place anyway for two reasons: 1. It's a common pattern to allow such a "void *" to be used for callback data, so we might as well follow that pattern here in anticipation of a future in-tree user. 2. I have patches for such an in-tree user already in a series that'll be submitted after this one. See the reference to "git bundle create --stdin" in the commit that added the "handle_stdin_line" API. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 35 +++++++++++++++-------------------- revision.c | 4 ++-- revision.h | 6 ++++-- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 595adc89c12..9f1d7efeb61 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3765,28 +3765,25 @@ static void mark_bitmap_preferred_tips(void) static enum rev_info_stdin_line get_object_list_handle_stdin_line( struct rev_info *revs, struct strbuf *line_sb, void *stdin_line_priv) { - int *flags = stdin_line_priv; char *line = line_sb->buf; - if (*line == '-') { - if (!strcmp(line, "--not")) { - *flags ^= UNINTERESTING; - write_bitmap_index = 0; - return REV_INFO_STDIN_LINE_CONTINUE; - } - if (starts_with(line, "--shallow ")) { - struct object_id oid; - if (get_oid_hex(line + 10, &oid)) - die("not an object name '%s'", line + 10); - register_shallow(the_repository, &oid); - use_bitmap_index = 0; - return REV_INFO_STDIN_LINE_CONTINUE; - } + if (*line != '-') + return REV_INFO_STDIN_LINE_PROCESS; + + if (!strcmp(line, "--not")) { + revs->revarg_flags ^= UNINTERESTING; + write_bitmap_index = 0; + return REV_INFO_STDIN_LINE_CONTINUE; + } else if (starts_with(line, "--shallow ")) { + struct object_id oid; + if (get_oid_hex(line + 10, &oid)) + die("not an object name '%s'", line + 10); + register_shallow(the_repository, &oid); + use_bitmap_index = 0; + return REV_INFO_STDIN_LINE_CONTINUE; + } else { die(_("not a rev '%s'"), line); } - if (handle_revision_arg(line, revs, *flags, REVARG_CANNOT_BE_FILENAME)) - die(_("bad revision '%s'"), line); - return REV_INFO_STDIN_LINE_CONTINUE; } static void get_object_list(int ac, const char **av) @@ -3795,7 +3792,6 @@ static void get_object_list(int ac, const char **av) struct setup_revision_opt s_r_opt = { .allow_exclude_promisor_objects = 1, }; - int flags = 0; repo_init_revisions(the_repository, &revs, NULL); save_commit_buffer = 0; @@ -3805,7 +3801,6 @@ static void get_object_list(int ac, const char **av) revs.stdin_handling = REV_INFO_STDIN_ALWAYS_READ; revs.handle_stdin_line = get_object_list_handle_stdin_line; - revs.stdin_line_priv = &flags; setup_revisions(ac, av, &revs, &s_r_opt); if (use_bitmap_index && !get_object_list_from_bitmap(&revs)) diff --git a/revision.c b/revision.c index 557b7f113a9..f910b7882ae 100644 --- a/revision.c +++ b/revision.c @@ -2090,7 +2090,7 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl return 0; } -int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt) +static int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt) { int ret = handle_revision_arg_1(arg, revs, flags, revarg_opt); if (!ret) @@ -2140,7 +2140,7 @@ static void read_revisions_from_stdin(struct rev_info *revs, } die("options not supported in --stdin mode"); } - if (handle_revision_arg(sb.buf, revs, 0, + if (handle_revision_arg(sb.buf, revs, revs->revarg_flags, REVARG_CANNOT_BE_FILENAME)) die("bad revision '%s'", sb.buf); } diff --git a/revision.h b/revision.h index 52241c84c5b..3da56333960 100644 --- a/revision.h +++ b/revision.h @@ -156,6 +156,9 @@ struct rev_info { * revision.c's normal processing of the line (after * possibly munging the provided strbuf). * + * Change "revarg_flags" to affect the subsequent handling + * in handle_revision_arg() + * * - Return REV_INFO_STDIN_LINE_CONTINUE to indicate that the * line is fully processed, moving onto the next line (if * any) @@ -164,6 +167,7 @@ struct rev_info { * around. */ rev_info_stdin_line_func handle_stdin_line; + int revarg_flags; void *stdin_line_priv; /* topo-sort */ @@ -422,8 +426,6 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, const char * const usagestr[]); #define REVARG_CANNOT_BE_FILENAME 01 #define REVARG_COMMITTISH 02 -int handle_revision_arg(const char *arg, struct rev_info *revs, - int flags, unsigned revarg_opt); /** * Reset the flags used by the revision walking api. You can use this to do