From patchwork Sun Sep 12 00:15:49 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: 12486663 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 8C27EC433FE for ; Sun, 12 Sep 2021 00:16:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E273610A3 for ; Sun, 12 Sep 2021 00:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234026AbhILARV (ORCPT ); Sat, 11 Sep 2021 20:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232515AbhILARV (ORCPT ); Sat, 11 Sep 2021 20:17:21 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2BF8C061757 for ; Sat, 11 Sep 2021 17:16:07 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id s24so3872872wmh.4 for ; Sat, 11 Sep 2021 17:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4o/0QoQUwLvhQ+aXkgZv1L46xFg4uGAN2KvEf5r0WLA=; b=jh5l1BBsWaoIF6moLQcrjJwqatBs7tGxSGgPmlBun9WDHXfzB+ymFeIYlDFf5FockI lY6MUvjusa+SX+mkmz9JvRBM/PV1K64FNT9qGxo2b0cxYRn9lI+nF5XEdxCcHEOE2hq7 PN6fSHC9mnmeVj4pwxuywjmz0djpi/DdZkTx1Nvk2jF/RG9rAjRDEQUMZ2uhMh1H85oA EasmSGexB+ONsr32FMo9jsS0wVe4vUTLneymqze3ZXhPxw7PYw7PAECQtNPaZXqI9tZ/ b7xvAtJpJog3l3Rt/bERjAxPgEZFFRWnuMh3vapcARQfJVFOVttKfcrWVQk4oXLO2Cz5 pwYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4o/0QoQUwLvhQ+aXkgZv1L46xFg4uGAN2KvEf5r0WLA=; b=WVU4ibTCrCdTrvHASt2FKjxyQPp6yFc2ogWKSTteqtP0b46mrGD9ipA2VzjW7nX2tj 3ZCMGIUEOz9BOrCliWPtk6IbGrWdtIbPSDJUCQf7hVnrZOfo4EQj/s292X9TqX+EpH/S XVFRhqIZfSiy180SsibyzwDpXU5VahCKh0byKPgUIvrdWED6YB3DdxhRhTW5YCfVfAbc yPIkE34ZMclemSi98yOgnQaL7AVLVeprwE6iVqR7GlJs3i24CHXqD2jC58iRGjTpiUpr blLRJL2dWtrB7K7Wddhs7tkRY023a6NzQUmTV63tno8NGg5W5OkphPaOajXUh2kFbipK z4Ow== X-Gm-Message-State: AOAM533C3Ws+ebWAFQP+l9xpH7fk4m+brroAgxbvV4cGeOa6bmR6Xnax M8hGWVZsDZT0dhCAm/mhDUImziW3Xz8Uyw== X-Google-Smtp-Source: ABdhPJwsWoTelaoilB5hrhl73sViQwflj4O7+90/UxHvWFz2YR+1oXB+brfojNhpMLdCy53MgwLQDA== X-Received: by 2002:a05:600c:4f94:: with SMTP id n20mr4448771wmq.110.1631405765999; Sat, 11 Sep 2021 17:16:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 1/7] remote-curl: pass "struct strvec *" instead of int/char ** pair Date: Sun, 12 Sep 2021 02:15:49 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We'll be changing the "int nr" in the "struct strvec" to "int size_t" soon, i.e. from signed to unsigned. It will then make sense to use the "size_t" type for things that mirror that "nr" member. This sets up that change in remote-curl.c, we'll change the "int i" here to a "size_t i" in a later commit (let's also split and "err" up to make that change smaller). In this case the push() function can just pass the "struct strvec" it has down to push_dav() and push_git(), in addition make use of strvec_pushv() in push_dav() instead of looping over the the specs ourselves. So we can get rid of much of the need for tracking the "nr", which in the case of push_dav() was already a "size_t". Signed-off-by: Ævar Arnfjörð Bjarmason --- remote-curl.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index 598cff7cde6..1f177e86f11 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1266,10 +1266,9 @@ static void parse_fetch(struct strbuf *buf) strbuf_reset(buf); } -static int push_dav(int nr_spec, const char **specs) +static int push_dav(struct strvec *specs) { struct child_process child = CHILD_PROCESS_INIT; - size_t i; child.git_cmd = 1; strvec_push(&child.args, "http-push"); @@ -1279,18 +1278,18 @@ static int push_dav(int nr_spec, const char **specs) if (options.verbosity > 1) strvec_push(&child.args, "--verbose"); strvec_push(&child.args, url.buf); - for (i = 0; i < nr_spec; i++) - strvec_push(&child.args, specs[i]); + strvec_pushv(&child.args, specs->v); if (run_command(&child)) die(_("git-http-push failed")); return 0; } -static int push_git(struct discovery *heads, int nr_spec, const char **specs) +static int push_git(struct discovery *heads, struct strvec *specs) { struct rpc_state rpc; - int i, err; + int i; + int err; struct strvec args; struct string_list_item *cas_option; struct strbuf preamble = STRBUF_INIT; @@ -1326,8 +1325,8 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) strvec_push(&args, "--force-if-includes"); strvec_push(&args, "--stdin"); - for (i = 0; i < nr_spec; i++) - packet_buf_write(&preamble, "%s\n", specs[i]); + for (i = 0; i < specs->nr; i++) + packet_buf_write(&preamble, "%s\n", specs->v[i]); packet_buf_flush(&preamble); memset(&rpc, 0, sizeof(rpc)); @@ -1342,15 +1341,15 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) return err; } -static int push(int nr_spec, const char **specs) +static int push(struct strvec *specs) { struct discovery *heads = discover_refs("git-receive-pack", 1); int ret; if (heads->proto_git) - ret = push_git(heads, nr_spec, specs); + ret = push_git(heads, specs); else - ret = push_dav(nr_spec, specs); + ret = push_dav(specs); free_discovery(heads); return ret; } @@ -1374,7 +1373,7 @@ static void parse_push(struct strbuf *buf) break; } while (1); - ret = push(specs.nr, specs.v); + ret = push(&specs); printf("\n"); fflush(stdout); From patchwork Sun Sep 12 00:15:50 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: 12486665 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 20295C433F5 for ; Sun, 12 Sep 2021 00:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0CC1610A3 for ; Sun, 12 Sep 2021 00:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234419AbhILARY (ORCPT ); Sat, 11 Sep 2021 20:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232515AbhILARW (ORCPT ); Sat, 11 Sep 2021 20:17:22 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95203C061574 for ; Sat, 11 Sep 2021 17:16:08 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id d21so786443wra.12 for ; Sat, 11 Sep 2021 17:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zkqemqG3cBjPTjtLRJ208voEVSZCzeHv7kV3xWaedt8=; b=lm7I+LmzZjZwltXJEcQGndeeSn4V3aiipht7TYDaOBu8/GH2xJUaSnYbb9KzaY7eSZ b53d6FYya4lTP9Yxdsd2wpuZ89Bb4JCel4Q7RD5mDmFnQAoxC974oMHVphOWXCQMxjJn LO3bLiOHWO21T88HZYrFg2itlgGQuXASDOZl6+PNRhMu5aCXeZOtQStY3dwuXmYT06F+ 6xSMWHk2FsdZFe+URNySsJMKknvlFPvrkvyYVT8sYZx8iH02P/o4DAvg8LL6UhldAm5+ JLqpjO72IFyFiKYJEi9XDejex+BAcKdCFxDyVFi0iYaSOrPi31dJbkWY6W5Z56VxOfvj ZRqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zkqemqG3cBjPTjtLRJ208voEVSZCzeHv7kV3xWaedt8=; b=WeUMa7V4vZJt4SMc1lyduCj/P7W9I3hhu11wIugIAOhR2M4HrSBE9JUvmLu5MmmHLs RUZVJjI5/KCBTGDAJS+Fww15hMPTfx2+QKy7yZCFj7Wq7qao7o83EklgbBTkaraH6kPS G7PCMCjhJrrb+ITXXjsYDIcznzucspAO5sOOEeS0HGgBCqzEfxHTdRSxuSXc63Ca0GcO Z21jng7HAfAQWViRG7T1mYDQmvPCx8YTSvzWk4GnTBVyRf4razIjeb+oqIBKhLK3a3wf ZY+Zas0rg/sdmP7taTZ+SYKbmw4+lo5OhyeqUe1D98NK3bchk2P9Bo9vUqXjb/5N/BhT lfRw== X-Gm-Message-State: AOAM532DwuET0AXkHS8yn53sz98qrO/LwyZMh9uoc8xABPHVPtNPSVdi 0EroVlMcYkssBvTgLnEPyMNhx4SmSxq89g== X-Google-Smtp-Source: ABdhPJzOsRY02p2uXL8Qx9wt6qZ6JCH3GzrX677tuXussL++sDBZDdfrvEElrZh77bFNVlQ7cZ0iUA== X-Received: by 2002:a5d:628e:: with SMTP id k14mr5087570wru.414.1631405766871; Sat, 11 Sep 2021 17:16:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 2/7] pack-objects: pass "struct strvec *" instead of int/char ** pair Date: Sun, 12 Sep 2021 02:15:50 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As in the preceding commit, prepare for the "nr" member of "struct strvec" changing from an "int" to a "size_t". In this case we end up passing the "nr" to setup_revisions(), which expects to take an argc/argv pair passed to main(), so we can't change its type. But we can defer the conversion until that point. Let's continue to pass the "struct strvec *" down into instead of "unwrapping" it in cases where the only source of the "int/char **" pair is a "struct strvec". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index ec8503563a6..1902c0b6776 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3701,7 +3701,7 @@ static void mark_bitmap_preferred_tips(void) } } -static void get_object_list(int ac, const char **av) +static void get_object_list(struct strvec *rp) { struct rev_info revs; struct setup_revision_opt s_r_opt = { @@ -3713,7 +3713,7 @@ 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); + setup_revisions(rp->nr, rp->v, &revs, &s_r_opt); /* make sure shallows are read */ is_repository_shallow(the_repository); @@ -4138,7 +4138,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } else if (!use_internal_rev_list) read_object_list_from_stdin(); else { - get_object_list(rp.nr, rp.v); + get_object_list(&rp); strvec_clear(&rp); } cleanup_preferred_base(); From patchwork Sun Sep 12 00:15:51 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: 12486667 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 376A3C433FE for ; Sun, 12 Sep 2021 00:16:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A0CA60E9B for ; Sun, 12 Sep 2021 00:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbhILARZ (ORCPT ); Sat, 11 Sep 2021 20:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232111AbhILARW (ORCPT ); Sat, 11 Sep 2021 20:17:22 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 365E6C061757 for ; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id m9so8496747wrb.1 for ; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZVygsSuXHuZJi9knm7pqlmkVdykROSUGvWUOAWL3Z94=; b=UDp1Ug4bIgKr1NB6HFAzZB0r0R2e2Q86IzYex21spvTSep78CRp7LeaYdxspz1FPXx vIW9/LMhFbaqOqBxgHLVf5GMRkTnMJAhrb+sGKDfXVwOJ1tnviPfWnM51t02AgpNZHQN G8/s9zyjIt6wzxu2X5MKG4wziel7Gmo4+v2SMPKQ6WyfFKjcD5WKXIoesfdDjQSgvv+h ajEnjNlXAarQof+3iEaIirFlpJqiiibzVy0dt9RS5x3nR1eLNGAEof17HhFuz2AAN0c5 QFtWjL70CgycpwxYvqxPcgxMUu/0V+SpfMgFan+3cLKSeKKrwuBfCLlTFfuk4Boe6yGG 8fVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZVygsSuXHuZJi9knm7pqlmkVdykROSUGvWUOAWL3Z94=; b=P/2RUcTb0wf+I2XO6GR7938fDKt1x2eMXIB9oQWmTh/9ZhWfYOjPKOJrHYD2MRxqZf 1lPGpmtG0ytwyxAJ37l5jObUffuvIQIyUl9RzmZ1151YoQH+9yAxxotbiDd34V6AqkCd /+tVbLnjrSM2lolUMMVxL7SCe/soP6xjFU6NiGsRN0CJholD0+8bqTEY26Knj/hjXm2k moKEtC55FXSQ+ASMDFgyPEi6lYdkTJo0bmRypjXVIhDAOJekYRWig1E4d0VEZvCwSJ8T 9x+azajUJXXmgmvocjbpIWrHUJTCUlVQYggdvG2uYUlj4IrmezCgE004748TeXP/uCeg F9nA== X-Gm-Message-State: AOAM531gksl1ksQXXCcx5LZK159kHgwZ/AOrBct2HtBAF4WraWllu3jk 2FhvHfkJ1ZPNZx0KmHHWrQN+5f5uCByP5A== X-Google-Smtp-Source: ABdhPJxFIhrk4XwVo434GXW+MZOFZc+ag9ci8JOufgWejMECdm7WXcKpc/38o05LI4EcaugmF3CAUA== X-Received: by 2002:a5d:6792:: with SMTP id v18mr5098378wru.416.1631405767615; Sat, 11 Sep 2021 17:16:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 3/7] sequencer.[ch]: pass "struct strvec *" instead of int/char ** pair Date: Sun, 12 Sep 2021 02:15:51 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As in the preceding commit, prepare for the "nr" member of "struct strvec" changing from an "int" to a "size_t". These are the same sorts of changes to pass a "struct strvec *" further down instead of passing args->nr and args->v. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 3 +-- sequencer.c | 6 +++--- sequencer.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index eb01f4d790b..27669880918 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -363,8 +363,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) oid_to_hex(&opts->restrict_revision->object.oid)); ret = sequencer_make_script(the_repository, &todo_list.buf, - make_script_args.nr, make_script_args.v, - flags); + &make_script_args, flags); if (ret) error(_("could not generate todo list")); diff --git a/sequencer.c b/sequencer.c index 68316636921..a4ba434f173 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5355,8 +5355,8 @@ static int make_script_with_merges(struct pretty_print_context *pp, return 0; } -int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, - const char **argv, unsigned flags) +int sequencer_make_script(struct repository *r, struct strbuf *out, + struct strvec *args, unsigned flags) { char *format = NULL; struct pretty_print_context pp = {0}; @@ -5390,7 +5390,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, pp.fmt = revs.commit_format; pp.output_encoding = get_log_output_encoding(); - if (setup_revisions(argc, argv, &revs, NULL) > 1) + if (setup_revisions(args->nr, args->v, &revs, NULL) > 1) return error(_("make_script: unhandled options")); if (prepare_revision_walk(&revs) < 0) diff --git a/sequencer.h b/sequencer.h index 2088344cb37..36f67164f86 100644 --- a/sequencer.h +++ b/sequencer.h @@ -158,8 +158,8 @@ int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7) #define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8) -int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, - const char **argv, unsigned flags); +int sequencer_make_script(struct repository *r, struct strbuf *out, + struct strvec *args, unsigned flags); void todo_list_add_exec_commands(struct todo_list *todo_list, struct string_list *commands); From patchwork Sun Sep 12 00:15:52 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: 12486669 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 64AB1C433EF for ; Sun, 12 Sep 2021 00:16:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 477D5610A3 for ; Sun, 12 Sep 2021 00:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234573AbhILAR0 (ORCPT ); Sat, 11 Sep 2021 20:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233452AbhILARX (ORCPT ); Sat, 11 Sep 2021 20:17:23 -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 01429C06175F for ; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so4178388wmq.1 for ; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0fD3o4xaWjuu+E2OO3NdUvZv3Ev1nVB0lJhpRcOVJS8=; b=NGpFjUj7JresrKcHAhJxxXXYoavjsN6s0deqJhYQAP8/4RmlWjgqGTAGuKbAvtp2RY FsNtScOBv3URgc3BTnohUdtV8XxsxhKT9Ze7xjryNIdd23e/RCJCV2Af9QyLJFV9SgBH UyKhxs1+q7sPeJYQZNYQGzs2B7xsilrGaEP4c8B6/b1orUk2gTUFQuZv9X2sF9jn5jJj /mFk1IN+oo38dVY/Z4tsClNHk0Jj5LyoQvq20KUrZCD0qlkKvRCCJ3P2Nq2XkO60h4Mp 6tu+CP/2PrBv7ykpSVKcdgaS9tveTSezlPoKiQ6Qfeccu3woXw0GjMYQhTg4wiYNhaS6 OolA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0fD3o4xaWjuu+E2OO3NdUvZv3Ev1nVB0lJhpRcOVJS8=; b=v8X1PZvWhk2ZBgDwELK86yQQ89kVfoWsElG6sqmDCyxSFZbUxnqUbP+3PIj3hKJZ7s Dn1jm9qirozRdvw5mS6NjMpVOZzNUwToP/xEST8k7w+ZwbdaigJwLEok63wMlUiIqj0R 0zSv5ri9Oi97aEcZ2ucxls0QvzZ8rTV7XtjlKFK6m9KBfz0izw4jun7Rr8iX/d1cUCVE 47RqnwZ0eLBtUkhoqYgUKq5CqouEG799HyK1k1Akgu1PoZ9Q85j0pNysnYQQ4bnGyiak 4wrmcXnIhjkBCnagAZG2V6uyKrThXA/lxSjkGMrAAiSsvDcpo9ubSOQCNLBBgLo6answ 0MRQ== X-Gm-Message-State: AOAM530/ciWwHOw2NhKvuVYq95UzcFZ+MOf92xPKl3JPzDpPn4LuxQVm gFXeYATbauRe3K1OpY+CY0G41/v9q30w6g== X-Google-Smtp-Source: ABdhPJyQ2K8eZ949T3c16MQChOWUQNxylai2VQwPAOYx3OTCb8xnK5QnuDSl/vkRORIR9v0czsMOwQ== X-Received: by 2002:a1c:2905:: with SMTP id p5mr4403353wmp.93.1631405768317; Sat, 11 Sep 2021 17:16:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 4/7] upload-pack.c: pass "struct strvec *" instead of int/char ** pair Date: Sun, 12 Sep 2021 02:15:52 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As in the preceding commit, prepare for the "nr" member of "struct strvec" changing from an "int" to a "size_t". These are the same sorts of changes to pass a "struct strvec *" further down instead of passing args->nr and args->v. Signed-off-by: Ævar Arnfjörð Bjarmason --- shallow.c | 5 +++-- shallow.h | 6 ++++-- upload-pack.c | 7 +++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/shallow.c b/shallow.c index 9ed18eb8849..6928db36669 100644 --- a/shallow.c +++ b/shallow.c @@ -15,6 +15,7 @@ #include "list-objects.h" #include "commit-reach.h" #include "shallow.h" +#include "strvec.h" void set_alternate_shallow_file(struct repository *r, const char *path, int override) { @@ -196,7 +197,7 @@ static void show_commit(struct commit *commit, void *data) * are marked with shallow_flag. The list of border/shallow commits * are also returned. */ -struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av, +struct commit_list *get_shallow_commits_by_rev_list(struct strvec *args, int shallow_flag, int not_shallow_flag) { @@ -215,7 +216,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av, repo_init_revisions(the_repository, &revs, NULL); save_commit_buffer = 0; - setup_revisions(ac, av, &revs, NULL); + setup_revisions(args->nr, args->v, &revs, NULL); if (prepare_revision_walk(&revs)) die("revision walk setup failed"); diff --git a/shallow.h b/shallow.h index 5b4a96dcd69..206405ec8ca 100644 --- a/shallow.h +++ b/shallow.h @@ -5,6 +5,7 @@ #include "object.h" #include "repository.h" #include "strbuf.h" +#include "strvec.h" void set_alternate_shallow_file(struct repository *r, const char *path, int override); int register_shallow(struct repository *r, const struct object_id *oid); @@ -32,8 +33,9 @@ void rollback_shallow_file(struct repository *r, struct shallow_lock *lk); struct commit_list *get_shallow_commits(struct object_array *heads, int depth, int shallow_flag, int not_shallow_flag); -struct commit_list *get_shallow_commits_by_rev_list( - int ac, const char **av, int shallow_flag, int not_shallow_flag); +struct commit_list *get_shallow_commits_by_rev_list(struct strvec *args, + int shallow_flag, + int not_shallow_flag); int write_shallow_commits(struct strbuf *out, int use_pack_protocol, const struct oid_array *extra); diff --git a/upload-pack.c b/upload-pack.c index 6ce07231d3d..5928973bcc3 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -859,13 +859,12 @@ static void deepen(struct upload_pack_data *data, int depth) } static void deepen_by_rev_list(struct upload_pack_data *data, - int ac, - const char **av) + struct strvec *args) { struct commit_list *result; disable_commit_graph(the_repository); - result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); + result = get_shallow_commits_by_rev_list(args, SHALLOW, NOT_SHALLOW); send_shallow(data, result); free_commit_list(result); send_unshallow(data); @@ -900,7 +899,7 @@ static int send_shallow_list(struct upload_pack_data *data) struct object *o = data->want_obj.objects[i].item; strvec_push(&av, oid_to_hex(&o->oid)); } - deepen_by_rev_list(data, av.nr, av.v); + deepen_by_rev_list(data, &av); strvec_clear(&av); ret = 1; } else { From patchwork Sun Sep 12 00:15:53 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: 12486671 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 7D7B9C433FE for ; Sun, 12 Sep 2021 00:16:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61CE26113E for ; Sun, 12 Sep 2021 00:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234629AbhILARa (ORCPT ); Sat, 11 Sep 2021 20:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234343AbhILARY (ORCPT ); Sat, 11 Sep 2021 20:17:24 -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 AD592C061574 for ; Sat, 11 Sep 2021 17:16:10 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso4170097wmb.2 for ; Sat, 11 Sep 2021 17:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k67VARF2MF1egGhnxXp1DcLOi1n7kd1vRAHXLBoau1Q=; b=AI/Z5THUqEiLih+q9KbqQOuL10/5YGii6AV+169OfIZvkIElQ3dkCnNETkkC8NCF/2 +TUm0rtJFgGJckDE/rTc3FNcb1dHnp1Z/km/JpBM4M1YX/H3YasV9Ltd8iX+9jUzrtqG cwLWV681CVwhIItiLiU6sAS7gHLuGZ+Fx1OnoXbIuLGLhfRB2gHa7Mjs/fMi09/7kPpP IJo+NZi6ooQoA9Aq13ToBcrv0/8irAuTxw2O/0HY7ZAyDMz4/xOYITa91smklsZyrO86 Rqt6bIQOx+zBUsbUFR9aIQzaOiSNueuNB3rYNM/bJfD+mnlKJSj8yc9KdSrnzO71EDPU sc5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k67VARF2MF1egGhnxXp1DcLOi1n7kd1vRAHXLBoau1Q=; b=n8lgEaFP5eflOkpDQdIaYYliKx2ApmBqN9+TsUg7TNR1z7qMqtqECIwes2R+d0Mnc8 Tq0+mg4VeBSOHMht+6719Yd/Cc1AEATj00yy6C5zSYJ5a4XNQNu3VNhNmtATrC6ULX5E M58ymz9CKUqk9Y7VQyA6tUcKoRmvKgD3tXHHjNFsAO8ykLb6KfEnuxDhh8zpXlNtpHeg 26D5KWtTJj+Nlp9p+md7dLhjktV5LqFrwx2hmkVjeD3aogf9NmCTCLSSpSo1bVhK2nV/ tCRDhmxFm/ua3xQZDONZvV6m4gsm5sefwcK78auala/cTgN5S6iqRYjm9iVBc2N2XVRJ NBMA== X-Gm-Message-State: AOAM533qp/kQXMBFO3GRrmDBl3xXyPBt/hNCJMxYzkYKIaxdN3JPNqlA 5b7o8+Ac0lEEZETSXpndIPa+EQ/TlRQb0w== X-Google-Smtp-Source: ABdhPJxv5gYk9zCtKtMvNUA8pDdoUvNun6jIErAxqGCsWE+nHVBPy68ZqWIjj683k9vYGWNq0u1SJw== X-Received: by 2002:a1c:f314:: with SMTP id q20mr4361299wmq.154.1631405769076; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 5/7] rebase: don't have loop over "struct strvec" depend on signed "nr" Date: Sun, 12 Sep 2021 02:15:53 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As in the preceding commit, prepare for the "nr" member of "struct strvec" changing from an "int" to a "size_t". Let's change this code added in f57696802c3 (rebase: really just passthru the `git am` options, 2018-11-14) so that it won't cause a bug if the "i" variable here is updated to be a "size_t" instead of an "int". The reason it would be buggy is because this for-loop relied on "counting down" from nr-1 to 0, we'll then decrement the variable one last time, so a value of -1 indicates that we've visited all elements. Since we're looking for a needle in the haystack having looked at all the hay means that the needle isn't there. Let's replace this with simpler code that loops overthe "struct strvec" and checks the current needle is "-q", if it isn't and we're doing a merge we die, otherwise we do a "REBASE_APPLY". We've been able to simplify this code since 8295ed690bf (rebase: make the backend configurable via config setting, 2020-02-15) when we stopped using this for anything except this one check, so let's do that and move the check into the loop itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 27669880918..dcd897fda9c 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1750,16 +1750,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.git_am_opts.nr || options.type == REBASE_APPLY) { /* all am options except -q are compatible only with --apply */ - for (i = options.git_am_opts.nr - 1; i >= 0; i--) - if (strcmp(options.git_am_opts.v[i], "-q")) - break; - - if (i >= 0) { - if (is_merge(&options)) - die(_("cannot combine apply options with " - "merge options")); - else + for (i = 0; i < options.git_am_opts.nr; i++) { + if (strcmp(options.git_am_opts.v[i], "-q")) { + if (is_merge(&options)) + die(_("cannot combine apply options with " + "merge options")); options.type = REBASE_APPLY; + break; + } } } From patchwork Sun Sep 12 00:15:54 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: 12486673 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 A61B6C433EF for ; Sun, 12 Sep 2021 00:16:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87CE76113E for ; Sun, 12 Sep 2021 00:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232515AbhILARd (ORCPT ); Sat, 11 Sep 2021 20:17:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbhILARZ (ORCPT ); Sat, 11 Sep 2021 20:17:25 -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 93C45C06175F for ; Sat, 11 Sep 2021 17:16:11 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id u15-20020a05600c19cf00b002f6445b8f55so3968489wmq.0 for ; Sat, 11 Sep 2021 17:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M8rW8iJmsCkigfQpcMTzE9IDkfyIJ2dOb7VEkRPVGmI=; b=ZHyY71G+RKa4FFwYUCuC5ztgejAHln3DGAzzuA7Jfjd5VK959dUNCxPCPUFzxA8NK9 MaOyxKmL3cxj5ulKw4P9XLKG1G3rxfrVqcDWgP6i0b/gaOPnrYNcUiytk2dNW/kwUfi9 qWokKyVXcJlezaXmUxA8g9GVrbbYfr2btVhA61hXCuuFEPADvOPvcWXiLeJbMutcqwTv 4oQ4EqSLe6dKuieqOv59yS1zc5KjD5ufoHUaCLDURgrWT9k0xNG76rJL5PP9x3prNfF8 tgdByoiOHy3RISfT3LI7Ub9Kd2ndel+5txCib5EYBTEEUcrZcKQlbmf+ISfp6F0yPpbv oc/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M8rW8iJmsCkigfQpcMTzE9IDkfyIJ2dOb7VEkRPVGmI=; b=G4D6iRgnlu+5uBNxYFZfJtf3YOmqZeRr8S51aINIwy8yX050vMtc2bmpoG4FD8jTS/ MrWH01zy0gEryegAkR+na5Pqjnxh95WzM144Po1jgdjeCzPbg9R6EhJp8AJ9ESGHuQ+t RuC8beBZTzgjXoqAoak4Rbw4EKvCDG51eYNsbSAMCsA5gbyv0KSFrIbRHqGDXsNEjYIP UfDEKHzVOy+A3jXaI7mB6L9x4WeIw7uqxf37gEqk9tvZcOGeyHzhssGF3xuYEXRfwRMs BLI7lW1xdbID7K+bCMSWPbuA/im4SgsYi9HsUiI5N06cj5B/d8lDq0DtR6nQCBPFTWuU 4Haw== X-Gm-Message-State: AOAM533V5m86YGbDsTn3OWlJmzH47zdcR9Cok/+udiHuKK+1DXnknY/H uLbp+V2OisKzcqU3aaeILC3I6F0dsKa6zA== X-Google-Smtp-Source: ABdhPJxg793Y2mTRfFcmCJEj6YR2E0+QYq6kAoCNE0ppEC+ofEE/EYR5vjHPHGHEMgPfpPvYrlwwKw== X-Received: by 2002:a05:600c:4fc8:: with SMTP id o8mr4422001wmq.106.1631405769916; Sat, 11 Sep 2021 17:16:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 6/7] strvec: use size_t to store nr and alloc Date: Sun, 12 Sep 2021 02:15:54 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King We converted argv_array (which later became strvec) to use size_t in 819f0e76b1 (argv-array: use size_t for count and alloc, 2020-07-28) in order to avoid the possibility of integer overflow. But later, commit d70a9eb611 (strvec: rename struct fields, 2020-07-28) accidentally converted these back to ints! Those two commits were part of the same patch series. I'm pretty sure what happened is that they were originally written in the opposite order and then cleaned up and re-ordered during an interactive rebase. And when resolving the inevitable conflict, I mistakenly took the "rename" patch completely, accidentally dropping the type change. We can correct it now; better late than never. Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- strvec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strvec.h b/strvec.h index fdcad75b45b..6b3cbd67589 100644 --- a/strvec.h +++ b/strvec.h @@ -29,8 +29,8 @@ extern const char *empty_strvec[]; */ struct strvec { const char **v; - int nr; - int alloc; + size_t nr; + size_t alloc; }; #define STRVEC_INIT { empty_strvec, 0, 0 } From patchwork Sun Sep 12 00:15:55 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: 12486675 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 DD9A5C433F5 for ; Sun, 12 Sep 2021 00:16:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C76666113E for ; Sun, 12 Sep 2021 00:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232111AbhILARe (ORCPT ); Sat, 11 Sep 2021 20:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234543AbhILARZ (ORCPT ); Sat, 11 Sep 2021 20:17:25 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7477DC061760 for ; Sat, 11 Sep 2021 17:16:12 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id x6so8442376wrv.13 for ; Sat, 11 Sep 2021 17:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GyJqPsdiKMDus6lT6ql8Ydda2ewa8+IzOGjDejEDM+E=; b=g1L0JbfijvMVFkoMf+uI9PVSAlStk5GzJWW7to33pZhoEQ2VIruP+TWsnldfYM7vyO +9ZebVtkPL2d50EXrzj+iM4pnLx1TWeOMsrQeAyGIYXysOsJql9ttxW1aELA3R6VXL+O i7Wq9AYpkrUkUj5U1pg8ZWHInb4WGppWLrTUJrNLFHjb/qnsfstoZySr8C1Ephd1vtiK OZwMlYdwGRzX6zkoqXu3iLrHJMN9DDfERrs7AvgoYLikQ05Ag41AG0vkhF+a0Cw52rib Wra9zRhPoWiUNRnTrz0v4MvDGjz9v9c8EHfeHbPt/wBUbz7iK8+hjkf1759NHsspEX6x Iysw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GyJqPsdiKMDus6lT6ql8Ydda2ewa8+IzOGjDejEDM+E=; b=zRJbW4KKc0Z++rsSMcWrFbU6O+hiHYYV/UTfHhOdnK8q+aM3FDFXCqPuq2m52/dPWs 8NCdCuHnclldmuC8MBduMHWX0IqR3vZWgOEboHjyftMBc+8JOzgSzgfsb9FzkCthAKVa 8gsHlaBsoJtipASkdvOOtwkG0pz31egUoajG8qtmYhupGHB+VIjMMFcHa/aPOyCFPlIr ffaJ+57Oa0RjlC987xuM6uyAoE9Wf06XgePGxeh9IzIdWeGkNVoyZnHJH1tCqN9WLLoR U2GTBdmKgAD4jpIbwZlZRPcYrVA17ZDzR5kAbGuqTiF1Q9uHdI61mLEKYlyV2g3s/7nh YDCQ== X-Gm-Message-State: AOAM531ML8VvcZeke9+rbl69l5WKfXO+4Mvta/VdavR65iB5UtI7Kn7e T4aAcv1IqY7fSHodi9eD2lUqg07LRQaZ6w== X-Google-Smtp-Source: ABdhPJx1VMRRmxueb2Il9uZFR501nyHSnFxjQDP8V39LLVpLE22Kr8Lma1YArFmDTQn2h10tOfaS2w== X-Received: by 2002:adf:d209:: with SMTP id j9mr4304226wrh.97.1631405770744; Sat, 11 Sep 2021 17:16:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p5sm3301078wrd.25.2021.09.11.17.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 17:16:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Philip Oakley , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 7/7] strvec API users: change some "int" tracking "nr" to "size_t" Date: Sun, 12 Sep 2021 02:15:55 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.998.ga4d44345d43 In-Reply-To: References: <5e5e7fd9-83d7-87f7-b1ef-1292912b6c00@iee.email> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that the strvec.h "int nr" has been changed to "size_t nr" in the preceding commit change various users of the API so that their local tracking (usually for-loop iteration) of the number of items in the array uses "size_t" as well. These were found by changing the "nr" member to a pointer temporarily, and manually looking at the codepaths that the compiler complained about. As argued in [1] these changes are not strictly necessary as a follow-up, but let's do them anyway so we don't need to wonder about the "size_t" v.s. "int" inconsistency going forward. As noted in <87v93i8svd.fsf@evledraar.gmail.com> in that thread we have various things that interact with the "int argc" passed from main() (e.g. setup_revisions()) and "struct strvec". Those things could consistently use "int" before, but will now use some mixture of "int" and "size_t". That's OK, but is the reason we're not converting all API users to use "size_t" here for their own copies of "nr", or when they pass that "nr" to other functions. 1. https://lore.kernel.org/git/YTIBnT8Ue1HZXs82@coredump.intra.peff.net/ 2. https://lore.kernel.org/git/87v93i8svd.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 7 ++++--- connect.c | 8 ++++---- fetch-pack.c | 4 ++-- ls-refs.c | 2 +- remote-curl.c | 2 +- sequencer.c | 2 +- serve.c | 2 +- submodule.c | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index dcd897fda9c..b96faaa7fea 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1424,7 +1424,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("apply all changes, even those already present upstream")), OPT_END(), }; - int i; + size_t i; + unsigned int j; if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_rebase_usage, @@ -1654,8 +1655,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } } - for (i = 0; i < exec.nr; i++) - if (check_exec_cmd(exec.items[i].string)) + for (j = 0; j < exec.nr; j++) + if (check_exec_cmd(exec.items[j].string)) exit(1); if (!(options.flags & REBASE_NO_QUIET)) diff --git a/connect.c b/connect.c index aff13a270e6..a54d4aa4d90 100644 --- a/connect.c +++ b/connect.c @@ -68,7 +68,7 @@ static NORETURN void die_initial_contact(int unexpected) /* Checks if the server supports the capability 'c' */ int server_supports_v2(const char *c, int die_on_error) { - int i; + size_t i; for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; @@ -85,7 +85,7 @@ int server_supports_v2(const char *c, int die_on_error) int server_feature_v2(const char *c, const char **v) { - int i; + size_t i; for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; @@ -101,7 +101,7 @@ int server_feature_v2(const char *c, const char **v) int server_supports_feature(const char *c, const char *feature, int die_on_error) { - int i; + size_t i; for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; @@ -479,7 +479,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, const struct string_list *server_options, int stateless_rpc) { - int i; + size_t i; const char *hash_name; struct strvec *ref_prefixes = transport_options ? &transport_options->ref_prefixes : NULL; diff --git a/fetch-pack.c b/fetch-pack.c index 0bf7ed7e477..d20f9a046f7 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -945,7 +945,7 @@ static int get_pack(struct fetch_pack_args *args, } if (index_pack_args) { - int i; + size_t i; for (i = 0; i < cmd.args.nr; i++) strvec_push(index_pack_args, cmd.args.v[i]); @@ -1674,7 +1674,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, } for (i = 0; i < packfile_uris.nr; i++) { - int j; + size_t j; struct child_process cmd = CHILD_PROCESS_INIT; char packname[GIT_MAX_HEXSZ + 1]; const char *uri = packfile_uris.items[i].string + diff --git a/ls-refs.c b/ls-refs.c index 84021416ca5..9622bc46072 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -46,7 +46,7 @@ static void ensure_config_read(void) */ static int ref_match(const struct strvec *prefixes, const char *refname) { - int i; + size_t i; if (!prefixes->nr) return 1; /* no restriction */ diff --git a/remote-curl.c b/remote-curl.c index 1f177e86f11..682643bb842 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1288,7 +1288,7 @@ static int push_dav(struct strvec *specs) static int push_git(struct discovery *heads, struct strvec *specs) { struct rpc_state rpc; - int i; + size_t i; int err; struct strvec args; struct string_list_item *cas_option; diff --git a/sequencer.c b/sequencer.c index a4ba434f173..ca3ee2e4167 100644 --- a/sequencer.c +++ b/sequencer.c @@ -919,7 +919,7 @@ static char *get_author(const char *message) static const char *author_date_from_env_array(const struct strvec *env) { - int i; + size_t i; const char *date; for (i = 0; i < env->nr; i++) diff --git a/serve.c b/serve.c index f11c0e07c45..0271bf946cc 100644 --- a/serve.c +++ b/serve.c @@ -159,7 +159,7 @@ static int is_command(const char *key, struct protocol_capability **command) int has_capability(const struct strvec *keys, const char *capability, const char **value) { - int i; + size_t i; for (i = 0; i < keys->nr; i++) { const char *out; if (skip_prefix(keys->v[i], capability, &out) && diff --git a/submodule.c b/submodule.c index 8e611fe1dbf..38ee56782c7 100644 --- a/submodule.c +++ b/submodule.c @@ -1606,7 +1606,7 @@ int fetch_populated_submodules(struct repository *r, int default_option, int quiet, int max_parallel_jobs) { - int i; + size_t i; struct submodule_parallel_fetch spf = SPF_INIT; spf.r = r;