commit-reach: use `size_t` to track indices in `get_reachable_subset()`

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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 27, 2024 at 11:46 UTC 85ee0680e2d5d667919e06394ca7622f09652310
7 files changed +17 -16
bisect.c
+5 -4
@@ -780,10 +780,10 @@ static struct commit *get_commit_reference(struct repository *r,
780 }
781
782 static struct commit **get_bad_and_good_commits(struct repository *r,
783 - int *rev_nr)
783 + size_t *rev_nr)
784 {
785 struct commit **rev;
786 - int i, n = 0;
786 + size_t i, n = 0;
787
788 ALLOC_ARRAY(rev, 1 + good_revs.nr);
789 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
887 return res;
888 }
889
890 -static int check_ancestors(struct repository *r, int rev_nr,
890 +static int check_ancestors(struct repository *r, size_t rev_nr,
891 struct commit **rev, const char *prefix)
892 {
893 struct strvec rev_argv = STRVEC_INIT;
@@ -922,7 +922,8 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
922 {
923 char *filename;
924 struct stat st;
925 - int fd, rev_nr;
925 + int fd;
926 + size_t rev_nr;
927 enum bisect_error res = BISECT_OK;
928 struct commit **rev;
929
commit-reach.c
+4 -4
@@ -791,8 +791,8 @@ int can_all_from_reach_with_flag(struct object_array *from,
791 timestamp_t min_generation)
792 {
793 struct commit **list = NULL;
794 - int i;
795 - int nr_commits;
794 + size_t i;
795 + size_t nr_commits;
796 int result = 1;
797
798 ALLOC_ARRAY(list, from->nr);
@@ -944,8 +944,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
944 return result;
945 }
946
947 -struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
948 - struct commit **to, int nr_to,
947 +struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
948 + struct commit **to, size_t nr_to,
949 unsigned int reachable_flag)
950 {
951 struct commit **item;
commit-reach.h
+2 -2
@@ -95,8 +95,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
95 * This method uses the PARENT1 and PARENT2 flags during its operation,
96 * so be sure these flags are not set before calling the method.
97 */
98 -struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
99 - struct commit **to, int nr_to,
98 +struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
99 + struct commit **to, size_t nr_to,
100 unsigned int reachable_flag);
101
102 struct ahead_behind_count {
commit.c
+2 -2
@@ -778,11 +778,11 @@ static void clear_commit_marks_1(struct commit_list **plist,
778 }
779 }
780
781 -void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark)
781 +void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark)
782 {
783 struct commit_list *list = NULL;
784
785 - while (nr--) {
785 + for (size_t i = 0; i < nr; i++) {
786 clear_commit_marks_1(&list, *commit, mark);
787 commit++;
788 }
commit.h
+1 -1
@@ -210,7 +210,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
210 struct commit *pop_commit(struct commit_list **stack);
211
212 void clear_commit_marks(struct commit *commit, unsigned int mark);
213 -void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
213 +void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark);
214
215
216 enum rev_sort_order {
ref-filter.c
+1 -1
@@ -3041,7 +3041,7 @@ static void reach_filter(struct ref_array *array,
3041 struct commit_list **check_reachable,
3042 int include_reached)
3043 {
3044 - int i, old_nr;
3044 + size_t i, old_nr;
3045 struct commit **to_clear;
3046
3047 if (!*check_reachable)
remote.c
+2 -2
@@ -1535,7 +1535,7 @@ static struct ref **tail_ref(struct ref **head)
1535
1536 struct tips {
1537 struct commit **tip;
1538 - int nr, alloc;
1538 + size_t nr, alloc;
1539 };
1540
1541 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
1602 const int reachable_flag = 1;
1603 struct commit_list *found_commits;
1604 struct commit **src_commits;
1605 - int nr_src_commits = 0, alloc_src_commits = 16;
1605 + size_t nr_src_commits = 0, alloc_src_commits = 16;
1606 ALLOC_ARRAY(src_commits, alloc_src_commits);
1607
1608 for_each_string_list_item(item, &src_tag) {