aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/merge-base.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-12-27 11:46:29 +0100
committerJunio C Hamano <gitster@pobox.com>2024-12-27 08:12:40 -0800
commit5e7fe8a7b89a07d8c3ab298ac69bc33f6ba88b47 (patch)
treec3d944cce3fb235e37a28ad15bdce6561e523cc5 /builtin/merge-base.c
parent455ac07021d4feede4f5b7e39bf00dc186ce3c09 (diff)
downloadgit-5e7fe8a7b89a07d8c3ab298ac69bc33f6ba88b47.tar.gz
commit-reach: use `size_t` to track indices when computing merge bases
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge-base.c')
-rw-r--r--builtin/merge-base.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index a20c93b11a..123c81515e 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;