Skip to content

Commit 41c78cf

Browse files
committed
Merge branch 'ps/more-sign-compare' into next
More -Wsign-compare fixes. * ps/more-sign-compare: sign-compare: avoid comparing ptrdiff with an int/unsigned commit-reach: use `size_t` to track indices when computing merge bases shallow: fix -Wsign-compare warnings builtin/log: fix remaining -Wsign-compare warnings builtin/log: use `size_t` to track indices commit-reach: use `size_t` to track indices in `get_reachable_subset()` commit-reach: use `size_t` to track indices in `remove_redundant()` commit-reach: fix type of `min_commit_date` commit-reach: fix index used to loop through unsigned integer prio-queue: fix type of `insertion_ctr`
2 parents 8677dc5 + 2402725 commit 41c78cf

File tree

13 files changed

+112
-106
lines changed

13 files changed

+112
-106
lines changed

bisect.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,10 @@ static struct commit *get_commit_reference(struct repository *r,
780780
}
781781

782782
static struct commit **get_bad_and_good_commits(struct repository *r,
783-
int *rev_nr)
783+
size_t *rev_nr)
784784
{
785785
struct commit **rev;
786-
int i, n = 0;
786+
size_t i, n = 0;
787787

788788
ALLOC_ARRAY(rev, 1 + good_revs.nr);
789789
rev[n++] = get_commit_reference(r, current_bad_oid);
@@ -855,7 +855,7 @@ static void handle_skipped_merge_base(const struct object_id *mb)
855855
* for early success, this will be converted back to 0 in
856856
* check_good_are_ancestors_of_bad().
857857
*/
858-
static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
858+
static enum bisect_error check_merge_bases(size_t rev_nr, struct commit **rev, int no_checkout)
859859
{
860860
enum bisect_error res = BISECT_OK;
861861
struct commit_list *result = NULL;
@@ -887,7 +887,7 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
887887
return res;
888888
}
889889

890-
static int check_ancestors(struct repository *r, int rev_nr,
890+
static int check_ancestors(struct repository *r, size_t rev_nr,
891891
struct commit **rev, const char *prefix)
892892
{
893893
struct strvec rev_argv = STRVEC_INIT;
@@ -922,7 +922,8 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
922922
{
923923
char *filename;
924924
struct stat st;
925-
int fd, rev_nr;
925+
int fd;
926+
size_t rev_nr;
926927
enum bisect_error res = BISECT_OK;
927928
struct commit **rev;
928929

builtin/log.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#define USE_THE_REPOSITORY_VARIABLE
9-
#define DISABLE_SIGN_COMPARE_WARNINGS
109

1110
#include "builtin.h"
1211
#include "abspath.h"
@@ -209,7 +208,6 @@ static void cmd_log_init_defaults(struct rev_info *rev,
209208

210209
static void set_default_decoration_filter(struct decoration_filter *decoration_filter)
211210
{
212-
int i;
213211
char *value = NULL;
214212
struct string_list *include = decoration_filter->include_ref_pattern;
215213
const struct string_list *config_exclude;
@@ -243,7 +241,7 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f
243241
* No command-line or config options were given, so
244242
* populate with sensible defaults.
245243
*/
246-
for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
244+
for (size_t i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
247245
if (!ref_namespace[i].decoration)
248246
continue;
249247

@@ -717,14 +715,14 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
717715
unsigned long size;
718716
enum object_type type;
719717
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
720-
int offset = 0;
718+
unsigned long offset = 0;
721719

722720
if (!buf)
723721
return error(_("could not read object %s"), oid_to_hex(oid));
724722

725723
assert(type == OBJ_TAG);
726724
while (offset < size && buf[offset] != '\n') {
727-
int new_offset = offset + 1;
725+
unsigned long new_offset = offset + 1;
728726
const char *ident;
729727
while (new_offset < size && buf[new_offset++] != '\n')
730728
; /* do nothing */
@@ -1316,24 +1314,25 @@ static void print_signature(const char *signature, FILE *file)
13161314

13171315
static char *find_branch_name(struct rev_info *rev)
13181316
{
1319-
int i, positive = -1;
13201317
struct object_id branch_oid;
13211318
const struct object_id *tip_oid;
13221319
const char *ref, *v;
13231320
char *full_ref, *branch = NULL;
1321+
int interesting_found = 0;
1322+
size_t idx;
13241323

1325-
for (i = 0; i < rev->cmdline.nr; i++) {
1324+
for (size_t i = 0; i < rev->cmdline.nr; i++) {
13261325
if (rev->cmdline.rev[i].flags & UNINTERESTING)
13271326
continue;
1328-
if (positive < 0)
1329-
positive = i;
1330-
else
1327+
if (interesting_found)
13311328
return NULL;
1329+
interesting_found = 1;
1330+
idx = i;
13321331
}
1333-
if (positive < 0)
1332+
if (!interesting_found)
13341333
return NULL;
1335-
ref = rev->cmdline.rev[positive].name;
1336-
tip_oid = &rev->cmdline.rev[positive].item->oid;
1334+
ref = rev->cmdline.rev[idx].name;
1335+
tip_oid = &rev->cmdline.rev[idx].item->oid;
13371336
if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid,
13381337
&full_ref, 0) &&
13391338
skip_prefix(full_ref, "refs/heads/", &v) &&
@@ -1746,11 +1745,12 @@ struct base_tree_info {
17461745

17471746
static struct commit *get_base_commit(const struct format_config *cfg,
17481747
struct commit **list,
1749-
int total)
1748+
size_t total)
17501749
{
17511750
struct commit *base = NULL;
17521751
struct commit **rev;
1753-
int i = 0, rev_nr = 0, auto_select, die_on_failure, ret;
1752+
int auto_select, die_on_failure, ret;
1753+
size_t i = 0, rev_nr = 0;
17541754

17551755
switch (cfg->auto_base) {
17561756
case AUTO_BASE_NEVER:
@@ -1885,13 +1885,12 @@ define_commit_slab(commit_base, int);
18851885
static void prepare_bases(struct base_tree_info *bases,
18861886
struct commit *base,
18871887
struct commit **list,
1888-
int total)
1888+
size_t total)
18891889
{
18901890
struct commit *commit;
18911891
struct rev_info revs;
18921892
struct diff_options diffopt;
18931893
struct commit_base commit_base;
1894-
int i;
18951894

18961895
if (!base)
18971896
return;
@@ -1906,7 +1905,7 @@ static void prepare_bases(struct base_tree_info *bases,
19061905
repo_init_revisions(the_repository, &revs, NULL);
19071906
revs.max_parents = 1;
19081907
revs.topo_order = 1;
1909-
for (i = 0; i < total; i++) {
1908+
for (size_t i = 0; i < total; i++) {
19101909
list[i]->object.flags &= ~UNINTERESTING;
19111910
add_pending_object(&revs, &list[i]->object, "rev_list");
19121911
*commit_base_at(&commit_base, list[i]) = 1;
@@ -2007,7 +2006,7 @@ int cmd_format_patch(int argc,
20072006
struct rev_info rev;
20082007
char *to_free = NULL;
20092008
struct setup_revision_opt s_r_opt;
2010-
int nr = 0, total, i;
2009+
size_t nr = 0, total, i;
20112010
int use_stdout = 0;
20122011
int start_number = -1;
20132012
int just_numbers = 0;
@@ -2183,7 +2182,7 @@ int cmd_format_patch(int argc,
21832182
fmt_patch_suffix = cfg.fmt_patch_suffix;
21842183

21852184
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
2186-
if (cfg.log.fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
2185+
if (cfg.log.fmt_patch_name_max <= cast_size_t_to_int(strlen("0000-") + strlen(fmt_patch_suffix)))
21872186
cfg.log.fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
21882187

21892188
if (cover_from_description_arg)
@@ -2500,11 +2499,14 @@ int cmd_format_patch(int argc,
25002499

25012500
if (show_progress)
25022501
progress = start_delayed_progress(_("Generating patches"), total);
2503-
while (0 <= --nr) {
2502+
for (i = 0; i < nr; i++) {
2503+
size_t idx = nr - i - 1;
25042504
int shown;
2505-
display_progress(progress, total - nr);
2506-
commit = list[nr];
2507-
rev.nr = total - nr + (start_number - 1);
2505+
2506+
display_progress(progress, total - idx);
2507+
commit = list[idx];
2508+
rev.nr = total - idx + (start_number - 1);
2509+
25082510
/* Make the second and subsequent mails replies to the first */
25092511
if (cfg.thread) {
25102512
/* Have we already had a message ID? */

builtin/merge-base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "parse-options.h"
99
#include "commit-reach.h"
1010

11-
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
11+
static int show_merge_base(struct commit **rev, size_t rev_nr, int show_all)
1212
{
1313
struct commit_list *result = NULL, *r;
1414

@@ -149,7 +149,7 @@ int cmd_merge_base(int argc,
149149
struct repository *repo UNUSED)
150150
{
151151
struct commit **rev;
152-
int rev_nr = 0;
152+
size_t rev_nr = 0;
153153
int show_all = 0;
154154
int cmdmode = 0;
155155
int ret;

0 commit comments

Comments
 (0)