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

Patrick Steinhardt committed Jul 31, 2025 at 16:56 UTC 376d7f1a11a52bc3f2f4ce74557536ac2195ce5f
1 file changed +23 -31
builtin/remote.c
+23 -31
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "builtin.h"
4 #include "config.h"
@@ -182,7 +181,6 @@ static int add(int argc, const char **argv, const char *prefix,
181 struct remote *remote;
182 struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
183 const char *name, *url;
185 - int i;
184 int result = 0;
185
186 struct option options[] = {
@@ -233,7 +231,7 @@ static int add(int argc, const char **argv, const char *prefix,
231 strbuf_addf(&buf, "remote.%s.fetch", name);
232 if (track.nr == 0)
233 string_list_append(&track, "*");
236 - for (i = 0; i < track.nr; i++) {
234 + for (size_t i = 0; i < track.nr; i++) {
235 add_branch(buf.buf, track.items[i].string,
236 name, mirror, &buf2);
237 }
@@ -647,18 +645,17 @@ static int read_remote_branches(const char *refname, const char *referent UNUSED
645 static int migrate_file(struct remote *remote)
646 {
647 struct strbuf buf = STRBUF_INIT;
650 - int i;
648
649 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++)
651 git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0);
652 strbuf_reset(&buf);
653 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++)
655 git_config_set_multivar(buf.buf, remote->push.items[i].raw, "^$", 0);
656 strbuf_reset(&buf);
657 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++)
659 git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0);
660 #ifndef WITH_BREAKING_CHANGES
661 if (remote->origin == REMOTE_REMOTES)
@@ -744,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix,
741 old_remote_context = STRBUF_INIT;
742 struct string_list remote_branches = STRING_LIST_INIT_DUP;
743 struct rename_info rename;
747 - int i, refs_renamed_nr = 0, refspec_updated = 0;
744 + int refs_renamed_nr = 0, refspec_updated = 0;
745 struct progress *progress = NULL;
746 int result = 0;
747
@@ -790,7 +787,7 @@ static int mv(int argc, const char **argv, const char *prefix,
787 strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
788 git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
789 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++) {
791 char *ptr;
792
793 strbuf_reset(&buf2);
@@ -813,7 +810,7 @@ static int mv(int argc, const char **argv, const char *prefix,
810 }
811
812 read_branches();
816 - for (i = 0; i < branch_list.nr; i++) {
813 + for (size_t i = 0; i < branch_list.nr; i++) {
814 struct string_list_item *item = branch_list.items + i;
815 struct branch_info *info = item->util;
816 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,
843 _("Renaming remote references"),
844 rename.remote_branches->nr + rename.symrefs_nr);
845 }
849 - for (i = 0; i < remote_branches.nr; i++) {
846 + for (size_t i = 0; i < remote_branches.nr; i++) {
847 struct string_list_item *item = remote_branches.items + i;
848 struct strbuf referent = STRBUF_INIT;
849
@@ -859,7 +856,7 @@ static int mv(int argc, const char **argv, const char *prefix,
856 strbuf_release(&referent);
857 display_progress(progress, ++refs_renamed_nr);
858 }
862 - for (i = 0; i < remote_branches.nr; i++) {
859 + for (size_t i = 0; i < remote_branches.nr; i++) {
860 struct string_list_item *item = remote_branches.items + i;
861
862 if (item->util)
@@ -875,7 +872,7 @@ static int mv(int argc, const char **argv, const char *prefix,
872 die(_("renaming '%s' failed"), item->string);
873 display_progress(progress, ++refs_renamed_nr);
874 }
878 - for (i = 0; i < remote_branches.nr; i++) {
875 + for (size_t i = 0; i < remote_branches.nr; i++) {
876 struct string_list_item *item = remote_branches.items + i;
877
878 if (!item->util)
@@ -920,7 +917,7 @@ static int rm(int argc, const char **argv, const char *prefix,
917 struct string_list branches = STRING_LIST_INIT_DUP;
918 struct string_list skipped = STRING_LIST_INIT_DUP;
919 struct branches_for_remote cb_data;
923 - int i, result;
920 + int result;
921
922 memset(&cb_data, 0, sizeof(cb_data));
923 cb_data.branches = &branches;
@@ -942,7 +939,7 @@ static int rm(int argc, const char **argv, const char *prefix,
939 for_each_remote(add_known_remote, &known_remotes);
940
941 read_branches();
945 - for (i = 0; i < branch_list.nr; i++) {
942 + for (size_t i = 0; i < branch_list.nr; i++) {
943 struct string_list_item *item = branch_list.items + i;
944 struct branch_info *info = item->util;
945 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,
985 "Note: Some branches outside the refs/remotes/ hierarchy were not removed;\n"
986 "to delete them, use:",
987 skipped.nr));
991 - for (i = 0; i < skipped.nr; i++)
988 + for (size_t i = 0; i < skipped.nr; i++)
989 fprintf(stderr, " git branch -d %s\n",
990 skipped.items[i].string);
991 }
@@ -1166,7 +1163,6 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
1163 struct branch_info *branch_info = item->util;
1164 struct string_list *merge = &branch_info->merge;
1165 int width = show_info->width + 4;
1169 - int i;
1166
1167 if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) {
1168 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)
1188 } else {
1189 printf_ln(_("merges with remote %s"), merge->items[0].string);
1190 }
1195 - for (i = 1; i < merge->nr; i++)
1191 + for (size_t i = 1; i < merge->nr; i++)
1192 printf(_("%-*s and with remote %s\n"), width, "",
1193 merge->items[i].string);
1194
@@ -1277,7 +1273,6 @@ static int get_one_entry(struct remote *remote, void *priv)
1273 struct string_list *list = priv;
1274 struct strbuf remote_info_buf = STRBUF_INIT;
1275 struct strvec *url;
1280 - int i;
1276
1277 if (remote->url.nr > 0) {
1278 struct strbuf promisor_config = STRBUF_INIT;
@@ -1294,8 +1289,7 @@ static int get_one_entry(struct remote *remote, void *priv)
1289 } else
1290 string_list_append(list, remote->name)->util = NULL;
1291 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++) {
1293 strbuf_addf(&remote_info_buf, "%s (push)", url->v[i]);
1294 string_list_append(list, remote->name)->util =
1295 strbuf_detach(&remote_info_buf, NULL);
@@ -1312,10 +1306,8 @@ static int show_all(void)
1306 result = for_each_remote(get_one_entry, &list);
1307
1308 if (!result) {
1315 - int i;
1316 -
1309 string_list_sort(&list);
1318 - for (i = 0; i < list.nr; i++) {
1310 + for (size_t i = 0; i < list.nr; i++) {
1311 struct string_list_item *item = list.items + i;
1312 if (verbose)
1313 printf("%s\t%s\n", item->string,
@@ -1352,7 +1344,7 @@ static int show(int argc, const char **argv, const char *prefix,
1344 query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES);
1345
1346 for (; argc; argc--, argv++) {
1355 - int i;
1347 + size_t i;
1348 struct strvec *url;
1349
1350 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,
1450 static int set_head(int argc, const char **argv, const char *prefix,
1451 struct repository *repo UNUSED)
1452 {
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;
1454 struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
1455 b_local_head = STRBUF_INIT;
1456 char *head_name = NULL;
@@ -1489,7 +1481,7 @@ static int set_head(int argc, const char **argv, const char *prefix,
1481 else if (states.heads.nr > 1) {
1482 result |= error(_("Multiple remote HEAD branches. "
1483 "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++)
1485 fprintf(stderr, " git remote set-head %s %s\n",
1486 argv[0], states.heads.items[i].string);
1487 } else
@@ -1714,7 +1706,7 @@ static int set_branches(int argc, const char **argv, const char *prefix,
1706 static int get_url(int argc, const char **argv, const char *prefix,
1707 struct repository *repo UNUSED)
1708 {
1717 - int i, push_mode = 0, all_mode = 0;
1709 + int push_mode = 0, all_mode = 0;
1710 const char *remotename = NULL;
1711 struct remote *remote;
1712 struct strvec *url;
@@ -1742,7 +1734,7 @@ static int get_url(int argc, const char **argv, const char *prefix,
1734 url = push_mode ? push_url_of_remote(remote) : &remote->url;
1735
1736 if (all_mode) {
1745 - for (i = 0; i < url->nr; i++)
1737 + for (size_t i = 0; i < url->nr; i++)
1738 printf_ln("%s", url->v[i]);
1739 } else {
1740 printf_ln("%s", url->v[0]);
@@ -1754,7 +1746,7 @@ static int get_url(int argc, const char **argv, const char *prefix,
1746 static int set_url(int argc, const char **argv, const char *prefix,
1747 struct repository *repo UNUSED)
1748 {
1757 - int i, push_mode = 0, add_mode = 0, delete_mode = 0;
1749 + int push_mode = 0, add_mode = 0, delete_mode = 0;
1750 int matches = 0, negative_matches = 0;
1751 const char *remotename = NULL;
1752 const char *newurl = NULL;
@@ -1818,7 +1810,7 @@ static int set_url(int argc, const char **argv, const char *prefix,
1810 if (regcomp(&old_regex, oldurl, REG_EXTENDED))
1811 die(_("Invalid old URL pattern: %s"), oldurl);
1812
1821 - for (i = 0; i < urlset->nr; i++)
1813 + for (size_t i = 0; i < urlset->nr; i++)
1814 if (!regexec(&old_regex, urlset->v[i], 0, NULL, 0))
1815 matches++;
1816 else