Skip to content

Commit 0905ed2

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85ee068 commit 0905ed2

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

builtin/log.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,11 +1746,12 @@ struct base_tree_info {
17461746

17471747
static struct commit *get_base_commit(const struct format_config *cfg,
17481748
struct commit **list,
1749-
int total)
1749+
size_t total)
17501750
{
17511751
struct commit *base = NULL;
17521752
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;
17541755

17551756
switch (cfg->auto_base) {
17561757
case AUTO_BASE_NEVER:
@@ -1885,13 +1886,12 @@ define_commit_slab(commit_base, int);
18851886
static void prepare_bases(struct base_tree_info *bases,
18861887
struct commit *base,
18871888
struct commit **list,
1888-
int total)
1889+
size_t total)
18891890
{
18901891
struct commit *commit;
18911892
struct rev_info revs;
18921893
struct diff_options diffopt;
18931894
struct commit_base commit_base;
1894-
int i;
18951895

18961896
if (!base)
18971897
return;
@@ -1906,7 +1906,7 @@ static void prepare_bases(struct base_tree_info *bases,
19061906
repo_init_revisions(the_repository, &revs, NULL);
19071907
revs.max_parents = 1;
19081908
revs.topo_order = 1;
1909-
for (i = 0; i < total; i++) {
1909+
for (size_t i = 0; i < total; i++) {
19101910
list[i]->object.flags &= ~UNINTERESTING;
19111911
add_pending_object(&revs, &list[i]->object, "rev_list");
19121912
*commit_base_at(&commit_base, list[i]) = 1;
@@ -2007,7 +2007,7 @@ int cmd_format_patch(int argc,
20072007
struct rev_info rev;
20082008
char *to_free = NULL;
20092009
struct setup_revision_opt s_r_opt;
2010-
int nr = 0, total, i;
2010+
size_t nr = 0, total, i;
20112011
int use_stdout = 0;
20122012
int start_number = -1;
20132013
int just_numbers = 0;
@@ -2500,11 +2500,14 @@ int cmd_format_patch(int argc,
25002500

25012501
if (show_progress)
25022502
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;
25042505
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+
25082511
/* Make the second and subsequent mails replies to the first */
25092512
if (cfg.thread) {
25102513
/* Have we already had a message ID? */

0 commit comments

Comments
 (0)