From patchwork Fri Dec 27 10:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921669 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2CA21F130D for ; Fri, 27 Dec 2024 10:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296441; cv=none; b=OQd2gZx0DL2fw0DJ0kkymOZR6fMnncR4IMCGZwRs/2jlnb+OlBg0yndU0SVFOxU3/hI9umT7/rEeJcrm7YqtpFQRSUxp0LD4WTpcQFnnbZ5rsC7iERc0qOX0EG7urFE/aoJyT5kIqzUbsar6v2B4GCaQaVzWprgCcha7cvFsUY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296441; c=relaxed/simple; bh=EUDVjAVZVhB7sueLaL46VD3nXlV8Wdoxtj0CwK1eoqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eJfxA83By8qgO9t28cK2atpBH3Yqw7wy26ZolXAGHdN9jsNtFIWOcKVMeMY5mb/18j8HD9XV6leV2jClbk2DcUQxBOOQtCraxzFpUT54zV4z9jxEdsgOKcBai3lzob1jQiQkzH8bZC+5JmmYHuH6d7CcZOUXpEiYYTRZUtOXSS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=pYQhVV1l; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=W5gfFIwD; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="pYQhVV1l"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="W5gfFIwD" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id A380C138009C; Fri, 27 Dec 2024 05:47:18 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 27 Dec 2024 05:47:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296438; x=1735382838; bh=/e4A7vHStJBS3+u6Z7NkXFgt2MTauRhGc6L5fOlUgoQ=; b= pYQhVV1lFTaCoqSKOM/KabkX4Wvnbqm2QCQ9GuAXu8PmBvGTvGuQeseeYzNDgkzc jBh3tVOFEFGRDNrZNeZXRffG7mA7R5jnSfNVrh4HpkWwG7JL5iQWkW/zNwy81+EE S9tlyOIOEuu7XYPOVoT29R+D4zVPovtXqz/sh8Ie9rA22MKxvoRwIvJC0dN3FtGr dogQ3axHMMlok4p48NhXhZRLKDi9WrWgCbBOrXX1UCI6A3MYsi/vcIeRfCURVHon 1y1yoofNuPnyIyvju+74qK1kCuCgF6GCMD78pW/aFWsrRUTQTnJVwd/wGDmphwyp s6GDw+2aK+RRFazdVfRa9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296438; x= 1735382838; bh=/e4A7vHStJBS3+u6Z7NkXFgt2MTauRhGc6L5fOlUgoQ=; b=W 5gfFIwDLbYVETbMJWRSucE93KEepJ4AkDsiTT4FLNbSDHMkNqFOIdtKkkJjNfuNd NvtPqGeD4hn5B29QgM0/9RTb0EbmqwYEtthyK4KNZOGCEmbDvnaHEl1ydDCjRkQQ 2E9pBvpu4NHQr8tz65ZcEkqybIPtHavO0CNyCh2q03Ee/BF61lMMQUK56HkA0rBp idf/cVOA2q8eu/IO5gXCvtdfR3BAFeHoSRadEwd4K807QyEGZToMA2PrGWibB/ni WfynXz3svX1vrOk/lHyYlXo5dVedgPcCIXHSWOzK/VBNKia46KF4rk7MVTC5SfTD nupCQkei77PtJz2/WapsQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghffhesphgvfhhfrdhnvg ht X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:17 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d1ccf9c6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:12 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:21 +0100 Subject: [PATCH 1/9] prio-queue: fix type of `insertion_ctr` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-1-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 In 62e745ced2 (prio-queue: use size_t rather than int for size, 2024-12-20), we have converted `struct prio_queue` to use `size_t` to track the number of entries in the queue as well as the allocated size of the underlying array. There is one more counter though, namely the insertion counter, that is still using an `unsigned` instead of a `size_t`. This is unlikely to ever be a problem, but it makes one wonder why some indices use `size_t` while others use `unsigned`. Furthermore, the mentioned commit stated the intent to also adapt these variables, but seemingly forgot to do so. Fix the issue by converting those counters to use `size_t`, as well. Signed-off-by: Patrick Steinhardt --- prio-queue.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prio-queue.h b/prio-queue.h index 36f370625f0802cb84082fea904ad6e8a456520a..38d032636d4cf9c544811cff6c3e6a080d6c7b82 100644 --- a/prio-queue.h +++ b/prio-queue.h @@ -22,13 +22,13 @@ typedef int (*prio_queue_compare_fn)(const void *one, const void *two, void *cb_data); struct prio_queue_entry { - unsigned ctr; + size_t ctr; void *data; }; struct prio_queue { prio_queue_compare_fn compare; - unsigned insertion_ctr; + size_t insertion_ctr; void *cb_data; size_t alloc, nr; struct prio_queue_entry *array; From patchwork Fri Dec 27 10:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921670 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B2621F1312 for ; Fri, 27 Dec 2024 10:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296441; cv=none; b=jDutKM06XIzy3PozYN3YiNj+AfuR91NvC5J4MJ6ABVqsibgom2gdFFflzgvGPsfAvC8JuMMoRc+EvrdFH3htwuEEhXhkPHyTpovEz5oP5Z2mQdVL1URQTYj1djkLl8ibopx13Hbi4MENyD3f2DpQhpjbZpKJ3AAtuEphqcGH6nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296441; c=relaxed/simple; bh=pG3ygjWkFhmo5PuIIs8Oua2uMij7ZmBasJFturr/df8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nIw1uL1vcBwAytw5/4vhefbvid/MeadnR+Z2AVimGUqOsjIvfCLeJ+uLKQpvk+jcfsgi3p+m8EeQiUMzuFqjSIxL1c0xK6sscnRKIQSFvSlthrL7TD1g6FmcuG53X0HbRqrq9g6W26lCQMiSWrJPWA6NL2plxAm18JccZrnJV3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=cFR33usH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=rM6O2Efz; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="cFR33usH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rM6O2Efz" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 02E151380141; Fri, 27 Dec 2024 05:47:19 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 27 Dec 2024 05:47:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296438; x=1735382838; bh=awPmDc+rxS03qd5ZqvaQya5fYkUudIBSx8ZpHtV/AFo=; b= cFR33usHK4npEjsx7bhlyzq1e9rJLwTNzfgoo4eWrX5IGKaLipsRzMzcoiPQDVdj 1yow6tgL8bZkGqh945UI3R+2zjzKpNf5/Yv5xZvI4pdA4NYxjID0sPN6jdByyrXn 8/WGkuMPvbHarmS1XEMXTd6BDhksd3GZ+CiRl5usuPnp1fr5Hrtk5CjORBGL27xv IoItgC14u7Lw+tbS7zHFLE8X59N6iIZzjrCJ+CSZQg18PkhbKs/m1gJ0DL0VmZ2I CMXX7OmFlVcPFaDfUlAxDUfrVCpVEjizKvdSDV4XaVWda0YdWyP0y5mAbhUc+4m4 uDNOmN9cJPsvrDOIWdLwKg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296438; x= 1735382838; bh=awPmDc+rxS03qd5ZqvaQya5fYkUudIBSx8ZpHtV/AFo=; b=r M6O2EfzU7cmFJ5XSlUKBYUkkqYoXpUaWWMuSwUq0rucnCMvHzqCLSlQcn3gedI0R 3W0m9FOo0/iHqfbedAN9wBf0tnvjo7HGqsHiWGt/SM1B9di4QSmXDpHoZhwvF3Qm 1r6m/fjFrsXQzUfaG5EofQpTSKYankuwSQRh3AThr6CQ14pfTps3/HHUt/bKXUua ik/6Xt6AgZp3UfMLH5cdn+U4dbj0Lbd1DBqxqTEqWQmwLMIT8dnYD3zFvKZejjs2 sKjq6+xL3zoocQairPaHDPqibiZP7sbhq9QxULl563jTCL80hZVTGDzMMtf+kIzS x20lgF88BD2KaStAscGqQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:18 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 347534c8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:13 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:22 +0100 Subject: [PATCH 2/9] commit-reach: fix index used to loop through unsigned integer Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-2-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 In 62e745ced2 (prio-queue: use size_t rather than int for size, 2024-12-20), we refactored `struct prio_queue` to track the number of contained entries via a `size_t`. While the refactoring adapted one of the users of that variable, it forgot to also adapt "commit-reach.c" accordingly. This was missed because that file has -Wsign-conversion disabled. Fix the issue by using a `size_t` to iterate through entries. Signed-off-by: Patrick Steinhardt --- commit-reach.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index e3edd1199529792fafbaa03999c5b7b202f7cf1b..e65872617003d0e43776909c30343f091d6b42f2 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -42,8 +42,7 @@ static int compare_commits_by_gen(const void *_a, const void *_b) static int queue_has_nonstale(struct prio_queue *queue) { - int i; - for (i = 0; i < queue->nr; i++) { + for (size_t i = 0; i < queue->nr; i++) { struct commit *commit = queue->array[i].data; if (!(commit->object.flags & STALE)) return 1; From patchwork Fri Dec 27 10:46:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921671 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF4971F1318 for ; Fri, 27 Dec 2024 10:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296442; cv=none; b=Z/jW8sbLkMIcaIWMWa9dhihS0MKuPbl1EWXmygUkjledC0po/9h9b5VQOMQNgAfGacOcQNwUnsICADI+WMKZD7GLI2m+JZgCxjeKWwwBaDIT2i3gMK2EyAhUocGayC+08KdsOnfZBNv1yHO0rvWbKIdmmhW/GJ7O3/Au9C7akcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296442; c=relaxed/simple; bh=6xVxPtbtC+2Y2SHomu4gdtUQExVWPnWx6rlpLB5LxRg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M0XJTrtt4sQPogI7vC2vmZYDm2vR3zAbCyuYnnQbp5w0t2IBAXhbmGAPgRTq2r8wtRWT04lbEFI0FSS7ZZ7XVqb3oaOXFmkSIMoC4QFl39I640+1zZedyXuX26P6IUe0xHc4vEejHJku+R07zYVHAkdpSDQyh7M+U8PvkQbQgsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=YtmmEhUh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=yWg7F2n+; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="YtmmEhUh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="yWg7F2n+" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id A31AE138017E; Fri, 27 Dec 2024 05:47:19 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 27 Dec 2024 05:47:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296439; x=1735382839; bh=/5KdHv+h8Ku/y6CIc5v5ba7jNIK+0Vg5OI6fTAVMoXQ=; b= YtmmEhUhL3Yk7Z2XRJqUieTGEYYDZQXxr4pVKE7a32aw5GCJwadDICJ2jqsfKoBh EwmvafGDETg87NqG3+wJzeWu4uG2XGeS1YFacx0MOAOraGQkjEUy0ngWA33ncPmt kCSklMny/66tJsAke5oFyT8cNEPdBNJcBY/ydHl11jiWJ1Al2keCnHC7XxXaLcOQ 3TIIWgi3Gk3Rl/cfYSxHfukkI50MOplfEpoIoXdNcWs8qiXocXJPZW2nhAoP+w08 TduZU0jMkZ+uIUc9/jA4UOfR7wvYT5AvyZZh+L62P0UocohjxQqJvXsml6wRPmXT DRi1/eZKt1MidDXfo+yJnA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296439; x= 1735382839; bh=/5KdHv+h8Ku/y6CIc5v5ba7jNIK+0Vg5OI6fTAVMoXQ=; b=y Wg7F2n+xpdqgxfLgI5UmjRjJpEyQg3e0S0Q1ukK0yxQb7o9DmoHc7O3TVynzREvT nc2ChhLPv0VI7AqoZotjZ3djil4IgCzCMIohwH7mw8VM6MX5HCbcEKmUZrcujRF5 9D7vzz1jNIGMqP1AG5UXM6oZ5kKWgtrgnfRd8aOL4i1qjIEa67KF0wSeBz5p17zp +4jGsddVSGuZM+sIN7h9hod7xS0gtpMQ/GG3hBZEKqBE8sTXjPMyYK83T0nE7fi5 Xt6kkDgJ0JxuFIOXp9Q5GsQua79VsXeRVGkFCc4yabT6wCPlk4QjxrVnEnkrJImk i0nHEa9I9KjSyvagI/tgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:18 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 64bb6045 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:14 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:23 +0100 Subject: [PATCH 3/9] commit-reach: fix type of `min_commit_date` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-3-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 The `can_all_from_reach_with_flag()` function accepts a parameter that allows callers to cut off traversal at a specified commit date. This parameter is of type `time_t`, which is a signed type, while we end up comparing it to a commit's `date` field, which is of the unsigned type `timestamp_t`. Fix the parameter to be of type `timestamp_t`. There is only a single caller in "upload-pack.c" that sets this parameter, and that caller knows to pass in a `timestamp_t` already. Signed-off-by: Patrick Steinhardt --- commit-reach.c | 4 ++-- commit-reach.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index e65872617003d0e43776909c30343f091d6b42f2..9f8b2457bcc12bebf725a5276d1aec467bb7af05 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -780,7 +780,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit, int can_all_from_reach_with_flag(struct object_array *from, unsigned int with_flag, unsigned int assign_flag, - time_t min_commit_date, + timestamp_t min_commit_date, timestamp_t min_generation) { struct commit **list = NULL; @@ -883,9 +883,9 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, int cutoff_by_min_date) { struct object_array from_objs = OBJECT_ARRAY_INIT; - time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0; struct commit_list *from_iter = from, *to_iter = to; int result; + timestamp_t min_commit_date = cutoff_by_min_date ? from->item->date : 0; timestamp_t min_generation = GENERATION_NUMBER_INFINITY; while (from_iter) { diff --git a/commit-reach.h b/commit-reach.h index 9a745b7e1766850a77fbe52c3eeae290b68038d0..d5f3347376b6310727c74b81cb7660485b96c0bc 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -81,7 +81,7 @@ int commit_contains(struct ref_filter *filter, struct commit *commit, int can_all_from_reach_with_flag(struct object_array *from, unsigned int with_flag, unsigned int assign_flag, - time_t min_commit_date, + timestamp_t min_commit_date, timestamp_t min_generation); int can_all_from_reach(struct commit_list *from, struct commit_list *to, int commit_date_cutoff); From patchwork Fri Dec 27 10:46:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921672 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB20B1F131B for ; Fri, 27 Dec 2024 10:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296442; cv=none; b=ipV3LKAoAPClRgkQ751Y99AV1FRJXEf2AMVCpN/vSzV272+1zaloS7j5snZKwtSf0G05RC3cF6V9GGPa6VCXjrIMtAHswe0OGgiJm7812a548aN7VCDRLsGEaFRNKJXFiTZdsT/TOdvpeEp86/ZeHa0s2neVACHJFRfmg+tzAQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296442; c=relaxed/simple; bh=sWWvdFX8+G0JZdD6Y1RBbEuLWUrVe5mkzJZKo/VtHDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DS3Zqr5fh0hANmArFwUA5CKRaElvNNVTP5o4cSN0yk0ogLRdaA/7FSBFBuUnsW2N9gOaomfHckV3pxREtDdeSQrLBaLnHQAurntu81I+zowY3ytdBn1oieUtlDB/xy1hjEeuCNL939AxTruCRx0lySLdkidNr4V7niyY+7eJLNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=iLmus2H3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ey8neuZP; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="iLmus2H3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ey8neuZP" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id F18BA11400C9; Fri, 27 Dec 2024 05:47:19 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 27 Dec 2024 05:47:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296439; x=1735382839; bh=zVGUr6/t6ZAEB/umwIvhBQhcLRmlUt7JQVHGCn4Iqw0=; b= iLmus2H3rL2CS8LhfNnlHJFkEMTHVm+CqiLnZjAqJWLndLeQp5vt5U7NADQalvea m8F1NC1JaaJm4SBBaPq9KdTscjMtqbKyzRlXt0G4rxvAJ0u59ZZhBpYcXnI5au+2 5Qy97YJNDwjFciLL4+Mly6aXoG8G8garfZc38ojTpo9j7EQ/qVUyH/bfVQfLOKvo 1x5PgU8ErFBjXOQwc4NL2z+pAqFl80KQQBNDu/h+DVD29FDQL7iSIxxpaqgt5ePg h6wFADoUi61Y6SmkGipZ5Vq1t9hbQr/UOtVLl4B/gFPCIGVZ/HArg09+FrmCbZUb 63tjh8UvfSsuelzaoPOkog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296439; x= 1735382839; bh=zVGUr6/t6ZAEB/umwIvhBQhcLRmlUt7JQVHGCn4Iqw0=; b=e y8neuZPq5Kiv2MKijgK2sBXWiv+4Aikocguc3nktDmQlDLU0O8j2nXZ2DBm+vmLl sQb/2rhlwQUR3JL0RxOp48zTx4grWmhpPBYCOxQp4zbXM7jQXmfRrZNUCwX3p8ng GOsmup0gYuLqtfl0Fhwm0jGev1dn3KWCaJWAiRMkFXYGtcTLoOi1Crf7hLAOIE35 0bn9l52cWploCpSVUocY+Zsfp0DAflToG+Euh+uuRTyTQ8TfFxoAjeZxL9JaUN+n 7nAC2QKto1azpkAXIohKIxp7NCrVUAS9MgjIC2MULCzGGArwaTBsyFRLWqUUUoob eRCdgiNzxAZXYCGhw57qQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghffhesphgvfhhfrdhnvg ht X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:19 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6e97b52c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:15 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:24 +0100 Subject: [PATCH 4/9] commit-reach: use `size_t` to track indices in `remove_redundant()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-4-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 The function `remove_redundant()` gets as input an array of commits as well as the size of that array and then drops redundant commits from that array. It then returns either `-1` in case an error occurred, or the new number of items in the array. The function receives and returns these sizes with a signed integer, which causes several warnings with -Wsign-compare. Fix this issue by consistently using `size_t` to track array indices and splitting up the returned value into a returned error code and a separate out pointer for the new computed size. Note that `get_merge_bases_many()` and related functions still track array sizes as a signed integer. This will be fixed in a subsequent commit. Signed-off-by: Patrick Steinhardt --- commit-reach.c | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 9f8b2457bcc12bebf725a5276d1aec467bb7af05..d7f6f1be75e95cc834d60be719e930a77ad0518f 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -212,12 +212,13 @@ int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result) } static int remove_redundant_no_gen(struct repository *r, - struct commit **array, int cnt) + struct commit **array, + size_t cnt, size_t *dedup_cnt) { struct commit **work; unsigned char *redundant; - int *filled_index; - int i, j, filled; + size_t *filled_index; + size_t i, j, filled; CALLOC_ARRAY(work, cnt); redundant = xcalloc(cnt, 1); @@ -267,20 +268,22 @@ static int remove_redundant_no_gen(struct repository *r, for (i = filled = 0; i < cnt; i++) if (!redundant[i]) array[filled++] = work[i]; + *dedup_cnt = filled; free(work); free(redundant); free(filled_index); - return filled; + return 0; } static int remove_redundant_with_gen(struct repository *r, - struct commit **array, int cnt) + struct commit **array, size_t cnt, + size_t *dedup_cnt) { - int i, count_non_stale = 0, count_still_independent = cnt; + size_t i, count_non_stale = 0, count_still_independent = cnt; timestamp_t min_generation = GENERATION_NUMBER_INFINITY; struct commit **walk_start, **sorted; size_t walk_start_nr = 0, walk_start_alloc = cnt; - int min_gen_pos = 0; + size_t min_gen_pos = 0; /* * Sort the input by generation number, ascending. This allows @@ -326,12 +329,12 @@ static int remove_redundant_with_gen(struct repository *r, * terminate early. Otherwise, we will do the same amount of work * as before. */ - for (i = walk_start_nr - 1; i >= 0 && count_still_independent > 1; i--) { + for (i = walk_start_nr; i && count_still_independent > 1; i--) { /* push the STALE bits up to min generation */ struct commit_list *stack = NULL; - commit_list_insert(walk_start[i], &stack); - walk_start[i]->object.flags |= STALE; + commit_list_insert(walk_start[i - 1], &stack); + walk_start[i - 1]->object.flags |= STALE; while (stack) { struct commit_list *parents; @@ -388,10 +391,12 @@ static int remove_redundant_with_gen(struct repository *r, clear_commit_marks_many(walk_start_nr, walk_start, STALE); free(walk_start); - return count_non_stale; + *dedup_cnt = count_non_stale; + return 0; } -static int remove_redundant(struct repository *r, struct commit **array, int cnt) +static int remove_redundant(struct repository *r, struct commit **array, + size_t cnt, size_t *dedup_cnt) { /* * Some commit in the array may be an ancestor of @@ -401,19 +406,17 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt * that number. */ if (generation_numbers_enabled(r)) { - int i; - /* * If we have a single commit with finite generation * number, then the _with_gen algorithm is preferred. */ - for (i = 0; i < cnt; i++) { + for (size_t i = 0; i < cnt; i++) { if (commit_graph_generation(array[i]) < GENERATION_NUMBER_INFINITY) - return remove_redundant_with_gen(r, array, cnt); + return remove_redundant_with_gen(r, array, cnt, dedup_cnt); } } - return remove_redundant_no_gen(r, array, cnt); + return remove_redundant_no_gen(r, array, cnt, dedup_cnt); } static int get_merge_bases_many_0(struct repository *r, @@ -425,7 +428,8 @@ static int get_merge_bases_many_0(struct repository *r, { struct commit_list *list; struct commit **rslt; - int cnt, i; + size_t cnt, i; + int ret; if (merge_bases_many(r, one, n, twos, result) < 0) return -1; @@ -452,8 +456,8 @@ static int get_merge_bases_many_0(struct repository *r, clear_commit_marks(one, all_flags); clear_commit_marks_many(n, twos, all_flags); - cnt = remove_redundant(r, rslt, cnt); - if (cnt < 0) { + ret = remove_redundant(r, rslt, cnt, &cnt); + if (ret < 0) { free(rslt); return -1; } @@ -582,7 +586,8 @@ struct commit_list *reduce_heads(struct commit_list *heads) struct commit_list *p; struct commit_list *result = NULL, **tail = &result; struct commit **array; - int num_head, i; + size_t num_head, i; + int ret; if (!heads) return NULL; @@ -603,11 +608,13 @@ struct commit_list *reduce_heads(struct commit_list *heads) p->item->object.flags &= ~STALE; } } - num_head = remove_redundant(the_repository, array, num_head); - if (num_head < 0) { + + ret = remove_redundant(the_repository, array, num_head, &num_head); + if (ret < 0) { free(array); return NULL; } + for (i = 0; i < num_head; i++) tail = &commit_list_insert(array[i], tail)->next; free(array); From patchwork Fri Dec 27 10:46:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921673 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B7191F12F8 for ; Fri, 27 Dec 2024 10:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296443; cv=none; b=Vjvhj4FCYL1YBHceWVsNnSA936JRuvVEArUZ9iuq46T0/Uzk+bDynuyjZggmbCgxRznEfrs4cKMzgL5tYDOtF/OQjZ/Wpt8Rr4oByHTBqXM6hUiN32Y7Qu2a43DLbUYZuR0pbUkoOHuvEEnFCxs4BMEFz/wJ2jP3DzpQjUdGw4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296443; c=relaxed/simple; bh=HLHynNfCCOyl7r7y8m+vUGF0F/shQyUSdzjyDMCEhRU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uvj1ENBQkhaiiRB83zvBRH3f8Csir057MfAxvizh6zvteIyEiAozcDLxEHZIz+DU1jIZbCvtzYMXS88NITtFcO2fZD3PApBjGdafuZiLc726RhIZpE/lILdbd/OuZXdaUSlMkJRn41fD0A3JoFNzm+V32nqX7nzHw2cGYzzF7XM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=dkDKSc8a; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=wGECxv/L; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="dkDKSc8a"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wGECxv/L" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A67111400D8; Fri, 27 Dec 2024 05:47:20 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 27 Dec 2024 05:47:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296440; x=1735382840; bh=5S6Vh/GlSTPlon10saubYRL0hUbdtAsBrSh9OPH4RY0=; b= dkDKSc8ahSMQYsvGsZ9M2+osADTcrEeEodvpSS9Gqfn5Dftb3nQm6l1aBUc7NBqf dqatVu9KXxubdEub56Gtzr/eiiNXTPcD4nAx0ux090NE1nv0O6b7YLHBn/2XqISA cyhwuiYc7VJ+LEMSRF/Q4pYJL5rZaV8vW1lw0n1ojd03xKXdLv6GvpGiTdcKA0f2 ONDzQbXGB+4v89ZHmgJZ0FzeFq9aQxtjCQPpF97orIGUOEUM6Wns4/unf4KpJiiM 4iTkaX12nEWlpG2ygMs9zFNq0I5ZrAmqa9K7Y7dlD5nH+AxOpqnvoAYGbN32WEXx iC5U5Z9K7En2drf97ggaUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296440; x= 1735382840; bh=5S6Vh/GlSTPlon10saubYRL0hUbdtAsBrSh9OPH4RY0=; b=w GECxv/LOOaaqoBJX9hG5D9LhFNX13WzevSZMCRJdHgJFHf49MjD8toiWuwAAejVS tm0ZmDYj2HhPFCFmxh4hQYm83hnixiJX4pbUa9C67IHCkzP7LGrr1CtUKG+ZmQKj S9z3BdvRZXn86ScmavfDm9KkPU2Vi3DhmOtq/Moqh/4Z5CiI3ZcS1309pUNX10j6 TrykaZr+4cuJrWTeIGwX9OtlDKImpyxnqAGONMk7OWNbJtOzLKMfq6UZwkud9zNH 5R7lVyC+dbcAESn8cWmvHJDvQzBUz2ssSl9F2u5/ytjGbZA1h8CVoo0fWZvoB+lR MdduoExBWY3xW9rU8UZeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:19 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 153ea489 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:16 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:25 +0100 Subject: [PATCH 5/9] commit-reach: use `size_t` to track indices in `get_reachable_subset()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-5-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 Similar as with the preceding commit, adapt `get_reachable_subset()` so that it tracks array indices via `size_t` instead of using signed integers to fix a couple of -Wsign-compare warnings. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt --- bisect.c | 9 +++++---- commit-reach.c | 8 ++++---- commit-reach.h | 4 ++-- commit.c | 4 ++-- commit.h | 2 +- ref-filter.c | 2 +- remote.c | 4 ++-- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bisect.c b/bisect.c index 1a9069c9ad8a19d6e0ee45415407c70f36885514..7a1afc46e5fc0250212f5b6eaf952cf8e36b56fe 100644 --- a/bisect.c +++ b/bisect.c @@ -780,10 +780,10 @@ static struct commit *get_commit_reference(struct repository *r, } static struct commit **get_bad_and_good_commits(struct repository *r, - int *rev_nr) + size_t *rev_nr) { struct commit **rev; - int i, n = 0; + size_t i, n = 0; ALLOC_ARRAY(rev, 1 + good_revs.nr); rev[n++] = get_commit_reference(r, current_bad_oid); @@ -887,7 +887,7 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int return res; } -static int check_ancestors(struct repository *r, int rev_nr, +static int check_ancestors(struct repository *r, size_t rev_nr, struct commit **rev, const char *prefix) { struct strvec rev_argv = STRVEC_INIT; @@ -922,7 +922,8 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r, { char *filename; struct stat st; - int fd, rev_nr; + int fd; + size_t rev_nr; enum bisect_error res = BISECT_OK; struct commit **rev; diff --git a/commit-reach.c b/commit-reach.c index d7f6f1be75e95cc834d60be719e930a77ad0518f..bab40f557580476d59d3a0b0ef56f40263e6615e 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -791,8 +791,8 @@ int can_all_from_reach_with_flag(struct object_array *from, timestamp_t min_generation) { struct commit **list = NULL; - int i; - int nr_commits; + size_t i; + size_t nr_commits; int result = 1; ALLOC_ARRAY(list, from->nr); @@ -944,8 +944,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, return result; } -struct commit_list *get_reachable_subset(struct commit **from, int nr_from, - struct commit **to, int nr_to, +struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from, + struct commit **to, size_t nr_to, unsigned int reachable_flag) { struct commit **item; diff --git a/commit-reach.h b/commit-reach.h index d5f3347376b6310727c74b81cb7660485b96c0bc..fa5408054ac01372c041d18595a405cfdaec6af3 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -95,8 +95,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to, * This method uses the PARENT1 and PARENT2 flags during its operation, * so be sure these flags are not set before calling the method. */ -struct commit_list *get_reachable_subset(struct commit **from, int nr_from, - struct commit **to, int nr_to, +struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from, + struct commit **to, size_t nr_to, unsigned int reachable_flag); struct ahead_behind_count { diff --git a/commit.c b/commit.c index a127fe60c5e83c3968fc0538f0e801e4afd52acd..540660359d4190f7dbc1aaa7668b033a6d16afe9 100644 --- a/commit.c +++ b/commit.c @@ -778,11 +778,11 @@ static void clear_commit_marks_1(struct commit_list **plist, } } -void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark) +void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark) { struct commit_list *list = NULL; - while (nr--) { + for (size_t i = 0; i < nr; i++) { clear_commit_marks_1(&list, *commit, mark); commit++; } diff --git a/commit.h b/commit.h index 943e3d74b2ae026d77e3bac59a4e993314e79ce4..70c870dae4d4b972a1f608983fc17024ad04d2e9 100644 --- a/commit.h +++ b/commit.h @@ -210,7 +210,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list, struct commit *pop_commit(struct commit_list **stack); void clear_commit_marks(struct commit *commit, unsigned int mark); -void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark); +void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark); enum rev_sort_order { diff --git a/ref-filter.c b/ref-filter.c index 23054694c2c96014ef411a225c6c941eb8d2d56c..bf5534605e234d7cdd01d52f5c83f5314745e13d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -3041,7 +3041,7 @@ static void reach_filter(struct ref_array *array, struct commit_list **check_reachable, int include_reached) { - int i, old_nr; + size_t i, old_nr; struct commit **to_clear; if (!*check_reachable) diff --git a/remote.c b/remote.c index 18e5ccf391844516e2fcc54fc0d6835283ff6a48..0f6fba85625b523122e50e28a0f64b6e143cd9fb 100644 --- a/remote.c +++ b/remote.c @@ -1535,7 +1535,7 @@ static struct ref **tail_ref(struct ref **head) struct tips { struct commit **tip; - int nr, alloc; + size_t nr, alloc; }; static void add_to_tips(struct tips *tips, const struct object_id *oid) @@ -1602,7 +1602,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds const int reachable_flag = 1; struct commit_list *found_commits; struct commit **src_commits; - int nr_src_commits = 0, alloc_src_commits = 16; + size_t nr_src_commits = 0, alloc_src_commits = 16; ALLOC_ARRAY(src_commits, alloc_src_commits); for_each_string_list_item(item, &src_tag) { From patchwork Fri Dec 27 10:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921674 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E09541F1928 for ; Fri, 27 Dec 2024 10:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296443; cv=none; b=o5rVvM3Xn8da6m+uslQrpqLCle996p3GMS77MN0sreOYjBFA0hleDmXBcezQil9UJSpxf5XgPp09mjOwzvNkAnVkNIR0czm+MJ2W+RhjnTWWZjC1zbuHn+MxWac7sD0hEkPlpNM+QFAFaVdhxsQUK+s6gqOCHUZ2+zsCWOUOQdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296443; c=relaxed/simple; bh=+l99LwHFc1MYAwaTp9Zp/LN5Lpan4f2C3lnuf4wpsLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IValCClKrB1GzZRk/XamXFfQONs/OQRPX+1iDPwwbEaAFnShfPoWpZlUZeejvFYRW9bNwJLb833O2fd4WIS/SxUSwPrNUxny6hTxyt4e6jlfMbll3yg3VRr29ZDGjbUzsaajCbY9vq9J+toWeOp2nzYTFLsOLgDBsHe8E/j6dk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=vRlHeb2r; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cTntg20o; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="vRlHeb2r"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cTntg20o" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id EBA7D11400D9; Fri, 27 Dec 2024 05:47:20 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Fri, 27 Dec 2024 05:47:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296440; x=1735382840; bh=peLPTGtCri9lUYt7wnA+2OC/t2Ppy6husePTPzRP1qU=; b= vRlHeb2r4uDe5TJLuIx/M9H86JzzXxU3jCxrTl0702uBTVkINyv0Sxl66IAeg0gP GculsGecV7O73FbIKjoCPOPTeaWhBQMQ8gnwhU4AzRev3ARSLhkM6XOZNXOC/4iO P30359/WbnKiYk1sexnIoVkQyCp23myeNsXdmAXw3D4DaJ8rtsgMhgAqn7piq7Qi L6BGsL746oUslmlrweBFQldJfdE26akp8VNSxPaF/RO9A/qmwwDacYvc8cAfGUDz g8oO0a86EFEX14m/Jvw8qnBbj6RbARFwcTb+6QufvUysKl7MBSxldxi62Mya0pgd e2vDwsJmlaDwqcR802uBkw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296440; x= 1735382840; bh=peLPTGtCri9lUYt7wnA+2OC/t2Ppy6husePTPzRP1qU=; b=c Tntg20opYy6HGcAMAMQttpLNpQnvcY5pDl7G5+HLfEsSWwGm6COKurV/3v8bI+15 UhxQHhFzxBgCCwAlJiq5eKJ5/ONCU7rR1QGwgjR8DunnripeTPp7MTdyKt3fqWW6 9STHT5dwbSzEtq96tqtSv+xHi8Jb1ADmcPOimX9/CzIhM6d89TXm74seqdQSoKrq VNmVjDD2WLOzPZl2t+vazdghyGKJL2an7IhwmVHhjXgOBcNBTRctHKebDTIKgVZ1 omSU4d2YZCyFJb61Ui1KAQxdVS1TcQbn8VSdy/pFJS7/Cz9wh0uulnkxWPSXR2P+ dQ1+mU9r2JsZXbrFXAlBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:20 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0b36e5c6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:17 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:26 +0100 Subject: [PATCH 6/9] builtin/log: use `size_t` to track indices Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-6-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 Similar as with the preceding commit, adapt "builtin/log.c" so that it tracks array indices via `size_t` instead of using signed integers. This fixes a couple of -Wsign-compare warnings and prepares the code for a similar refactoring of `repo_get_merge_bases_many()` in a subsequent commit. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 75e1b34123b348f57334d5592879398064de246e..805b2355d964915732edf5928d54fb6d06e394d4 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1746,11 +1746,12 @@ struct base_tree_info { static struct commit *get_base_commit(const struct format_config *cfg, struct commit **list, - int total) + size_t total) { struct commit *base = NULL; struct commit **rev; - int i = 0, rev_nr = 0, auto_select, die_on_failure, ret; + int auto_select, die_on_failure, ret; + size_t i = 0, rev_nr = 0; switch (cfg->auto_base) { case AUTO_BASE_NEVER: @@ -1885,13 +1886,12 @@ define_commit_slab(commit_base, int); static void prepare_bases(struct base_tree_info *bases, struct commit *base, struct commit **list, - int total) + size_t total) { struct commit *commit; struct rev_info revs; struct diff_options diffopt; struct commit_base commit_base; - int i; if (!base) return; @@ -1906,7 +1906,7 @@ static void prepare_bases(struct base_tree_info *bases, repo_init_revisions(the_repository, &revs, NULL); revs.max_parents = 1; revs.topo_order = 1; - for (i = 0; i < total; i++) { + for (size_t i = 0; i < total; i++) { list[i]->object.flags &= ~UNINTERESTING; add_pending_object(&revs, &list[i]->object, "rev_list"); *commit_base_at(&commit_base, list[i]) = 1; @@ -2007,7 +2007,7 @@ int cmd_format_patch(int argc, struct rev_info rev; char *to_free = NULL; struct setup_revision_opt s_r_opt; - int nr = 0, total, i; + size_t nr = 0, total, i; int use_stdout = 0; int start_number = -1; int just_numbers = 0; @@ -2500,11 +2500,14 @@ int cmd_format_patch(int argc, if (show_progress) progress = start_delayed_progress(_("Generating patches"), total); - while (0 <= --nr) { + for (i = 0; i < nr; i++) { + size_t idx = nr - i - 1; int shown; - display_progress(progress, total - nr); - commit = list[nr]; - rev.nr = total - nr + (start_number - 1); + + display_progress(progress, total - idx); + commit = list[idx]; + rev.nr = total - idx + (start_number - 1); + /* Make the second and subsequent mails replies to the first */ if (cfg.thread) { /* Have we already had a message ID? */ From patchwork Fri Dec 27 10:46:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921675 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C6EE1F2373 for ; Fri, 27 Dec 2024 10:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296444; cv=none; b=J0p+k6Ky223h+EVwZGasiiKrHaq2F6kZVWRs0n87SMV98W7qF4xXmVk/ht2GKHC9NI5aayGLo5N3n5Mx4reCD+GaWaIbPwAeBEHBrF36+AvRXOBiL9PHf8+Mq8VPQ3hpuii1up6hph2HwYwqcJmyKHQqw6Y9Xyjt9VcG7XhwYbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296444; c=relaxed/simple; bh=k3O4KP1LZ2WQgWEnVxU7CVhX/pooq+KmWp7vQc3s52U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IutKqcm5Hao6cjaAdZG4nQPAqxh2AN3qvKsOn0OJo2oY0CadpOM+O4yQOjnubAnDZHVIQFigMXB9M0VrqvLPAGIiWHYt5Pkc39c+i3VBi/mI+ydiMC6E98HcspyXCHnR6nBaNEZiiZhFKC2dGnILemhZnmKccaWeK/myGvlGRsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=bcm1hdvF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uIDod3fZ; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="bcm1hdvF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uIDod3fZ" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id DC15513801C5; Fri, 27 Dec 2024 05:47:21 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 27 Dec 2024 05:47:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296441; x=1735382841; bh=bzfII0eNrJq61Ponqi2eLztRVNnjc0dGan5XAEiw3UI=; b= bcm1hdvFAMmE/hw2YoYuzOZMYunObn+/Pgls+9WKHDivqbULJno0gk6yOvBK1Rs5 9pezYHR1fJhG/0XLFWdk7HDrDCdcUylBrlH5zOtzVczIECybWpAhTeMUj4/Ia+5i 6ElyrlOOJxDjhHh+uLaWK9r+Eh6Nj6en78HrivxG2bzKWGc+FXwhg/HUA0bQmk1o dYK2K+1th9dFx1u6duzwf1ECTprchawGL4Zm2XC/Ia6mQw6cd01Iz7nZ2qAT3kCz LPQCguDKaxFd4hoP16zz9439u/ADokXKb09HbKxIxW4JL+tz5MyKyCmxYqs3OLUq 7Z+lFNoHrqDlDmL5EwBZ0w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296441; x= 1735382841; bh=bzfII0eNrJq61Ponqi2eLztRVNnjc0dGan5XAEiw3UI=; b=u IDod3fZZl4bXzWQ9wbOrLkmo3fBakFhX/GEbAL+1vVICBJWcKYkVC5D/4pNWIARb xPwLnvGPTT96/u1xizb65eZFTaCCCuaLkS9FmYlvkC/HrBdGtqkRF/DdlIw8DH9I 1FPJj2faFqthb051fbXd9gQGVrPbncK59bAeXGhudYxW+XhVv9gdQecdEZTxLOhe xbF1HRLsmYrcgSjuFIPuyQ/DJq5FwawSwb9ILFM4xmQnbcmFE/84N2b95qyR50y1 IHXxNKcP6fvDkYSTmCgEYR5ML3x3rt5EHH4NpIacScBbNWbI/1IFT7qUHQI9N6pV HI6FWqlsG91yc2yuEn1hA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghffhesphgvfhhfrdhnvg ht X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:21 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7d2a8354 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:17 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:27 +0100 Subject: [PATCH 7/9] builtin/log: fix remaining -Wsign-compare warnings Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-7-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 Fix remaining -Wsign-compare warnings in "builtin/log.c" and mark the file as -Wsign-compare-clean. While most of the fixes are obvious, one fix requires us to use `cast_size_t_to_int()`, which will cause us to die in case the `size_t` cannot be represented as `int`. This should be fine though, as the data would typically be set either via a config key or via the command line, neither of which should ever exceed a couple of kilobytes of data. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 805b2355d964915732edf5928d54fb6d06e394d4..a4f41aafcae069541ee987dc94d245edfe9787a8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -6,7 +6,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "abspath.h" @@ -209,7 +208,6 @@ static void cmd_log_init_defaults(struct rev_info *rev, static void set_default_decoration_filter(struct decoration_filter *decoration_filter) { - int i; char *value = NULL; struct string_list *include = decoration_filter->include_ref_pattern; const struct string_list *config_exclude; @@ -243,7 +241,7 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f * No command-line or config options were given, so * populate with sensible defaults. */ - for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) { + for (size_t i = 0; i < ARRAY_SIZE(ref_namespace); i++) { if (!ref_namespace[i].decoration) continue; @@ -717,14 +715,14 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) unsigned long size; enum object_type type; char *buf = repo_read_object_file(the_repository, oid, &type, &size); - int offset = 0; + unsigned long offset = 0; if (!buf) return error(_("could not read object %s"), oid_to_hex(oid)); assert(type == OBJ_TAG); while (offset < size && buf[offset] != '\n') { - int new_offset = offset + 1; + unsigned long new_offset = offset + 1; const char *ident; while (new_offset < size && buf[new_offset++] != '\n') ; /* do nothing */ @@ -1316,24 +1314,25 @@ static void print_signature(const char *signature, FILE *file) static char *find_branch_name(struct rev_info *rev) { - int i, positive = -1; struct object_id branch_oid; const struct object_id *tip_oid; const char *ref, *v; char *full_ref, *branch = NULL; + int interesting_found = 0; + size_t idx; - for (i = 0; i < rev->cmdline.nr; i++) { + for (size_t i = 0; i < rev->cmdline.nr; i++) { if (rev->cmdline.rev[i].flags & UNINTERESTING) continue; - if (positive < 0) - positive = i; - else + if (interesting_found) return NULL; + interesting_found = 1; + idx = i; } - if (positive < 0) + if (!interesting_found) return NULL; - ref = rev->cmdline.rev[positive].name; - tip_oid = &rev->cmdline.rev[positive].item->oid; + ref = rev->cmdline.rev[idx].name; + tip_oid = &rev->cmdline.rev[idx].item->oid; if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid, &full_ref, 0) && skip_prefix(full_ref, "refs/heads/", &v) && @@ -2183,7 +2182,7 @@ int cmd_format_patch(int argc, fmt_patch_suffix = cfg.fmt_patch_suffix; /* Make sure "0000-$sub.patch" gives non-negative length for $sub */ - if (cfg.log.fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix)) + if (cfg.log.fmt_patch_name_max <= cast_size_t_to_int(strlen("0000-") + strlen(fmt_patch_suffix))) cfg.log.fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix); if (cover_from_description_arg) From patchwork Fri Dec 27 10:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921676 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B10C11F2C24 for ; Fri, 27 Dec 2024 10:47:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296445; cv=none; b=mGLeO9F/S9EcivEZ7MyJfyYnmPfMJLLLfCo1LTDLukk9gVi+EayNq18X6THPo+alfu2uh4aAZYoyJHq9ALbJfwu5jU8w7z/SzkDE+w5lKaRLrL96doj+qbC5aszPPKSGZd8hFr3VnmrHtRNxDLbtvro04S87UpmDOznE2YudK8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296445; c=relaxed/simple; bh=vNp+4MRurfxhK7YAcvt2f8nOPyEUWrtmQKhfOFCKJS0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZmtRdIRMP7lO91U1BD2MB3WwPPKlqHapmG6hErf23p8H5lKyL3bQZI8vheKdnKk3lnR0LdVHSkLCWB8IRJ7Nlxg+Vyo+ChQulZZ+jMVVtZnsRrCJ4sJVzpfXBu1PAWL3nJKnKGY+nEP8akjiRsQ+Uxs087W3Hwswl0YaQfn/NQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=hRkBG9tV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K4+wMrbO; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="hRkBG9tV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K4+wMrbO" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id D11D511400AA; Fri, 27 Dec 2024 05:47:22 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Fri, 27 Dec 2024 05:47:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296442; x=1735382842; bh=UL+LkjC4ScqAXfKqfjLgPTP5V7B0ksBEKjyQ9SR5DE8=; b= hRkBG9tVhInGFLOgPZ+6XAQhqVW1qK3lj0GI4GtEla8pNcF/Ry085HFBmgAlbO8A UborZNGQ81MrWFYaeNx37Ngv4zNGVnlM16kcyUwAoJkQTFAhC8KgN61KXzJnoPbX 0L7GRL1zbyx7QLlkDwlJb6t5sSqQGQhMXPvmVgMamlRLQTvCL1uwvFeMWDCO3dp1 UgLrCYXyXnHMUkfz7k1PHG3NN+RRKwe+8/toULWAjSAmJupiQeMxryGJJueLXez/ jToeilWwNflFHRrj+veDRC+MwGfeEpd3VpxM+l2NuDa5epb1ewXa1NRPlmTqdxuu CWT3SjhCw9czxgvOEL2kjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296442; x= 1735382842; bh=UL+LkjC4ScqAXfKqfjLgPTP5V7B0ksBEKjyQ9SR5DE8=; b=K 4+wMrbO+8fU694I0gMJNwtzXAukXjR5nepCEEJZO4+YbuHreogHUQeWfeGY/CGbM 2/Lyit4ahTkUg9GaFfUHnTOJau6ObChx09qw3ktBXhzTiXnrGO+0N45FJq7rrzY9 dNISL5K5oJuWVzCW1/+oyDImsXImup8MoZxqz9viVaCE3YKVruPS/ccsHIGQnONp 7WS8HwXZU4Ai47ZHsdLew3WogQ6eXG9OazSrqN7qbErBTpDjcxLO+a/4OfHZwSlM QQJSolni4PzHt8OcQzlaZNZdKEVPob6A+uhY5gaM6SWEng0SDVN6xdAPtVwFjx91 EkilwX8P0sj4CQbYslW9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:22 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 46b01dbb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:18 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:28 +0100 Subject: [PATCH 8/9] shallow: fix -Wsign-compare warnings Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-8-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 Fix a couple of -Wsign-compare issues in "shallow.c" and mark the file as -Wsign-compare-clean. This change prepares the code for a refactoring of `repo_in_merge_bases_many()`, which will be adapted to accept the number of commits as `size_t` instead of `int`. Signed-off-by: Patrick Steinhardt --- shallow.c | 38 ++++++++++++++++++-------------------- shallow.h | 6 +++--- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/shallow.c b/shallow.c index 82a8da3d730b2f4f6bda462c8ac347f0b10da993..b8fcfbef0f9cdbfa895d4d6e1214f67942f88d25 100644 --- a/shallow.c +++ b/shallow.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" #include "hex.h" @@ -134,7 +133,8 @@ static void free_depth_in_slab(int **ptr) struct commit_list *get_shallow_commits(struct object_array *heads, int depth, int shallow_flag, int not_shallow_flag) { - int i = 0, cur_depth = 0; + size_t i = 0; + int cur_depth = 0; struct commit_list *result = NULL; struct object_array stack = OBJECT_ARRAY_INIT; struct commit *commit = NULL; @@ -335,16 +335,16 @@ static int write_shallow_commits_1(struct strbuf *out, int use_pack_protocol, const struct oid_array *extra, unsigned flags) { - struct write_shallow_data data; - int i; - data.out = out; - data.use_pack_protocol = use_pack_protocol; - data.count = 0; - data.flags = flags; + struct write_shallow_data data = { + .out = out, + .use_pack_protocol = use_pack_protocol, + .flags = flags, + }; + for_each_commit_graft(write_one_shallow, &data); if (!extra) return data.count; - for (i = 0; i < extra->nr; i++) { + for (size_t i = 0; i < extra->nr; i++) { strbuf_addstr(out, oid_to_hex(extra->oid + i)); strbuf_addch(out, '\n'); data.count++; @@ -466,7 +466,6 @@ struct trace_key trace_shallow = TRACE_KEY_INIT(SHALLOW); */ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa) { - int i; trace_printf_key(&trace_shallow, "shallow: prepare_shallow_info\n"); memset(info, 0, sizeof(*info)); info->shallow = sa; @@ -474,7 +473,7 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa) return; ALLOC_ARRAY(info->ours, sa->nr); ALLOC_ARRAY(info->theirs, sa->nr); - for (i = 0; i < sa->nr; i++) { + for (size_t i = 0; i < sa->nr; i++) { if (repo_has_object_file(the_repository, sa->oid + i)) { struct commit_graft *graft; graft = lookup_commit_graft(the_repository, @@ -507,7 +506,7 @@ void clear_shallow_info(struct shallow_info *info) void remove_nonexistent_theirs_shallow(struct shallow_info *info) { struct object_id *oid = info->shallow->oid; - int i, dst; + size_t i, dst; trace_printf_key(&trace_shallow, "shallow: remove_nonexistent_theirs_shallow\n"); for (i = dst = 0; i < info->nr_theirs; i++) { if (i != dst) @@ -560,7 +559,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid, { unsigned int i, nr; struct commit_list *head = NULL; - int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32); + size_t bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32); size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); struct commit *c = lookup_commit_reference_gently(the_repository, oid, 1); @@ -660,7 +659,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, struct object_id *oid = info->shallow->oid; struct oid_array *ref = info->ref; unsigned int i, nr; - int *shallow, nr_shallow = 0; + size_t *shallow, nr_shallow = 0; struct paint_info pi; trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n"); @@ -735,7 +734,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, struct commit_array { struct commit **commits; - int nr, alloc; + size_t nr, alloc; }; static int add_ref(const char *refname UNUSED, @@ -753,12 +752,11 @@ static int add_ref(const char *refname UNUSED, return 0; } -static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap) +static void update_refstatus(int *ref_status, size_t nr, uint32_t *bitmap) { - unsigned int i; if (!ref_status) return; - for (i = 0; i < nr; i++) + for (size_t i = 0; i < nr; i++) if (bitmap[i / 32] & (1U << (i % 32))) ref_status[i]++; } @@ -773,8 +771,8 @@ static void post_assign_shallow(struct shallow_info *info, struct object_id *oid = info->shallow->oid; struct commit *c; uint32_t **bitmap; - int dst, i, j; - int bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32); + size_t dst, i, j; + size_t bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32); struct commit_array ca; trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n"); diff --git a/shallow.h b/shallow.h index e9ca7e4bc80451a74dc10fb6d4e1a0b190dc4dcc..9bfeade93ead7421d7f2991862dde88ba546fc64 100644 --- a/shallow.h +++ b/shallow.h @@ -59,8 +59,8 @@ void prune_shallow(unsigned options); */ struct shallow_info { struct oid_array *shallow; - int *ours, nr_ours; - int *theirs, nr_theirs; + size_t *ours, nr_ours; + size_t *theirs, nr_theirs; struct oid_array *ref; /* for receive-pack */ @@ -69,7 +69,7 @@ struct shallow_info { int *reachable; int *shallow_ref; struct commit **commits; - int nr_commits; + size_t nr_commits; }; void prepare_shallow_info(struct shallow_info *, struct oid_array *); From patchwork Fri Dec 27 10:46:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13921677 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8EA51F2C4B for ; Fri, 27 Dec 2024 10:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296446; cv=none; b=OU97y1OiVw/cTc1caAhu2DF74kR2/79yvWGXgF05I9FH5U4G28oOrwaQVfwWJlmVqvpCYdp7g4Up0+i32OGNErmyGNAN8ere4cIFf9sakb3Aj6OhPSP+tlmuXtYSm22D7nfpSqZItV9rMB0UdCVgTp46SwrAA8uFjI21y19z6pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735296446; c=relaxed/simple; bh=Onq1Xvs6f6Gy6S95efIfPuIvVzSBZ0B+8qEIh71xUmE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LposA5XjqJapr9170RW+8j6IVOsFre07NhsZUfWhl0UYXfHSuadn6lVkMOaQ/DnLTMA1rg6fc4HyKjQ+zSe31ExT8p3XEv/1qZPrxQP9ph0ClqtfXgKyyCXzqj36L1RTmN7vqnGO/1Tsh9jdxH2RD6aD/1p1hTivCXP9C6Fp7jY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=iFsTvugw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YnhjVaXT; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="iFsTvugw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YnhjVaXT" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id C406F1380146; Fri, 27 Dec 2024 05:47:23 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 27 Dec 2024 05:47:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1735296443; x=1735382843; bh=zYcMOUIU3thyun63hOz2gpKsEcGRdAIkcmuRkAtkfDg=; b= iFsTvugwHjStD1BNjLmOp1kMblBlr7Puq+PcTd5Ucn29jajopgpjdSAyxGWiR8wo fNaJI9n6nI8ChI4VY7iDvQStFq4uLQ083lpRIUPF5icMf8ga8K4wZA/yiwypo+SB Vh1p19Xl48HJFZxtrudsaLvFJ/IugfjbhpJ9rRalEjWS78zlkoj6Rufn5mfVpqQC pmlmPTHRmp8Jo2rRP+yBYARtkgIa3ZVNSJNLjUit8IuIRWtxiQ6dp1Vqpt3feMYx ipkjyMOps6B8nWMbw8sToM5UHKWFCimH7M2Gv3rlZA8MCRSxsGWpJBjs78V0PoWK VS7TOv6mt+ymRI0l40Pv6w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735296443; x= 1735382843; bh=zYcMOUIU3thyun63hOz2gpKsEcGRdAIkcmuRkAtkfDg=; b=Y nhjVaXTW8YKB+B0niRGEH9MTOlva7AqrLnYHQgL6OBb2/fUMSKRMJbPnA6TvWgYq xSkWWh1jysmn95ubDngi1lHCdkh779Pk5FpXhAG9lEAfPCSoWLal/rSLiRgK0YtR foD0gdxtFe0zKMC9KxgiPUCWbLkbuH0Go7A4CmUYfjLyUbMkdb1zFz8B+/ntQkmj HVUIrCKwGA+nRR1+6dL4IllVitKNQYkh+cOq4PyvDLbbTjxQYKjXtwgeX19H8bvm yOsc7W/qHM64Y071PxqKFUxzprvHJMU+SlFiwwZvr8yDrlG4qLK13SreGGQACrMR 2vufZDwyIDkWHp8P0ebfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorh hg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Dec 2024 05:47:22 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4b7d4690 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 27 Dec 2024 10:45:19 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 27 Dec 2024 11:46:29 +0100 Subject: [PATCH 9/9] commit-reach: use `size_t` to track indices when computing merge bases Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241227-b4-pks-commit-reach-sign-compare-v1-9-07c59c2aa632@pks.im> References: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> In-Reply-To: <20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im> To: git@vger.kernel.org Cc: Jeff King X-Mailer: b4 0.14.2 The functions `repo_get_merge_bases_many()` and friends accepts an array of commits as well as a parameter that indicates how large that array is. This parameter is using a signed integer, which leads to a couple of warnings with -Wsign-compare. Refactor the code to use `size_t` to track indices instead and adapt callers accordingly. While most callers are trivial, there are two callers that require a bit more scrutiny: - builtin/merge-base.c:show_merge_base() subtracts `1` from the `rev_nr` before calling `repo_get_merge_bases_many_dirty()`, so if the variable was `0` it would wrap. This code is fine though because its only caller will execute that code only when `argc >= 2`, and it follows that `rev_nr >= 2`, as well. - bisect.ccheck_merge_bases() similarly subtracts `1` from `rev_nr`. Again, there is only a single caller that populates `rev_nr` with `good_revs.nr`. And because a bisection always requires at least one good revision it follws that `rev_nr >= 1`. Mark the file as -Wsign-compare-clean. Signed-off-by: Patrick Steinhardt --- bisect.c | 2 +- builtin/merge-base.c | 4 ++-- commit-reach.c | 7 +++---- commit-reach.h | 4 ++-- t/helper/test-reach.c | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bisect.c b/bisect.c index 7a1afc46e5fc0250212f5b6eaf952cf8e36b56fe..7a3c77c6d84da0cb6e135b6e0b1ca3596903af5c 100644 --- a/bisect.c +++ b/bisect.c @@ -855,7 +855,7 @@ static void handle_skipped_merge_base(const struct object_id *mb) * for early success, this will be converted back to 0 in * check_good_are_ancestors_of_bad(). */ -static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) +static enum bisect_error check_merge_bases(size_t rev_nr, struct commit **rev, int no_checkout) { enum bisect_error res = BISECT_OK; struct commit_list *result = NULL; diff --git a/builtin/merge-base.c b/builtin/merge-base.c index a20c93b11aaa0b9f380b843469da2a3b5db10d00..123c81515e1f5f12045e4073f78b6e8a2b04bb4b 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -8,7 +8,7 @@ #include "parse-options.h" #include "commit-reach.h" -static int show_merge_base(struct commit **rev, int rev_nr, int show_all) +static int show_merge_base(struct commit **rev, size_t rev_nr, int show_all) { struct commit_list *result = NULL, *r; @@ -149,7 +149,7 @@ int cmd_merge_base(int argc, struct repository *repo UNUSED) { struct commit **rev; - int rev_nr = 0; + size_t rev_nr = 0; int show_all = 0; int cmdmode = 0; int ret; diff --git a/commit-reach.c b/commit-reach.c index bab40f557580476d59d3a0b0ef56f40263e6615e..a339e41aa4ed1e375ee6f2f42a163ff1c654c3e4 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" #include "commit.h" @@ -421,7 +420,7 @@ static int remove_redundant(struct repository *r, struct commit **array, static int get_merge_bases_many_0(struct repository *r, struct commit *one, - int n, + size_t n, struct commit **twos, int cleanup, struct commit_list **result) @@ -469,7 +468,7 @@ static int get_merge_bases_many_0(struct repository *r, int repo_get_merge_bases_many(struct repository *r, struct commit *one, - int n, + size_t n, struct commit **twos, struct commit_list **result) { @@ -478,7 +477,7 @@ int repo_get_merge_bases_many(struct repository *r, int repo_get_merge_bases_many_dirty(struct repository *r, struct commit *one, - int n, + size_t n, struct commit **twos, struct commit_list **result) { diff --git a/commit-reach.h b/commit-reach.h index fa5408054ac01372c041d18595a405cfdaec6af3..6012402dfcfe453fd710d0b4c9a9e09f8953f63a 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -14,12 +14,12 @@ int repo_get_merge_bases(struct repository *r, struct commit *rev2, struct commit_list **result); int repo_get_merge_bases_many(struct repository *r, - struct commit *one, int n, + struct commit *one, size_t n, struct commit **twos, struct commit_list **result); /* To be used only when object flags after this call no longer matter */ int repo_get_merge_bases_many_dirty(struct repository *r, - struct commit *one, int n, + struct commit *one, size_t n, struct commit **twos, struct commit_list **result); diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 01cf77ae65b9a7db2f31a9a1558b8bb84b2e81d3..028ec0030678284eba844e121c6eff88abdd3139 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -35,7 +35,7 @@ int cmd__reach(int ac, const char **av) struct commit_list *X, *Y; struct object_array X_obj = OBJECT_ARRAY_INIT; struct commit **X_array, **Y_array; - int X_nr, X_alloc, Y_nr, Y_alloc; + size_t X_nr, X_alloc, Y_nr, Y_alloc; struct strbuf buf = STRBUF_INIT; struct repository *r = the_repository; @@ -157,7 +157,7 @@ int cmd__reach(int ac, const char **av) clear_contains_cache(&cache); } else if (!strcmp(av[1], "get_reachable_subset")) { const int reachable_flag = 1; - int i, count = 0; + int count = 0; struct commit_list *current; struct commit_list *list = get_reachable_subset(X_array, X_nr, Y_array, Y_nr, @@ -169,7 +169,7 @@ int cmd__reach(int ac, const char **av) oid_to_hex(&list->item->object.oid)); count++; } - for (i = 0; i < Y_nr; i++) { + for (size_t i = 0; i < Y_nr; i++) { if (Y_array[i]->object.flags & reachable_flag) count--; }