From patchwork Mon Jul 26 12:46:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12399481 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 9014AC4338F for ; Mon, 26 Jul 2021 12:46:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 729E4608FB for ; Mon, 26 Jul 2021 12:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234043AbhGZMGK (ORCPT ); Mon, 26 Jul 2021 08:06:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234146AbhGZMFq (ORCPT ); Mon, 26 Jul 2021 08:05:46 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F39C061760 for ; Mon, 26 Jul 2021 05:46:15 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so6167937wmb.5 for ; Mon, 26 Jul 2021 05:46:14 -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=lIB2AAOP3aOn+4x3Ic4fnOCSEJyID2+Csqbd4VIz00s=; b=JWZLANNp3L2n3AqoThF08TnfunL23DguTTLGkSd9r9QTJNmMdlfrTcccVUlf+YGoTz oJvEqc43Lnu9jDAGlvnzfd0kbR/kotR3h07ABIrjxKBTo5GakqwEm06+pDCsK4hDXix3 qMbkMEiFVE6wY6/yd8545pd62AGM8Gwvd1bLY9gKQBEp4eL1oL2Ri8nm1rxohCsHpuMC 5u/myty0Hxic/XX0E9Aw/yD68hVA7KDJYu03X9JfFKe8/kUX3F3PlKXBN4Mha47pAGdn hR2v/Qb2u6WMwD5OAqYFCBp8C0exOgl00d1GxLuJv3QBOm0EPd26gEbUgAC1stZe4YqP uf6Q== 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=lIB2AAOP3aOn+4x3Ic4fnOCSEJyID2+Csqbd4VIz00s=; b=tmGNv0kVGxyPXBcVN7HSM5IRTvRgnWpLIZ+B4VYCtD+UuAXC4q6s0LjcxT0Rg7uAKw Wup7D7ViCLwgkAu8PcfGud4HCxx/x8D9FUZVWLAfZ4Fw6RFQRzGP6tZPVD+eqJmLBl9c 86cmUR/aftnFbx5qFjwJQZn9pu3CBvs/61DnXc57spv/XOawiU6FWs7moh6jL2bz+bZZ c0Qzm41n6W0WcTz2gyIDZghDhqBi0159HirSqfRzTnnPkOEM+0qNJxwFl9VgEsPNOxDM Mb/YI+VRxMhD9ncE83yZ1PQIa/b1n6jwazYmRyiagOlbvYVgMccjEcLiztuJzr7hgpzy wqDA== X-Gm-Message-State: AOAM532JKdlGG3B94TCRWm5OlAGRKWD/ZsG1x5615C/BhDTFPYFAVtKZ aLFnPK+qTB4lBhwnZIxxF8jAQRIqhRmNYg== X-Google-Smtp-Source: ABdhPJz5vFuwQB56diJtFzL7QjN7LTr+lpQAH3p6DImnuLUx44jK1PJevYQPYZLOQ11UsOgX69IpqA== X-Received: by 2002:a1c:9ace:: with SMTP id c197mr5501113wme.170.1627303573349; Mon, 26 Jul 2021 05:46:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w18sm45155444wrg.68.2021.07.26.05.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 05:46:12 -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 v5 1/5] upload-pack: run is_repository_shallow() before setup_revisions() Date: Mon, 26 Jul 2021 14:46:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.956.g6b0c84ceda8 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 de00adbb9e0..1fbaa34f91b 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3757,11 +3757,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 Mon Jul 26 12:46:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12399487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FFECC4320A for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 349FE60F5B for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234183AbhGZMGX (ORCPT ); Mon, 26 Jul 2021 08:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234147AbhGZMFv (ORCPT ); Mon, 26 Jul 2021 08:05:51 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE3A7C061764 for ; Mon, 26 Jul 2021 05:46:15 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id k4so5244793wms.3 for ; Mon, 26 Jul 2021 05:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UtWSUblhIwb6qJqdRLxQ+YImbORm4FGLMMzAz58wc14=; b=HxGSHSpFpghroyER4A6DUL4h16ZnIa9PLSLcq5mcdUIAE4z9TbxtenkV599oIyrLVd sguO5xYsyNnNmYMW3cZq+iCmRXu9TXwcmDsRlB2B5NdGVLCh9056kfElPVfM7gNMzkqi J8W/tACzdu9Agvkgy97YXN9mn1PxpbWmrDXCCVtSGiH3AP9ocT4rQ7x3cbQC3PE0iJ1l WXfsSumlXiUv7dkfW+ylTVCV4Vt9eCnNVHFbtj1GOCk7zleaVfQiZSajGKKYGf8uoxDV 6RZd0oUR5g4sw0Bddbyo4McUJgIh/DM0h72QMPNWo/LDYKMg2mwYvEbwT5M2P2IWOOgW bFbA== 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=UtWSUblhIwb6qJqdRLxQ+YImbORm4FGLMMzAz58wc14=; b=RzXP3FacrCL1KyvC7M+plYYVKFfd4dgIOUNPx1hUY7rkoH+QDf+/AO4ujcgCYs2e1F FGZMRsYekNL+Ryo0ZfQvL9YdN6OXEpRJkdQpCt3dwwg53SnkmKfstG9cusi9rk3oaKJr hwYesYGsom+iNsj+1v3V/Fo6Wdpbio6AQ1KCA3CiOE9pFAOpCISwOA8XUnME4xpul2DV zuTVRqZWioO4F5gALS41pRAfWz10V4isabv5h3wikwgwlrAVzOqGyuveVi1XnrmzACva /yDQgTRkHe2dyMA1siTPWvSELfVc5rd0YlXexwl7S1mQf0lcF2Xy+KVSUC+3UQ2YlOec Hh4A== X-Gm-Message-State: AOAM531YPQjbkjcFMrPaWsfSVFUKzl83uapQvZ9hw1nFw2Vbt4PZEWjz 7gAlcBzcYygDEwIkruEOE4xAuaSBFFJavA== X-Google-Smtp-Source: ABdhPJxsJXfwEaIxoB2NX353TYIQQT1tIBS29LAxSjLgbQSZOYHKCJuQTjx8cAPwdlUiGmCOlkbD2w== X-Received: by 2002:a7b:cd14:: with SMTP id f20mr1084446wmj.113.1627303574302; Mon, 26 Jul 2021 05:46:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w18sm45155444wrg.68.2021.07.26.05.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 05:46:13 -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 v5 2/5] revision.h: refactor "disable_stdin" and "read_from_stdin" Date: Mon, 26 Jul 2021 14:46:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.956.g6b0c84ceda8 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 | 24 +++++++++++++++++++++--- sequencer.c | 4 ++-- 7 files changed, 36 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 36cb909ebaa..f1778833401 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -666,7 +666,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 8140561b6c7..50909339a59 100644 --- a/revision.c +++ b/revision.c @@ -2741,14 +2741,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 7464434f600..99458cc0647 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; + unsigned int consumed_stdin:1; /* topo-sort */ enum rev_sort_order sort_order; @@ -217,7 +235,7 @@ struct rev_info { preserve_subject:1, encode_email_headers:1, include_header: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 Mon Jul 26 12:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12399491 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 87448C432BE for ; Mon, 26 Jul 2021 12:47:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68058608FB for ; Mon, 26 Jul 2021 12:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234217AbhGZMGc (ORCPT ); Mon, 26 Jul 2021 08:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbhGZMFv (ORCPT ); Mon, 26 Jul 2021 08:05:51 -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 06FD7C061765 for ; Mon, 26 Jul 2021 05:46:17 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l11-20020a7bc34b0000b029021f84fcaf75so8110058wmj.1 for ; Mon, 26 Jul 2021 05:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TPblhcHA6097nBq4dRK5qfiVYoDWzlFBEFuiC8qcpME=; b=REKBPT3/0uyv/jxNluACSUguf2SSTutPnrxCJY7CIffmpqw6+TR7FxdmZclQOXGVZt AKgrLKe6FPwrG2SBUNG8+KtgjGCCrE0x7rmvJ0jT0XhRdl6hQlxwuHRnBclEFg/deDj0 aET+Yn5INBjlrkBXGvBc6LZoJfKmTHLj2/vqoZ7s4JUcXSNfhjcgqPQ8Z0DqQ9QJ1G8F OvxyBJhF8HkdEnKRUHDhO+5fzI4Y9yFuLWWDUZ5Wcjs/kSQw6q9Zv/G3fHdouOUo7FhT PUpmJcoOrsOk8u7ruak7fALXXoLT3CCQO//SsJAib30SIzJBApRBd3baxqtuLv3nQSuD Uxmg== 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=TPblhcHA6097nBq4dRK5qfiVYoDWzlFBEFuiC8qcpME=; b=gxWpEXQ46i0H0gqdghN8t6/ledo0xwIBbX+T2MIed0LiU7DMVVFTDV/K85szas5hbr 0eOXnVhIJAIng8HIGt+J1ZB7JkBcQlpsyZubDNS4wO6Mn9n3NEqQy4nvIqZQIL9K9X0E NHQhy/0QQeos0qx+9iQe7ehPGt4NeX2mEWmMGN1CWHvBRjHw3leSTltt2XFqjW8FYN7I iy9RhGmGtkpp5TWqvP/CnCrY/Ak+sLSrNQ5rNFuEIuIvjcuKWOB9BTAEMjJADulWI1KT h0v1MbHrNqLp4ofDyD6Ud0nlcugO24sUxV0yIP+wNi/+tqchq1H4cQsWgf0nysm0DtDr uOVg== X-Gm-Message-State: AOAM532O8Vd1wtpsPm/YYLyOu9HzFqAG+74nqpxOl0bo+f+MoAmL3PSB y0ZxoL+zKvdAtjd1022/lkTG9ypXvAfUuQ== X-Google-Smtp-Source: ABdhPJysFm4+CQixsZxypH1bOQ5OdQVIafsTXQkYF8GFTZ+mvcbWC5FZ2X8ijMzF0e0A95hqYlpRdw== X-Received: by 2002:a1c:f214:: with SMTP id s20mr16908694wmc.14.1627303575275; Mon, 26 Jul 2021 05:46:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w18sm45155444wrg.68.2021.07.26.05.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 05:46:14 -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 v5 3/5] revision.[ch]: add a "handle_stdin_line" API Date: Mon, 26 Jul 2021 14:46:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.956.g6b0c84ceda8 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 50909339a59..3f6ab834aff 100644 --- a/revision.c +++ b/revision.c @@ -2119,6 +2119,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; @@ -2742,6 +2755,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; @@ -2790,6 +2804,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 99458cc0647..644b7c8a217 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 { */ unsigned 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 Mon Jul 26 12:46:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12399489 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 DAF18C43216 for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2AAC60F4F for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234191AbhGZMGY (ORCPT ); Mon, 26 Jul 2021 08:06:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234153AbhGZMFv (ORCPT ); Mon, 26 Jul 2021 08:05:51 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD158C0613C1 for ; Mon, 26 Jul 2021 05:46:17 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id f14-20020a05600c154eb02902519e4abe10so1921318wmg.4 for ; Mon, 26 Jul 2021 05:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ynEu1jl1gTVyIMiJeZeFPtz266FsAS7PTrg/gUPDBRI=; b=BsntoY/WOz5/fMUOpcr+UHWlgB2WLQtNTDQrBaEyw4a3iDVnldyv/VOJRkYVYTDPqw tW3yiTH9Hs03BAhtAkTM23Lpr249utPJPLWLE4Gf3Xy5G2QBzdPv3upWOR1SA9HT+VIS jPaTs6iFliNBhwSlSjQvu+LCXLONhyfizD8qfNhZ5qOVPeuheD+syZv7HGD8oBjotZZR G0X7ZZMPrTvxxRtxxwm/h48ZLOjeBH9c1SLYjbKVpAoNdNbkxvp2ImNbiKAXhU1+3ogR Hvt6xFkoWCZUddzRGgE8FXRcY68e0KL6aAbp6cX524mB44lcZ6BboSERP30iSnjPZYLi cajQ== 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=ynEu1jl1gTVyIMiJeZeFPtz266FsAS7PTrg/gUPDBRI=; b=MAUMnUhtQAkIF5LSZ6feS75EsbVeU17gpwSwRCfeeH8gmpqzhXLRpKg+aYak+hsDPs 5cXAz20LpEr9rB+WCuI7GKEBt4VeyU25uADyi8r4c7P/EJJx8mbvua+CuEeY1JodnYAt GReOWObxDnjX1WCjJj5nFhlNgVm9lPoZwPmuvDdqhxM2twYjbQbaGPb/6wd1a9987JL2 lVdKPhY9RU9P0QgivgXPHMVIRK6IxwO/Npl9qSM2VPGOMZgqvUKi9d2iNmi2iKAQkJbx UNQ6e3sz2Hp0M/YcreIskRSxNxehPgQ+/FHWCx8Jsf+gxF9Va097eUS8zc1gRyqgO6Nn 3Nug== X-Gm-Message-State: AOAM5319fYjyEHVfMV8oNUZ/HKJ7dzSAsF/iZNIJ5vl9KR1mzf64lipw vGqR5h/VOqO3dUt/67kmdM8mnGW+m34KOA== X-Google-Smtp-Source: ABdhPJyTLDPzAhRA8KbpQ9/4DwVCsnGSOa+DoEpBb+9vZcaCdmNtwHVkm9NZWRc3QBor8E5W71x7cg== X-Received: by 2002:a7b:cb4d:: with SMTP id v13mr15775121wmj.68.1627303576133; Mon, 26 Jul 2021 05:46:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w18sm45155444wrg.68.2021.07.26.05.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 05:46:15 -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 v5 4/5] pack-objects.c: do stdin parsing via revision.c's API Date: Mon, 26 Jul 2021 14:46:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.956.g6b0c84ceda8 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 1fbaa34f91b..35d5247f85a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3745,15 +3745,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; @@ -3761,39 +3786,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 Mon Jul 26 12:46:10 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: 12399485 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 2FADFC4320E for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 159C560F4F for ; Mon, 26 Jul 2021 12:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbhGZMGW (ORCPT ); Mon, 26 Jul 2021 08:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234050AbhGZMGH (ORCPT ); Mon, 26 Jul 2021 08:06:07 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C04C2C0613CF for ; Mon, 26 Jul 2021 05:46:18 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id b9so10077477wrx.12 for ; Mon, 26 Jul 2021 05:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P4NcsvRbIYhY3Sx7HCuzl6z66UVDeeGH4hmW7IgywXk=; b=cMhC5IWv/eqAC7eMOn827hUf3lMi4ioUwzoPYVXNzZ7oF4PMe8qb3J8xSyv/xGX4q8 u2zPM6P8/nsyjvMYNQ2fa4jJ9iyHgkHgagIqJPpkj/nCyGh8oZwUeBvh8ikQN+kFwABo danM+K26GZduK1gq40bJEMUyV3AO4ygpG0g4k/ZwwhbiOmz07H5zt9+3z71Cqe5wTDn1 ct5irYtfV17Ch9rz0ijzTnRD3OALpz7K9Nczc9flmuTrmb5O5EiYRPe8j6Lm4ODKAvEJ v+v0Uo3x8rPa6cRfUoNGog/aTAmUw3JaS1txVapOZA8OwpEktFQlWBwqKlD1QswGXkr4 6+Hw== 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=P4NcsvRbIYhY3Sx7HCuzl6z66UVDeeGH4hmW7IgywXk=; b=ZOEiXQ3ilWhPCMLFpblevptLhYUb7zNt4LtZzb7yYOZUv7stD7V9k7PR8hwPN/F0yQ R9gPsE+noAU7HbTtMLmnX1l4c7SHvpj7cNS39m7uCsuI3Lv+YBpSvmoOOMPLRvRe9hKL F2fcCZOBjoV4bR4OXIH1/FLaz6mcxP3bOf6hBROQkfktD5bpzzSKw0kNVqfFf4uGkEyF 6ZLWkQO5MzXXEs46RejqOZIjWi1ClNUerJf3ynF1V8kyszb8oXX1oGwWT1tLfpoV4r+L Us6Gna7UtB+tcQH8s6ezOYtfgiVZZrMCh96gU28oJkC4/3wkRMaLm/8Xf6Vlxn3zqsL5 3Vdw== X-Gm-Message-State: AOAM5327G4OusM6neATxqImKfR1CaQYPuckwjIu79BS97+2yi2jSV85y XNqF2c55ODMxYHtxdMJaYw7WKO+lswqGqg== X-Google-Smtp-Source: ABdhPJzlZ0ySzU84YhAHpgrsv9XKreK6fhh1ifm+yYLl860hLcuZ51bdwGedhfX/xfZM2yEl5rsqEg== X-Received: by 2002:adf:ea52:: with SMTP id j18mr3240094wrn.294.1627303577083; Mon, 26 Jul 2021 05:46:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id w18sm45155444wrg.68.2021.07.26.05.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 05:46:16 -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 v5 5/5] pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESS Date: Mon, 26 Jul 2021 14:46:10 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.956.g6b0c84ceda8 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 35d5247f85a..06a085a9a2a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3748,28 +3748,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) @@ -3778,7 +3775,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; @@ -3788,7 +3784,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 3f6ab834aff..4164a4fcd11 100644 --- a/revision.c +++ b/revision.c @@ -2089,7 +2089,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) @@ -2139,7 +2139,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 644b7c8a217..fd7fdbe42e8 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 */ @@ -423,8 +427,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