From patchwork Thu Jun 17 10:57:34 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: 12327443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A37DC48BE5 for ; Thu, 17 Jun 2021 10:57:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48A53613C1 for ; Thu, 17 Jun 2021 10:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232215AbhFQK74 (ORCPT ); Thu, 17 Jun 2021 06:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbhFQK7y (ORCPT ); Thu, 17 Jun 2021 06:59:54 -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 C6F71C061574 for ; Thu, 17 Jun 2021 03:57:46 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id c84so3121581wme.5 for ; Thu, 17 Jun 2021 03:57:46 -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=TMCULwZF6CNrBKVIawGJoMUhqkcP1UdIvescnf1bLrw=; b=n/n5bCTTl+wVGCvgE2qJNyWnkob9e6Wb4OLqqGpyoix5rWjMj09gW3ErfPIOsose6o MshVqN7e+0AFtEkrJdPHrMrvYRL93gcj7AvS6NIUOWxwB+ZnzHlUgg3H9VE2Vfy4mcSb /PCCFhdA98q190/wAsUgSRGyfber9ZovSNtInJhYaleQEB7GAUWtnIHmI2d08PrRxRz3 C4rAbSG785D7jG69Rh2Z7WiwYoaZ4MO6TZ+rodpoBnZ8qxW8N/vqrn850GeP8g2IEkzE wnibD3vBaUNZ2ch+882R7BJyNuLaP8T4k/0Qc6SBGqFssV9InfJr8oXXRd1IE2PFPsQN atGg== 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=TMCULwZF6CNrBKVIawGJoMUhqkcP1UdIvescnf1bLrw=; b=tnxZ66zCduJoXC/mT4FtK5keT2qlBNDda2Xbp49mHtN1GnSNHTep1VcOXehdd2jUKq bGsLfBJ2uvZEOcOQEKRegufDLz9l3ylVlBZVldkkSq7Z/LPw6MnY6IsanZ1a3QVWcVNT 3S6BThgLaQ2EIeypM57/ncme4K78Ds+VJLS0pg0HVbJZxLWSlbA6NUXmqub90GjUg4zN A8TIvZLh+9mdNhziZdSeiM53+rFxRloIbj8k4DVIehg45zjOJl95Gj5CYr2i6FuEvNyg 9rA734+UG9HPGe0XDyMKKNQSE9AgsVqEdTnwj/gad6BAdI+vmtdev39vFnx5XXX3X+7n i9Zw== X-Gm-Message-State: AOAM530zRZcxNXTSKIavdp3e3dN7jx4JioI300/wwm5W1Q7d8dWabmeE ogQSzUSMMr26GugrPGz3uTxg7en5tEzRgg== X-Google-Smtp-Source: ABdhPJxuJpHPVZC3ZsHMegfIXmEAg0yqIa/sjG73gOmX0vN7vUM3GVHekR2qkwezTncea1IWpQhAuA== X-Received: by 2002:a1c:984c:: with SMTP id a73mr2660200wme.17.1623927465090; Thu, 17 Jun 2021 03:57:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k5sm4897948wmk.11.2021.06.17.03.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 03:57:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 1/4] upload-pack: run is_repository_shallow() before setup_revisions() Date: Thu, 17 Jun 2021 12:57:34 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.571.gdba276db2c 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 de00adbb9e..1fbaa34f91 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 Thu Jun 17 10:57:35 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: 12327445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99752C49361 for ; Thu, 17 Jun 2021 10:57:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FD6E613CA for ; Thu, 17 Jun 2021 10:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232218AbhFQK75 (ORCPT ); Thu, 17 Jun 2021 06:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbhFQK7z (ORCPT ); Thu, 17 Jun 2021 06:59:55 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA136C061574 for ; Thu, 17 Jun 2021 03:57:47 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso6064772wmh.4 for ; Thu, 17 Jun 2021 03:57:47 -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=492/eCqUUOmePPYBWDmCqKw1Cql2fje/3YNwy33+QB8=; b=D/UiFccQgc3rMVOWUShmod/Vr70hhazHdrngHoxsve9OVd9rPOVDMS1Nk0+0OXr1aH zhGNPJZG92Am3jRDuDHZ3eY4E+44dsmc6dg0uOR8PgkNPM1XrNXQiEqX+sMNN5RyItt8 /QjocKwWfhoIQd7qnIkdgaKZjweNXzVEGuhd7Rc3ddgFIXF4NegoVXdOCFZjcmBCG9im T6/TNp59rSzdDRGoE+6pkLKqMgXHquqGWkfSotC60iDlw23uZpSu37IQsCP7TjLT4qHs EHsvw0IusugpR6rPjfPLZqLcr3P5AqtI7EaUUoahwo4fHJClLNu0in1w3KsNX/ILYbcz yAhA== 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=492/eCqUUOmePPYBWDmCqKw1Cql2fje/3YNwy33+QB8=; b=H9ciDqPlxqW31Tdvkf0OQHMG20WTjVYC9s5X/9481fx/m33KH9mLrc6I8EOCueRLD6 K0uGFAFmDXns64y5zWl+rSXj8cbKu67lzJYz7hSobpQcHpnIr0xfpZwIKk7n1aAv2ZZu gVobwwo+ALiacrpMueo35HoZA+TFgcXyYcZSoXVMeDmUTcJgAEtNqoTsuxMr5swyiUwG VwJqgF7h7fVIx8wNTOCM5sNnkBX6RbLRPOYg2+hTDvDonmEKz00ZmAIDYY7DnqCbVW3Q ZqZ/jS/OEQOCE82r1n96ALQwXnygeJ6LXY9nxb7/9VM20at7cep4QWD9cfiwzydBVfxD Rwpw== X-Gm-Message-State: AOAM531o4QJKQiZ1DdSLXEw9cfJj6Ra4rvYC1J/vN1IkoJekZE1Frrub 4bbrgpUrdzWkQYJ0IrOn0RTFA55Q1jalGg== X-Google-Smtp-Source: ABdhPJyE28UkMVNhaMu1E4VnnOWD4CVLpUsNjaObKRLuG9xhsTB5h+1P0uhwVcPgTUt6qhiLHUTgpg== X-Received: by 2002:a1c:770f:: with SMTP id t15mr4264978wmi.182.1623927466023; Thu, 17 Jun 2021 03:57:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k5sm4897948wmk.11.2021.06.17.03.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 03:57:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 2/4] revision.h: unify "disable_stdin" and "read_from_stdin" Date: Thu, 17 Jun 2021 12:57:35 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.571.gdba276db2c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 8b3dce56508 (Teach --stdin option to "log" family, 2009-11-03) we added the "disable_stdin" flag, and then much later in a12cbe23ef7 (rev-list: make empty --stdin not an error, 2018-08-22) we gained a "read_from_stdin" flag. 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 read it", 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. 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 | 4 ++-- revision.h | 23 ++++++++++++++++++++--- sequencer.c | 4 ++-- 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 0b2d886c81..3a6c8455b4 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 641523ff9a..c9f66c58c4 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 f33d30d57b..fc548ebe16 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 7677b1af5a..88bd9ef954 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_per_option) || revs.diff) usage(rev_list_usage); diff --git a/revision.c b/revision.c index 8140561b6c..69b3812093 100644 --- a/revision.c +++ b/revision.c @@ -2741,11 +2741,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s } if (!strcmp(arg, "--stdin")) { - if (revs->disable_stdin) { + if (revs->stdin_handling == REV_INFO_STDIN_IGNORE) { argv[left++] = arg; continue; } - if (revs->read_from_stdin++) + if (revs->consumed_stdin_per_option++) die("--stdin given twice?"); read_revisions_from_stdin(revs, &prune_data); continue; diff --git a/revision.h b/revision.h index 17698cb51a..475c8ed785 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 = 0, + 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 reading if we see it with + * REV_INFO_STDIN_CONSUME_ON_OPTION. + * + * Can be set to REV_INFO_STDIN_IGNORE to ignore any provided + * --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_per_option; /* 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 0bec01cf38..4e73bd79d6 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 Thu Jun 17 10:57:36 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: 12327447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 803F2C2B9F4 for ; Thu, 17 Jun 2021 10:57:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 685C8613CA for ; Thu, 17 Jun 2021 10:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232227AbhFQLAB (ORCPT ); Thu, 17 Jun 2021 07:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232211AbhFQK74 (ORCPT ); Thu, 17 Jun 2021 06:59:56 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DEC1C06175F for ; Thu, 17 Jun 2021 03:57:48 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id t4-20020a1c77040000b029019d22d84ebdso6066361wmi.3 for ; Thu, 17 Jun 2021 03:57:48 -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=BqtuiNPY+vjgqs3YQPKePwuhzH1ueInsD6tD4VnWCJc=; b=NA5LwwsYjDYvZDWdzrFQE75YtznbDCHMY54nLFfvcL5vc8OVFiAyWPooKvgq/yjaX7 GOHpGKjF6CrMj+Wt4haOKEMM9pGHrrceSgfEQ2lpu0n6zjEgxlVz1hAmzqHd7lJ32Mgz zJEuzYu4Uf4KML95nv7KkEB7n9J1gV6/SO6POfovfKzn6Mgn/oAbFWr/SOZqvQQ+OKVL dYsJZ4709zRwgCEwEX3SXOzBtw9MG9Xwo+tL6Sp9QVHcGwObYjTL7VxDnojz/4Vlk6EZ uuc5eAUrzlwTF+gFgtmi0HHtm/zDyf5K2++sLjwv1A7EhvhBonxwHYE3tuGq6Bua0Nnp /zUg== 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=BqtuiNPY+vjgqs3YQPKePwuhzH1ueInsD6tD4VnWCJc=; b=U6Iorc98c/5up+h36jtnpWW5VzXg40ceboeFdWw1DFXUXam1oM6dBH27qMGjtdekw2 zu+gZv3jLQxnoJFiqe4Zu9lX7MJTxgXXS7tOCm5jBl4K0TEBgku1oQ8Ybni29527znV5 OHiLIXtdzaQAlmwxL0L9Kg5tMImwHqJO/db+3+E4kn3St6f2MJRpB7l+lJKwZ/Avg6eq jtAVvTry77C6AGCdNhrU2yQA7j4G082YvmojBKeVnOxICBHic2+c6RltF75pwlhChdOZ o9sz4Iq0ftDe63XQJmpLASKttnoEwrALcc4Kb7O0CrN9sOa5uCTP5lKO5wuhmlChgCab 0DGQ== X-Gm-Message-State: AOAM530m9zBw/N8tyVWdQeCznMZw7KaVflTZprKmrvRhxqzjGhaybnYa HjcmaLtI8mJU/HUVxW7fDwMcSLBuQc0+xg== X-Google-Smtp-Source: ABdhPJzDk0YU13RvFCHVN5k2EaBjnvuLm7n+grztz+d1Zw5qY9i8yEHjjnn//MzMTCm348UCVXtp2A== X-Received: by 2002:a7b:cc09:: with SMTP id f9mr4341453wmh.104.1623927466822; Thu, 17 Jun 2021 03:57:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k5sm4897948wmk.11.2021.06.17.03.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 03:57:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 3/4] pack-objects.c: do stdin parsing via revision.c's API Date: Thu, 17 Jun 2021 12:57:36 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.571.gdba276db2c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the fgets(..., stdin) parsing in pack-objects.c to use a now-extended version of the rev_info stdin parsing API. The fgets() loop 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), and 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). Let's do the same here, as in 6e8d46f9d4b 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. For now there isn't all that much point in this whole exercises. We just end up calling setup_revisions() to 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 | 66 +++++++++++++++++++++--------------------- revision.c | 27 +++++++++++++++++ revision.h | 35 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 33 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 1fbaa34f91..cbb01f2b2d 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3745,15 +3745,43 @@ 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; + size_t len = line_sb->len; + + if (!len) + return REV_INFO_STDIN_LINE_BREAK; + 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 +3789,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; diff --git a/revision.c b/revision.c index 69b3812093..2ca2c38447 100644 --- a/revision.c +++ b/revision.c @@ -2119,6 +2119,25 @@ static void read_revisions_from_stdin(struct rev_info *revs, int len = sb.len; if (!len) break; + + if (revs->handle_stdin_line) { + int do_break = 0; + 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_BREAK: + do_break = 1; + break; + case REV_INFO_STDIN_LINE_CONTINUE: + continue; + } + if (do_break) + break; + } + if (sb.buf[0] == '-') { if (len == 2 && sb.buf[1] == '-') { seen_dashdash = 1; @@ -2787,6 +2806,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s } } + /* + * We've got always_read_from_stdin but no --stdin (or + * "consumed_stdin_per_option" would be set). + */ + if (revs->stdin_handling == REV_INFO_STDIN_ALWAYS_READ && + !revs->consumed_stdin_per_option) + 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 475c8ed785..5df1523a6c 100644 --- a/revision.h +++ b/revision.h @@ -89,8 +89,18 @@ struct topo_walk_info; enum rev_info_stdin { REV_INFO_STDIN_CONSUME_ON_OPTION = 0, REV_INFO_STDIN_IGNORE, + REV_INFO_STDIN_ALWAYS_READ, }; +enum rev_info_stdin_line { + REV_INFO_STDIN_LINE_PROCESS, + REV_INFO_STDIN_LINE_BREAK, + 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 +136,9 @@ struct rev_info { * * Can be set to REV_INFO_STDIN_IGNORE to ignore any provided * --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 +149,28 @@ struct rev_info { */ int consumed_stdin_per_option; + /* + * 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_BREAK to process no further + * lines, or anything further from the current line (just + * like REV_INFO_STDIN_LINE_CONTINUE). + * + * - 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 Thu Jun 17 10:57:37 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: 12327449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C609C49361 for ; Thu, 17 Jun 2021 10:57:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E0B9613BF for ; Thu, 17 Jun 2021 10:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbhFQLAC (ORCPT ); Thu, 17 Jun 2021 07:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232216AbhFQK75 (ORCPT ); Thu, 17 Jun 2021 06:59:57 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BCAAC061760 for ; Thu, 17 Jun 2021 03:57:49 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l7-20020a05600c1d07b02901b0e2ebd6deso3428360wms.1 for ; Thu, 17 Jun 2021 03:57:49 -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=pu+77s0V4l031kxzJBk0xvkCfchX6l2gU6Ik+6hSP+M=; b=kwjAIcnPYUipGGByNwOIQv65FI3i9fNdZq2w51Kr7Rg2vkO6ToOskXgYtamXbeZd+p VIxQEjY8J2XHbb50LeD6ZA9IxOr/4ri+NpIfn/KiNMa7fdyxHTKi4yom7mQK6qUso4HH ueS9kRBKpGLSJnGeN5zqHNe8pLMRbgDSyg3boTX2dU5URRjMT2fxeWcjWXr0Y/sIBfZN 1k9uT5H/2mw7WYmcnEVBpYUPi1juXeVeIRGyEVX+zj+DZrjJ/tfFhACW0lgYExij3VuK f3tjUkw3hy1pxwhN//AJ1DRs3y+nL1V4Jxjat85t619JKqiDXGrFSzp4HgyPgHITx+wd khbA== 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=pu+77s0V4l031kxzJBk0xvkCfchX6l2gU6Ik+6hSP+M=; b=OmcQhOlMNILEDelVNOdFrm46HJFeN05Nc4odmjgOztMI/B7opDDg9+av+zvjzYpaEE 2MVIk0Omu4+SeX1DdjEDa1OQCH0ece35/FknzucCnePG38zpcCP09f0o9Olg5iahBcEu GhU6tx/pSKbvxTvwRJ0VgESxbZfzK9IdUkxl1oWoAzrTD7W5MtOl3kDP8oPsUEdcdECU HZMYB9MZWvnrFWtwGGzfaaiaAXWMAXlySIkh1FTJdo56s4xWQYv5Am5klmHUBFa3HK6V OWm2Vg/OIEZTzNPwlRpsZQ42IByjJFZoqqpIDy/1Zl2mRFnWHjqGaVnPAI0O1aC6GUSL yUpQ== X-Gm-Message-State: AOAM533VNjzQEl3RhSq/O12j7fTJxMJNRm9jARPQToutqtqtDUYBMxt5 3KhLvuV3MtZTU4dGUVRo4/0JHyMLll+qwQ== X-Google-Smtp-Source: ABdhPJwoxayiA0xaec6ke/JnsCmmyR4UiHkknx7UPb9pCAVuTCRexQSbbQ8ST8Q+UTDfG2P3RO9N+g== X-Received: by 2002:a7b:c192:: with SMTP id y18mr4390973wmi.65.1623927467716; Thu, 17 Jun 2021 03:57:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id k5sm4897948wmk.11.2021.06.17.03.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 03:57:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jiang Xin , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 4/4] pack-objects.c: make use of REV_INFO_STDIN_LINE_PROCESS Date: Thu, 17 Jun 2021 12:57:37 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.571.gdba276db2c 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. This also 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 9 ++------- revision.c | 4 ++-- revision.h | 8 ++++++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index cbb01f2b2d..0ab2d10853 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3748,7 +3748,6 @@ 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; size_t len = line_sb->len; @@ -3756,7 +3755,7 @@ static enum rev_info_stdin_line get_object_list_handle_stdin_line( return REV_INFO_STDIN_LINE_BREAK; if (*line == '-') { if (!strcmp(line, "--not")) { - *flags ^= UNINTERESTING; + revs->revarg_flags ^= UNINTERESTING; write_bitmap_index = 0; return REV_INFO_STDIN_LINE_CONTINUE; } @@ -3770,9 +3769,7 @@ static enum rev_info_stdin_line get_object_list_handle_stdin_line( } 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; + return REV_INFO_STDIN_LINE_PROCESS; } static void get_object_list(int ac, const char **av) @@ -3781,7 +3778,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; @@ -3791,7 +3787,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 2ca2c38447..ad94a646f7 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) @@ -2145,7 +2145,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 5df1523a6c..c473567d82 100644 --- a/revision.h +++ b/revision.h @@ -157,11 +157,16 @@ 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_BREAK to process no further * lines, or anything further from the current line (just * like REV_INFO_STDIN_LINE_CONTINUE). * * - Return REV_INFO_STDIN_LINE_CONTINUE to indicate that the + * + * - Return REV_INFO_STDIN_LINE_BREAK to indicate that the * line is fully processed, moving onto the next line (if * any) * @@ -169,6 +174,7 @@ struct rev_info { * around. */ rev_info_stdin_line_func handle_stdin_line; + int revarg_flags; void *stdin_line_priv; /* topo-sort */ @@ -426,8 +432,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