builtin/log: use `size_t` to track indices

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

Patrick Steinhardt committed Dec 27, 2024 at 11:46 UTC 0905ed201a87bc97dc4d47c0cb8fd65316f33269
1 file changed +13 -10
builtin/log.c
+13 -10
@@ -1746,11 +1746,12 @@ struct base_tree_info {
1746
1747 static struct commit *get_base_commit(const struct format_config *cfg,
1748 struct commit **list,
1749 - int total)
1749 + size_t total)
1750 {
1751 struct commit *base = NULL;
1752 struct commit **rev;
1753 - int i = 0, rev_nr = 0, auto_select, die_on_failure, ret;
1753 + int auto_select, die_on_failure, ret;
1754 + size_t i = 0, rev_nr = 0;
1755
1756 switch (cfg->auto_base) {
1757 case AUTO_BASE_NEVER:
@@ -1885,13 +1886,12 @@ define_commit_slab(commit_base, int);
1886 static void prepare_bases(struct base_tree_info *bases,
1887 struct commit *base,
1888 struct commit **list,
1888 - int total)
1889 + size_t total)
1890 {
1891 struct commit *commit;
1892 struct rev_info revs;
1893 struct diff_options diffopt;
1894 struct commit_base commit_base;
1894 - int i;
1895
1896 if (!base)
1897 return;
@@ -1906,7 +1906,7 @@ static void prepare_bases(struct base_tree_info *bases,
1906 repo_init_revisions(the_repository, &revs, NULL);
1907 revs.max_parents = 1;
1908 revs.topo_order = 1;
1909 - for (i = 0; i < total; i++) {
1909 + for (size_t i = 0; i < total; i++) {
1910 list[i]->object.flags &= ~UNINTERESTING;
1911 add_pending_object(&revs, &list[i]->object, "rev_list");
1912 *commit_base_at(&commit_base, list[i]) = 1;
@@ -2007,7 +2007,7 @@ int cmd_format_patch(int argc,
2007 struct rev_info rev;
2008 char *to_free = NULL;
2009 struct setup_revision_opt s_r_opt;
2010 - int nr = 0, total, i;
2010 + size_t nr = 0, total, i;
2011 int use_stdout = 0;
2012 int start_number = -1;
2013 int just_numbers = 0;
@@ -2500,11 +2500,14 @@ int cmd_format_patch(int argc,
2500
2501 if (show_progress)
2502 progress = start_delayed_progress(_("Generating patches"), total);
2503 - while (0 <= --nr) {
2503 + for (i = 0; i < nr; i++) {
2504 + size_t idx = nr - i - 1;
2505 int shown;
2505 - display_progress(progress, total - nr);
2506 - commit = list[nr];
2507 - rev.nr = total - nr + (start_number - 1);
2506 +
2507 + display_progress(progress, total - idx);
2508 + commit = list[idx];
2509 + rev.nr = total - idx + (start_number - 1);
2510 +
2511 /* Make the second and subsequent mails replies to the first */
2512 if (cfg.thread) {
2513 /* Have we already had a message ID? */