Skip to content

Commit 376d7f1

Browse files
pks-tgitster
authored andcommitted
builtin/remote: fix sign comparison warnings
Fix -Wsign-comparison warnings. All of the warnings we have are about mismatches in signedness for loop counters. These are trivially fixable by using the correct integer type. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f530e5 commit 376d7f1

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

builtin/remote.c

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#define USE_THE_REPOSITORY_VARIABLE
2-
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "builtin.h"
54
#include "config.h"
@@ -182,7 +181,6 @@ static int add(int argc, const char **argv, const char *prefix,
182181
struct remote *remote;
183182
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
184183
const char *name, *url;
185-
int i;
186184
int result = 0;
187185

188186
struct option options[] = {
@@ -233,7 +231,7 @@ static int add(int argc, const char **argv, const char *prefix,
233231
strbuf_addf(&buf, "remote.%s.fetch", name);
234232
if (track.nr == 0)
235233
string_list_append(&track, "*");
236-
for (i = 0; i < track.nr; i++) {
234+
for (size_t i = 0; i < track.nr; i++) {
237235
add_branch(buf.buf, track.items[i].string,
238236
name, mirror, &buf2);
239237
}
@@ -647,18 +645,17 @@ static int read_remote_branches(const char *refname, const char *referent UNUSED
647645
static int migrate_file(struct remote *remote)
648646
{
649647
struct strbuf buf = STRBUF_INIT;
650-
int i;
651648

652649
strbuf_addf(&buf, "remote.%s.url", remote->name);
653-
for (i = 0; i < remote->url.nr; i++)
650+
for (size_t i = 0; i < remote->url.nr; i++)
654651
git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0);
655652
strbuf_reset(&buf);
656653
strbuf_addf(&buf, "remote.%s.push", remote->name);
657-
for (i = 0; i < remote->push.nr; i++)
654+
for (int i = 0; i < remote->push.nr; i++)
658655
git_config_set_multivar(buf.buf, remote->push.items[i].raw, "^$", 0);
659656
strbuf_reset(&buf);
660657
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
661-
for (i = 0; i < remote->fetch.nr; i++)
658+
for (int i = 0; i < remote->fetch.nr; i++)
662659
git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0);
663660
#ifndef WITH_BREAKING_CHANGES
664661
if (remote->origin == REMOTE_REMOTES)
@@ -744,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix,
744741
old_remote_context = STRBUF_INIT;
745742
struct string_list remote_branches = STRING_LIST_INIT_DUP;
746743
struct rename_info rename;
747-
int i, refs_renamed_nr = 0, refspec_updated = 0;
744+
int refs_renamed_nr = 0, refspec_updated = 0;
748745
struct progress *progress = NULL;
749746
int result = 0;
750747

@@ -790,7 +787,7 @@ static int mv(int argc, const char **argv, const char *prefix,
790787
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
791788
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
792789
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
793-
for (i = 0; i < oldremote->fetch.nr; i++) {
790+
for (int i = 0; i < oldremote->fetch.nr; i++) {
794791
char *ptr;
795792

796793
strbuf_reset(&buf2);
@@ -813,7 +810,7 @@ static int mv(int argc, const char **argv, const char *prefix,
813810
}
814811

815812
read_branches();
816-
for (i = 0; i < branch_list.nr; i++) {
813+
for (size_t i = 0; i < branch_list.nr; i++) {
817814
struct string_list_item *item = branch_list.items + i;
818815
struct branch_info *info = item->util;
819816
if (info->remote_name && !strcmp(info->remote_name, rename.old_name)) {
@@ -846,7 +843,7 @@ static int mv(int argc, const char **argv, const char *prefix,
846843
_("Renaming remote references"),
847844
rename.remote_branches->nr + rename.symrefs_nr);
848845
}
849-
for (i = 0; i < remote_branches.nr; i++) {
846+
for (size_t i = 0; i < remote_branches.nr; i++) {
850847
struct string_list_item *item = remote_branches.items + i;
851848
struct strbuf referent = STRBUF_INIT;
852849

@@ -859,7 +856,7 @@ static int mv(int argc, const char **argv, const char *prefix,
859856
strbuf_release(&referent);
860857
display_progress(progress, ++refs_renamed_nr);
861858
}
862-
for (i = 0; i < remote_branches.nr; i++) {
859+
for (size_t i = 0; i < remote_branches.nr; i++) {
863860
struct string_list_item *item = remote_branches.items + i;
864861

865862
if (item->util)
@@ -875,7 +872,7 @@ static int mv(int argc, const char **argv, const char *prefix,
875872
die(_("renaming '%s' failed"), item->string);
876873
display_progress(progress, ++refs_renamed_nr);
877874
}
878-
for (i = 0; i < remote_branches.nr; i++) {
875+
for (size_t i = 0; i < remote_branches.nr; i++) {
879876
struct string_list_item *item = remote_branches.items + i;
880877

881878
if (!item->util)
@@ -920,7 +917,7 @@ static int rm(int argc, const char **argv, const char *prefix,
920917
struct string_list branches = STRING_LIST_INIT_DUP;
921918
struct string_list skipped = STRING_LIST_INIT_DUP;
922919
struct branches_for_remote cb_data;
923-
int i, result;
920+
int result;
924921

925922
memset(&cb_data, 0, sizeof(cb_data));
926923
cb_data.branches = &branches;
@@ -942,7 +939,7 @@ static int rm(int argc, const char **argv, const char *prefix,
942939
for_each_remote(add_known_remote, &known_remotes);
943940

944941
read_branches();
945-
for (i = 0; i < branch_list.nr; i++) {
942+
for (size_t i = 0; i < branch_list.nr; i++) {
946943
struct string_list_item *item = branch_list.items + i;
947944
struct branch_info *info = item->util;
948945
if (info->remote_name && !strcmp(info->remote_name, remote->name)) {
@@ -988,7 +985,7 @@ static int rm(int argc, const char **argv, const char *prefix,
988985
"Note: Some branches outside the refs/remotes/ hierarchy were not removed;\n"
989986
"to delete them, use:",
990987
skipped.nr));
991-
for (i = 0; i < skipped.nr; i++)
988+
for (size_t i = 0; i < skipped.nr; i++)
992989
fprintf(stderr, " git branch -d %s\n",
993990
skipped.items[i].string);
994991
}
@@ -1166,7 +1163,6 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
11661163
struct branch_info *branch_info = item->util;
11671164
struct string_list *merge = &branch_info->merge;
11681165
int width = show_info->width + 4;
1169-
int i;
11701166

11711167
if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) {
11721168
error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"),
@@ -1192,7 +1188,7 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
11921188
} else {
11931189
printf_ln(_("merges with remote %s"), merge->items[0].string);
11941190
}
1195-
for (i = 1; i < merge->nr; i++)
1191+
for (size_t i = 1; i < merge->nr; i++)
11961192
printf(_("%-*s and with remote %s\n"), width, "",
11971193
merge->items[i].string);
11981194

@@ -1277,7 +1273,6 @@ static int get_one_entry(struct remote *remote, void *priv)
12771273
struct string_list *list = priv;
12781274
struct strbuf remote_info_buf = STRBUF_INIT;
12791275
struct strvec *url;
1280-
int i;
12811276

12821277
if (remote->url.nr > 0) {
12831278
struct strbuf promisor_config = STRBUF_INIT;
@@ -1294,8 +1289,7 @@ static int get_one_entry(struct remote *remote, void *priv)
12941289
} else
12951290
string_list_append(list, remote->name)->util = NULL;
12961291
url = push_url_of_remote(remote);
1297-
for (i = 0; i < url->nr; i++)
1298-
{
1292+
for (size_t i = 0; i < url->nr; i++) {
12991293
strbuf_addf(&remote_info_buf, "%s (push)", url->v[i]);
13001294
string_list_append(list, remote->name)->util =
13011295
strbuf_detach(&remote_info_buf, NULL);
@@ -1312,10 +1306,8 @@ static int show_all(void)
13121306
result = for_each_remote(get_one_entry, &list);
13131307

13141308
if (!result) {
1315-
int i;
1316-
13171309
string_list_sort(&list);
1318-
for (i = 0; i < list.nr; i++) {
1310+
for (size_t i = 0; i < list.nr; i++) {
13191311
struct string_list_item *item = list.items + i;
13201312
if (verbose)
13211313
printf("%s\t%s\n", item->string,
@@ -1352,7 +1344,7 @@ static int show(int argc, const char **argv, const char *prefix,
13521344
query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES);
13531345

13541346
for (; argc; argc--, argv++) {
1355-
int i;
1347+
size_t i;
13561348
struct strvec *url;
13571349

13581350
get_remote_ref_states(*argv, &info.states, query_flag);
@@ -1458,7 +1450,7 @@ static void report_set_head_auto(const char *remote, const char *head_name,
14581450
static int set_head(int argc, const char **argv, const char *prefix,
14591451
struct repository *repo UNUSED)
14601452
{
1461-
int i, opt_a = 0, opt_d = 0, result = 0, was_detached;
1453+
int opt_a = 0, opt_d = 0, result = 0, was_detached;
14621454
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
14631455
b_local_head = STRBUF_INIT;
14641456
char *head_name = NULL;
@@ -1489,7 +1481,7 @@ static int set_head(int argc, const char **argv, const char *prefix,
14891481
else if (states.heads.nr > 1) {
14901482
result |= error(_("Multiple remote HEAD branches. "
14911483
"Please choose one explicitly with:"));
1492-
for (i = 0; i < states.heads.nr; i++)
1484+
for (size_t i = 0; i < states.heads.nr; i++)
14931485
fprintf(stderr, " git remote set-head %s %s\n",
14941486
argv[0], states.heads.items[i].string);
14951487
} else
@@ -1714,7 +1706,7 @@ static int set_branches(int argc, const char **argv, const char *prefix,
17141706
static int get_url(int argc, const char **argv, const char *prefix,
17151707
struct repository *repo UNUSED)
17161708
{
1717-
int i, push_mode = 0, all_mode = 0;
1709+
int push_mode = 0, all_mode = 0;
17181710
const char *remotename = NULL;
17191711
struct remote *remote;
17201712
struct strvec *url;
@@ -1742,7 +1734,7 @@ static int get_url(int argc, const char **argv, const char *prefix,
17421734
url = push_mode ? push_url_of_remote(remote) : &remote->url;
17431735

17441736
if (all_mode) {
1745-
for (i = 0; i < url->nr; i++)
1737+
for (size_t i = 0; i < url->nr; i++)
17461738
printf_ln("%s", url->v[i]);
17471739
} else {
17481740
printf_ln("%s", url->v[0]);
@@ -1754,7 +1746,7 @@ static int get_url(int argc, const char **argv, const char *prefix,
17541746
static int set_url(int argc, const char **argv, const char *prefix,
17551747
struct repository *repo UNUSED)
17561748
{
1757-
int i, push_mode = 0, add_mode = 0, delete_mode = 0;
1749+
int push_mode = 0, add_mode = 0, delete_mode = 0;
17581750
int matches = 0, negative_matches = 0;
17591751
const char *remotename = NULL;
17601752
const char *newurl = NULL;
@@ -1818,7 +1810,7 @@ static int set_url(int argc, const char **argv, const char *prefix,
18181810
if (regcomp(&old_regex, oldurl, REG_EXTENDED))
18191811
die(_("Invalid old URL pattern: %s"), oldurl);
18201812

1821-
for (i = 0; i < urlset->nr; i++)
1813+
for (size_t i = 0; i < urlset->nr; i++)
18221814
if (!regexec(&old_regex, urlset->v[i], 0, NULL, 0))
18231815
matches++;
18241816
else

0 commit comments

Comments
 (0)