global: trivial conversions to fix `-Wsign-compare` warnings

We have a bunch of loops which iterate up to an unsigned boundary using a signed index, which generates warnigs because we compare a signed and unsigned value in the loop condition. Address these sites for trivial cases and enable `-Wsign-compare` warnings for these code units. This patch only adapts those code units where we can drop the `DISABLE_SIGN_COMPARE_WARNINGS` macro in the same step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 6, 2024 at 11:27 UTC 80c9e70ebe871f0826bc101142c66ff783405100
55 files changed +105 -238
advice.c
+2 -7
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "advice.h"
3 #include "config.h"
@@ -162,7 +160,6 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...)
160 int git_default_advice_config(const char *var, const char *value)
161 {
162 const char *k, *slot_name;
165 - int i;
163
164 if (!strcmp(var, "color.advice")) {
165 advice_use_color = git_config_colorbool(var, value);
@@ -181,7 +178,7 @@ int git_default_advice_config(const char *var, const char *value)
178 if (!skip_prefix(var, "advice.", &k))
179 return 0;
180
184 - for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
181 + for (size_t i = 0; i < ARRAY_SIZE(advice_setting); i++) {
182 if (strcasecmp(k, advice_setting[i].key))
183 continue;
184 advice_setting[i].level = git_config_bool(var, value)
@@ -195,9 +192,7 @@ int git_default_advice_config(const char *var, const char *value)
192
193 void list_config_advices(struct string_list *list, const char *prefix)
194 {
198 - int i;
199 -
200 - for (i = 0; i < ARRAY_SIZE(advice_setting); i++)
195 + for (size_t i = 0; i < ARRAY_SIZE(advice_setting); i++)
196 list_config_item(list, prefix, advice_setting[i].key);
197 }
198
base85.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "base85.h"
3
@@ -31,10 +29,9 @@ static const char en85[] = {
29 static char de85[256];
30 static void prep_base85(void)
31 {
34 - int i;
32 if (de85['Z'])
33 return;
37 - for (i = 0; i < ARRAY_SIZE(en85); i++) {
34 + for (size_t i = 0; i < ARRAY_SIZE(en85); i++) {
35 int ch = en85[i];
36 de85[ch] = i + 1;
37 }
builtin/add.c
+4 -6
@@ -4,8 +4,6 @@
4 * Copyright (C) 2006 Linus Torvalds
5 */
6
7 -#define DISABLE_SIGN_COMPARE_WARNINGS
8 -
7 #include "builtin.h"
8 #include "advice.h"
9 #include "config.h"
@@ -42,9 +40,9 @@ static int chmod_pathspec(struct repository *repo,
40 char flip,
41 int show_only)
42 {
45 - int i, ret = 0;
43 + int ret = 0;
44
47 - for (i = 0; i < repo->index->cache_nr; i++) {
45 + for (size_t i = 0; i < repo->index->cache_nr; i++) {
46 struct cache_entry *ce = repo->index->cache[i];
47 int err;
48
@@ -72,9 +70,9 @@ static int renormalize_tracked_files(struct repository *repo,
70 const struct pathspec *pathspec,
71 int flags)
72 {
75 - int i, retval = 0;
73 + int retval = 0;
74
77 - for (i = 0; i < repo->index->cache_nr; i++) {
75 + for (size_t i = 0; i < repo->index->cache_nr; i++) {
76 struct cache_entry *ce = repo->index->cache[i];
77
78 if (!include_sparse &&
builtin/branch.c
-1
@@ -6,7 +6,6 @@
6 */
7
8 #define USE_THE_REPOSITORY_VARIABLE
9 -#define DISABLE_SIGN_COMPARE_WARNINGS
9
10 #include "builtin.h"
11 #include "config.h"
builtin/difftool.c
+2 -2
@@ -13,7 +13,6 @@
13 */
14
15 #define USE_THE_REPOSITORY_VARIABLE
16 -#define DISABLE_SIGN_COMPARE_WARNINGS
16
17 #include "builtin.h"
18
@@ -367,7 +366,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
366 char *lbase_dir = NULL, *rbase_dir = NULL;
367 size_t ldir_len, rdir_len, wtdir_len;
368 const char *workdir, *tmp;
370 - int ret = 0, i;
369 + int ret = 0;
370 + size_t i;
371 FILE *fp = NULL;
372 struct hashmap working_tree_dups = HASHMAP_INIT(working_tree_entry_cmp,
373 NULL);
builtin/for-each-repo.c
+2 -3
@@ -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"
@@ -38,7 +37,7 @@ int cmd_for_each_repo(int argc,
37 {
38 static const char *config_key = NULL;
39 int keep_going = 0;
41 - int i, result = 0;
40 + int result = 0;
41 const struct string_list *values;
42 int err;
43
@@ -63,7 +62,7 @@ int cmd_for_each_repo(int argc,
62 else if (err)
63 return 0;
64
66 - for (i = 0; i < values->nr; i++) {
65 + for (size_t i = 0; i < values->nr; i++) {
66 int ret = run_command_on_repo(values->items[i].string, argc, argv);
67 if (ret) {
68 if (!keep_going)
builtin/help.c
+1 -3
@@ -3,7 +3,6 @@
3 */
4
5 #define USE_THE_REPOSITORY_VARIABLE
6 -#define DISABLE_SIGN_COMPARE_WARNINGS
6
7 #include "builtin.h"
8 #include "config.h"
@@ -131,7 +130,6 @@ static void list_config_help(enum show_config_type type)
130 struct string_list keys = STRING_LIST_INIT_DUP;
131 struct string_list keys_uniq = STRING_LIST_INIT_DUP;
132 struct string_list_item *item;
134 - int i;
133
134 for (p = config_name_list; *p; p++) {
135 const char *var = *p;
@@ -158,7 +156,7 @@ static void list_config_help(enum show_config_type type)
156 e->prefix, e->placeholder);
157
158 string_list_sort(&keys);
161 - for (i = 0; i < keys.nr; i++) {
159 + for (size_t i = 0; i < keys.nr; i++) {
160 const char *var = keys.items[i].string;
161 const char *wildcard, *tag, *cut;
162 const char *dot = NULL;
builtin/mailsplit.c
+1 -2
@@ -175,7 +175,6 @@ static int split_maildir(const char *maildir, const char *dir,
175 char *file = NULL;
176 FILE *f = NULL;
177 int ret = -1;
178 - int i;
178 struct string_list list = STRING_LIST_INIT_DUP;
179
180 list.cmp = maildir_filename_cmp;
@@ -183,7 +182,7 @@ static int split_maildir(const char *maildir, const char *dir,
182 if (populate_maildir_list(&list, maildir) < 0)
183 goto out;
184
186 - for (i = 0; i < list.nr; i++) {
185 + for (size_t i = 0; i < list.nr; i++) {
186 char *name;
187
188 free(file);
builtin/merge-tree.c
+2 -4
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "builtin.h"
4 #include "tree-walk.h"
@@ -499,10 +498,9 @@ static int real_merge(struct merge_tree_options *o,
498 if (!result.clean) {
499 struct string_list conflicted_files = STRING_LIST_INIT_NODUP;
500 const char *last = NULL;
502 - int i;
501
502 merge_get_conflicted_files(&result, &conflicted_files);
505 - for (i = 0; i < conflicted_files.nr; i++) {
503 + for (size_t i = 0; i < conflicted_files.nr; i++) {
504 const char *name = conflicted_files.items[i].string;
505 struct stage_info *c = conflicted_files.items[i].util;
506 if (!o->name_only)
@@ -586,7 +584,7 @@ int cmd_merge_tree(int argc,
584
585 if (xopts.nr && o.mode == MODE_TRIVIAL)
586 die(_("--trivial-merge is incompatible with all other options"));
589 - for (int x = 0; x < xopts.nr; x++)
587 + for (size_t x = 0; x < xopts.nr; x++)
588 if (parse_merge_opt(&o.merge_options, xopts.v[x]))
589 die(_("unknown strategy option: -X%s"), xopts.v[x]);
590
builtin/pack-redundant.c
+1 -3
@@ -7,7 +7,6 @@
7 */
8
9 #define USE_THE_REPOSITORY_VARIABLE
10 -#define DISABLE_SIGN_COMPARE_WARNINGS
10
11 #include "builtin.h"
12 #include "gettext.h"
@@ -391,7 +390,6 @@ static int cmp_remaining_objects(const void *a, const void *b)
390 static void sort_pack_list(struct pack_list **pl)
391 {
392 struct pack_list **ary, *p;
394 - int i;
393 size_t n = pack_list_size(*pl);
394
395 if (n < 2)
@@ -405,7 +403,7 @@ static void sort_pack_list(struct pack_list **pl)
403 QSORT(ary, n, cmp_remaining_objects);
404
405 /* link them back again */
408 - for (i = 0; i < n - 1; i++)
406 + for (size_t i = 0; i < n - 1; i++)
407 ary[i]->next = ary[i + 1];
408 ary[n - 1]->next = NULL;
409 *pl = ary[0];
builtin/pull.c
+1 -3
@@ -7,7 +7,6 @@
7 */
8
9 #define USE_THE_REPOSITORY_VARIABLE
10 -#define DISABLE_SIGN_COMPARE_WARNINGS
10
11 #include "builtin.h"
12 #include "advice.h"
@@ -943,11 +942,10 @@ static int get_can_ff(struct object_id *orig_head,
942 static int already_up_to_date(struct object_id *orig_head,
943 struct oid_array *merge_heads)
944 {
946 - int i;
945 struct commit *ours;
946
947 ours = lookup_commit_reference(the_repository, orig_head);
950 - for (i = 0; i < merge_heads->nr; i++) {
948 + for (size_t i = 0; i < merge_heads->nr; i++) {
949 struct commit_list *list = NULL;
950 struct commit *theirs;
951 int ok;
builtin/push.c
+2 -3
@@ -3,7 +3,6 @@
3 */
4
5 #define USE_THE_REPOSITORY_VARIABLE
6 -#define DISABLE_SIGN_COMPARE_WARNINGS
6
7 #include "builtin.h"
8 #include "advice.h"
@@ -420,7 +419,7 @@ static int do_push(int flags,
419 const struct string_list *push_options,
420 struct remote *remote)
421 {
423 - int i, errs;
422 + int errs;
423 struct strvec *url;
424 struct refspec *push_refspec = &rs;
425
@@ -435,7 +434,7 @@ static int do_push(int flags,
434 }
435 errs = 0;
436 url = push_url_of_remote(remote);
438 - for (i = 0; i < url->nr; i++) {
437 + for (size_t i = 0; i < url->nr; i++) {
438 struct transport *transport =
439 transport_get(remote, url->v[i]);
440 if (flags & TRANSPORT_PUSH_OPTIONS)
builtin/rerere.c
+4 -5
@@ -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"
@@ -57,7 +56,7 @@ int cmd_rerere(int argc,
56 struct repository *repo UNUSED)
57 {
58 struct string_list merge_rr = STRING_LIST_INIT_DUP;
60 - int i, autoupdate = -1, flags = 0;
59 + int autoupdate = -1, flags = 0;
60
61 struct option options[] = {
62 OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
@@ -100,11 +99,11 @@ int cmd_rerere(int argc,
99 if (setup_rerere(the_repository, &merge_rr,
100 flags | RERERE_READONLY) < 0)
101 return 0;
103 - for (i = 0; i < merge_rr.nr; i++)
102 + for (size_t i = 0; i < merge_rr.nr; i++)
103 printf("%s\n", merge_rr.items[i].string);
104 } else if (!strcmp(argv[0], "remaining")) {
105 rerere_remaining(the_repository, &merge_rr);
107 - for (i = 0; i < merge_rr.nr; i++) {
106 + for (size_t i = 0; i < merge_rr.nr; i++) {
107 if (merge_rr.items[i].util != RERERE_RESOLVED)
108 printf("%s\n", merge_rr.items[i].string);
109 else
@@ -116,7 +115,7 @@ int cmd_rerere(int argc,
115 if (setup_rerere(the_repository, &merge_rr,
116 flags | RERERE_READONLY) < 0)
117 return 0;
119 - for (i = 0; i < merge_rr.nr; i++) {
118 + for (size_t i = 0; i < merge_rr.nr; i++) {
119 const char *path = merge_rr.items[i].string;
120 const struct rerere_id *id = merge_rr.items[i].util;
121 if (diff_two(rerere_path(id, "preimage"), path, path, path))
builtin/stash.c
+2 -5
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "builtin.h"
4 #include "abspath.h"
@@ -875,9 +874,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
874 struct tree *tree[ARRAY_SIZE(oid)];
875 struct tree_desc tree_desc[ARRAY_SIZE(oid)];
876 struct unpack_trees_options unpack_tree_opt = { 0 };
878 - int i;
877
880 - for (i = 0; i < ARRAY_SIZE(oid); i++) {
878 + for (size_t i = 0; i < ARRAY_SIZE(oid); i++) {
879 tree[i] = parse_tree_indirect(oid[i]);
880 if (parse_tree(tree[i]) < 0)
881 die(_("failed to parse tree"));
@@ -1559,12 +1557,11 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
1557
1558 repo_read_index_preload(the_repository, NULL, 0);
1559 if (!include_untracked && ps->nr) {
1562 - int i;
1560 char *ps_matched = xcalloc(ps->nr, 1);
1561
1562 /* TODO: audit for interaction with sparse-index. */
1563 ensure_full_index(the_repository->index);
1567 - for (i = 0; i < the_repository->index->cache_nr; i++)
1564 + for (size_t i = 0; i < the_repository->index->cache_nr; i++)
1565 ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
1566 ps_matched);
1567
builtin/submodule--helper.c
+3 -5
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "builtin.h"
4 #include "abspath.h"
@@ -196,7 +195,7 @@ static int module_list_compute(const char **argv,
195 struct pathspec *pathspec,
196 struct module_list *list)
197 {
199 - int i, result = 0;
198 + int result = 0;
199 char *ps_matched = NULL;
200
201 parse_pathspec(pathspec, 0,
@@ -209,7 +208,7 @@ static int module_list_compute(const char **argv,
208 if (repo_read_index(the_repository) < 0)
209 die(_("index file corrupt"));
210
212 - for (i = 0; i < the_repository->index->cache_nr; i++) {
211 + for (size_t i = 0; i < the_repository->index->cache_nr; i++) {
212 const struct cache_entry *ce = the_repository->index->cache[i];
213
214 if (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce),
@@ -3398,7 +3397,6 @@ static void die_on_index_match(const char *path, int force)
3397 die(_("index file corrupt"));
3398
3399 if (ps.nr) {
3401 - int i;
3400 char *ps_matched = xcalloc(ps.nr, 1);
3401
3402 /* TODO: audit for interaction with sparse-index. */
@@ -3408,7 +3406,7 @@ static void die_on_index_match(const char *path, int force)
3406 * Since there is only one pathspec, we just need to
3407 * check ps_matched[0] to know if a cache entry matched.
3408 */
3411 - for (i = 0; i < the_repository->index->cache_nr; i++) {
3409 + for (size_t i = 0; i < the_repository->index->cache_nr; i++) {
3410 ce_path_match(the_repository->index, the_repository->index->cache[i], &ps,
3411 ps_matched);
3412
builtin/var.c
+1 -3
@@ -5,7 +5,6 @@
5 */
6
7 #define USE_THE_REPOSITORY_VARIABLE
8 -#define DISABLE_SIGN_COMPARE_WARNINGS
8
9 #include "builtin.h"
10
@@ -181,10 +180,9 @@ static void list_vars(void)
180 if ((val = ptr->read(0))) {
181 if (ptr->multivalued && *val) {
182 struct string_list list = STRING_LIST_INIT_DUP;
184 - int i;
183
184 string_list_split(&list, val, '\n', -1);
187 - for (i = 0; i < list.nr; i++)
185 + for (size_t i = 0; i < list.nr; i++)
186 printf("%s=%s\n", ptr->name, list.items[i].string);
187 string_list_clear(&list, 0);
188 } else {
commit.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "tag.h"
@@ -1766,7 +1765,6 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1765 { &compat_sig, r->compat_hash_algo },
1766 { &sig, r->hash_algo },
1767 };
1769 - int i;
1768
1769 /*
1770 * We write algorithms in the order they were implemented in
@@ -1780,7 +1778,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1778 * We traverse each algorithm in order, and apply the signature
1779 * to each buffer.
1780 */
1783 - for (i = 0; i < ARRAY_SIZE(bufs); i++) {
1781 + for (size_t i = 0; i < ARRAY_SIZE(bufs); i++) {
1782 if (!bufs[i].algo)
1783 continue;
1784 add_header_signature(&buffer, bufs[i].sig, bufs[i].algo);
compat/fsmonitor/fsm-listen-darwin.c
+1 -4
@@ -23,8 +23,6 @@
23 #endif
24 #endif
25
26 -#define DISABLE_SIGN_COMPARE_WARNINGS
27 -
26 #include "git-compat-util.h"
27 #include "fsmonitor-ll.h"
28 #include "fsm-listen.h"
@@ -210,13 +208,12 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef UNUSED,
208 const char *slash;
209 char *resolved = NULL;
210 struct strbuf tmp = STRBUF_INIT;
213 - int k;
211
212 /*
213 * Build a list of all filesystem changes into a private/local
214 * list and without holding any locks.
215 */
219 - for (k = 0; k < num_of_events; k++) {
216 + for (size_t k = 0; k < num_of_events; k++) {
217 /*
218 * On Mac, we receive an array of absolute paths.
219 */
compat/terminal.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "compat/terminal.h"
3 #include "gettext.h"
@@ -261,14 +259,13 @@ static DWORD cmode_in, cmode_out;
259 void restore_term(void)
260 {
261 if (use_stty) {
264 - int i;
262 struct child_process cp = CHILD_PROCESS_INIT;
263
264 if (stty_restore.nr == 0)
265 return;
266
267 strvec_push(&cp.args, "stty");
271 - for (i = 0; i < stty_restore.nr; i++)
268 + for (size_t i = 0; i < stty_restore.nr; i++)
269 strvec_push(&cp.args, stty_restore.items[i].string);
270 run_command(&cp);
271 string_list_clear(&stty_restore, 0);
diagnose.c
+3 -5
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "diagnose.h"
@@ -32,7 +31,6 @@ static struct diagnose_option diagnose_options[] = {
31
32 int option_parse_diagnose(const struct option *opt, const char *arg, int unset)
33 {
35 - int i;
34 enum diagnose_mode *diagnose = opt->value;
35
36 if (!arg) {
@@ -40,7 +38,7 @@ int option_parse_diagnose(const struct option *opt, const char *arg, int unset)
38 return 0;
39 }
40
43 - for (i = 0; i < ARRAY_SIZE(diagnose_options); i++) {
41 + for (size_t i = 0; i < ARRAY_SIZE(diagnose_options); i++) {
42 if (!strcmp(arg, diagnose_options[i].option_name)) {
43 *diagnose = diagnose_options[i].mode;
44 return 0;
@@ -187,7 +185,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
185 char **argv_copy = NULL;
186 int stdout_fd = -1, archiver_fd = -1;
187 struct strbuf buf = STRBUF_INIT;
190 - int res, i;
188 + int res;
189 struct archive_dir archive_dirs[] = {
190 { ".git", 0 },
191 { ".git/hooks", 0 },
@@ -240,7 +238,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
238
239 /* Only include this if explicitly requested */
240 if (mode == DIAGNOSE_ALL) {
243 - for (i = 0; i < ARRAY_SIZE(archive_dirs); i++) {
241 + for (size_t i = 0; i < ARRAY_SIZE(archive_dirs); i++) {
242 if (add_directory_to_archiver(&archiver_args,
243 archive_dirs[i].path,
244 archive_dirs[i].recursive)) {
diffcore-rename.c
+1 -3
@@ -4,7 +4,6 @@
4 */
5
6 #define USE_THE_REPOSITORY_VARIABLE
7 -#define DISABLE_SIGN_COMPARE_WARNINGS
7
8 #include "git-compat-util.h"
9 #include "diff.h"
@@ -689,7 +688,6 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
688 struct hashmap_iter iter;
689 struct strmap_entry *entry;
690 struct string_list to_remove = STRING_LIST_INIT_NODUP;
692 - int i;
691
692 if (!info->setup)
693 return;
@@ -735,7 +733,7 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
733 if (strintmap_contains(counts, UNKNOWN_DIR))
734 strintmap_remove(counts, UNKNOWN_DIR);
735 }
738 - for (i = 0; i < to_remove.nr; ++i)
736 + for (size_t i = 0; i < to_remove.nr; ++i)
737 strmap_remove(info->dir_rename_count,
738 to_remove.items[i].string, 1);
739 string_list_clear(&to_remove, 0);
entry.c
+2 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "object-store-ll.h"
@@ -442,7 +441,7 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
441 static void mark_colliding_entries(const struct checkout *state,
442 struct cache_entry *ce, struct stat *st)
443 {
445 - int i, trust_ino = check_stat;
444 + int trust_ino = check_stat;
445
446 #if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__)
447 trust_ino = 0;
@@ -452,7 +451,7 @@ static void mark_colliding_entries(const struct checkout *state,
451
452 /* TODO: audit for interaction with sparse-index. */
453 ensure_full_index(state->istate);
455 - for (i = 0; i < state->istate->cache_nr; i++) {
454 + for (size_t i = 0; i < state->istate->cache_nr; i++) {
455 struct cache_entry *dup = state->istate->cache[i];
456
457 if (dup == ce) {
ewah/ewah_bitmap.c
+1 -5
@@ -17,8 +17,6 @@
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 -#define DISABLE_SIGN_COMPARE_WARNINGS
21 -
20 #include "git-compat-util.h"
21 #include "ewok.h"
22 #include "ewok_rlw.h"
@@ -258,10 +256,8 @@ void ewah_each_bit(struct ewah_bitmap *self, void (*callback)(size_t, void*), vo
256 ++pointer;
257
258 for (k = 0; k < rlw_get_literal_words(word); ++k) {
261 - int c;
262 -
259 /* todo: zero count optimization */
264 - for (c = 0; c < BITS_IN_EWORD; ++c, ++pos) {
260 + for (size_t c = 0; c < BITS_IN_EWORD; ++c, ++pos) {
261 if ((self->buffer[pointer] & ((eword_t)1 << c)) != 0)
262 callback(pos, payload);
263 }
git.c
+13 -20
@@ -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"
@@ -56,7 +55,7 @@ static void list_builtins(struct string_list *list, unsigned int exclude_option)
55
56 static void exclude_helpers_from_list(struct string_list *list)
57 {
59 - int i = 0;
58 + size_t i = 0;
59
60 while (i < list->nr) {
61 if (strstr(list->items[i].string, "--"))
@@ -76,7 +75,6 @@ static int match_token(const char *spec, int len, const char *token)
75 static int list_cmds(const char *spec)
76 {
77 struct string_list list = STRING_LIST_INIT_DUP;
79 - int i;
78 int nongit;
79
80 /*
@@ -114,7 +112,7 @@ static int list_cmds(const char *spec)
112 if (*spec == ',')
113 spec++;
114 }
117 - for (i = 0; i < list.nr; i++)
115 + for (size_t i = 0; i < list.nr; i++)
116 puts(list.items[i].string);
117 string_list_clear(&list, 0);
118 return 0;
@@ -323,10 +321,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
321 trace2_cmd_name("_query_");
322 if (!strcmp(cmd, "parseopt")) {
323 struct string_list list = STRING_LIST_INIT_DUP;
326 - int i;
324
325 list_builtins(&list, NO_PARSEOPT);
329 - for (i = 0; i < list.nr; i++)
326 + for (size_t i = 0; i < list.nr; i++)
327 printf("%s ", list.items[i].string);
328 string_list_clear(&list, 0);
329 exit(0);
@@ -652,8 +649,7 @@ static struct cmd_struct commands[] = {
649
650 static struct cmd_struct *get_builtin(const char *s)
651 {
655 - int i;
656 - for (i = 0; i < ARRAY_SIZE(commands); i++) {
652 + for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
653 struct cmd_struct *p = commands + i;
654 if (!strcmp(s, p->cmd))
655 return p;
@@ -668,8 +664,7 @@ int is_builtin(const char *s)
664
665 static void list_builtins(struct string_list *out, unsigned int exclude_option)
666 {
671 - int i;
672 - for (i = 0; i < ARRAY_SIZE(commands); i++) {
667 + for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
668 if (exclude_option &&
669 (commands[i].option & exclude_option))
670 continue;
@@ -680,7 +675,6 @@ static void list_builtins(struct string_list *out, unsigned int exclude_option)
675 void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
676 {
677 const char *name;
683 - int i;
678
679 /*
680 * Callers can ask for a subset of the commands based on a certain
@@ -691,7 +685,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
685 if (!skip_prefix(prefix, "git-", &prefix))
686 BUG("prefix '%s' must start with 'git-'", prefix);
687
694 - for (i = 0; i < ARRAY_SIZE(commands); i++)
688 + for (size_t i = 0; i < ARRAY_SIZE(commands); i++)
689 if (skip_prefix(commands[i].cmd, prefix, &name))
690 add_cmdname(cmds, name, strlen(name));
691 }
@@ -813,7 +807,7 @@ static int run_argv(struct strvec *args)
807 handle_builtin(args);
808 else if (get_builtin(args->v[0])) {
809 struct child_process cmd = CHILD_PROCESS_INIT;
816 - int i;
810 + int err;
811
812 /*
813 * The current process is committed to launching a
@@ -827,7 +821,7 @@ static int run_argv(struct strvec *args)
821 commit_pager_choice();
822
823 strvec_push(&cmd.args, "git");
830 - for (i = 0; i < args->nr; i++)
824 + for (size_t i = 0; i < args->nr; i++)
825 strvec_push(&cmd.args, args->v[i]);
826
827 trace_argv_printf(cmd.args.v, "trace: exec:");
@@ -840,9 +834,9 @@ static int run_argv(struct strvec *args)
834 cmd.clean_on_exit = 1;
835 cmd.wait_after_clean = 1;
836 cmd.trace2_child_class = "git_alias";
843 - i = run_command(&cmd);
844 - if (i >= 0 || errno != ENOENT)
845 - exit(i);
837 + err = run_command(&cmd);
838 + if (err >= 0 || errno != ENOENT)
839 + exit(err);
840 die("could not execute builtin %s", args->v[0]);
841 }
842
@@ -851,9 +845,8 @@ static int run_argv(struct strvec *args)
845
846 seen = unsorted_string_list_lookup(&cmd_list, args->v[0]);
847 if (seen) {
854 - int i;
848 struct strbuf sb = STRBUF_INIT;
856 - for (i = 0; i < cmd_list.nr; i++) {
849 + for (size_t i = 0; i < cmd_list.nr; i++) {
850 struct string_list_item *item = &cmd_list.items[i];
851
852 strbuf_addf(&sb, "\n %s", item->string);
@@ -947,7 +940,7 @@ int cmd_main(int argc, const char **argv)
940 */
941 setup_path();
942
950 - for (size_t i = 0; i < argc; i++)
943 + for (int i = 0; i < argc; i++)
944 strvec_push(&args, argv[i]);
945
946 while (1) {
help.h
+3 -5
@@ -60,8 +60,7 @@ static inline void list_config_item(struct string_list *list,
60 #define define_list_config_array(array) \
61 void list_config_##array(struct string_list *list, const char *prefix) \
62 { \
63 - int i; \
64 - for (i = 0; i < ARRAY_SIZE(array); i++) \
63 + for (size_t i = 0; i < ARRAY_SIZE(array); i++) \
64 if (array[i]) \
65 list_config_item(list, prefix, array[i]); \
66 } \
@@ -70,11 +69,10 @@ struct string_list
69 #define define_list_config_array_extra(array, values) \
70 void list_config_##array(struct string_list *list, const char *prefix) \
71 { \
73 - int i; \
72 static const char *extra[] = values; \
75 - for (i = 0; i < ARRAY_SIZE(extra); i++) \
73 + for (size_t i = 0; i < ARRAY_SIZE(extra); i++) \
74 list_config_item(list, prefix, extra[i]); \
77 - for (i = 0; i < ARRAY_SIZE(array); i++) \
75 + for (size_t i = 0; i < ARRAY_SIZE(array); i++) \
76 if (array[i]) \
77 list_config_item(list, prefix, array[i]); \
78 } \
hex.c
+2 -5
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "hash.h"
@@ -8,8 +7,7 @@
7 static int get_hash_hex_algop(const char *hex, unsigned char *hash,
8 const struct git_hash_algo *algop)
9 {
11 - int i;
12 - for (i = 0; i < algop->rawsz; i++) {
10 + for (size_t i = 0; i < algop->rawsz; i++) {
11 int val = hex2chr(hex);
12 if (val < 0)
13 return -1;
@@ -84,7 +82,6 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
82 {
83 static const char hex[] = "0123456789abcdef";
84 char *buf = buffer;
87 - int i;
85
86 /*
87 * Our struct object_id has been memset to 0, so default to printing
@@ -93,7 +90,7 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
90 if (algop == &hash_algos[0])
91 algop = the_hash_algo;
92
96 - for (i = 0; i < algop->rawsz; i++) {
93 + for (size_t i = 0; i < algop->rawsz; i++) {
94 unsigned int val = *hash++;
95 *buf++ = hex[val >> 4];
96 *buf++ = hex[val & 0xf];
http-push.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "environment.h"
@@ -1339,7 +1338,6 @@ static struct object_list **process_tree(struct tree *tree,
1338
1339 static int get_delta(struct rev_info *revs, struct remote_lock *lock)
1340 {
1342 - int i;
1341 struct commit *commit;
1342 struct object_list **p = &objects;
1343 int count = 0;
@@ -1352,7 +1350,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
1350 count += add_send_request(&commit->object, lock);
1351 }
1352
1355 - for (i = 0; i < revs->pending.nr; i++) {
1353 + for (size_t i = 0; i < revs->pending.nr; i++) {
1354 struct object_array_entry *entry = revs->pending.objects + i;
1355 struct object *obj = entry->item;
1356 const char *name = entry->name;
list-objects-filter-options.c
+1 -4
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "config.h"
@@ -395,8 +394,6 @@ void list_objects_filter_copy(
394 struct list_objects_filter_options *dest,
395 const struct list_objects_filter_options *src)
396 {
398 - int i;
399 -
397 /* Copy everything. We will overwrite the pointers shortly. */
398 memcpy(dest, src, sizeof(struct list_objects_filter_options));
399
@@ -405,7 +402,7 @@ void list_objects_filter_copy(
402 dest->sparse_oid_name = xstrdup_or_null(src->sparse_oid_name);
403
404 ALLOC_ARRAY(dest->sub, dest->sub_alloc);
408 - for (i = 0; i < src->sub_nr; i++)
405 + for (size_t i = 0; i < src->sub_nr; i++)
406 list_objects_filter_copy(&dest->sub[i], &src->sub[i]);
407 }
408
list-objects.c
+2 -6
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "tag.h"
@@ -284,7 +283,6 @@ void mark_edges_uninteresting(struct rev_info *revs,
283 int sparse)
284 {
285 struct commit_list *list;
287 - int i;
286
287 if (sparse) {
288 struct oidset set;
@@ -321,7 +319,7 @@ void mark_edges_uninteresting(struct rev_info *revs,
319 }
320
321 if (revs->edge_hint_aggressive) {
324 - for (i = 0; i < revs->cmdline.nr; i++) {
322 + for (size_t i = 0; i < revs->cmdline.nr; i++) {
323 struct object *obj = revs->cmdline.rev[i].item;
324 struct commit *commit = (struct commit *)obj;
325 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
@@ -344,11 +342,9 @@ static void add_pending_tree(struct rev_info *revs, struct tree *tree)
342 static void traverse_non_commits(struct traversal_context *ctx,
343 struct strbuf *base)
344 {
347 - int i;
348 -
345 assert(base->len == 0);
346
351 - for (i = 0; i < ctx->revs->pending.nr; i++) {
347 + for (size_t i = 0; i < ctx->revs->pending.nr; i++) {
348 struct object_array_entry *pending = ctx->revs->pending.objects + i;
349 struct object *obj = pending->item;
350 const char *name = pending->name;
ls-refs.c
+1 -4
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "environment.h"
@@ -54,12 +53,10 @@ static enum {
53 */
54 static int ref_match(const struct strvec *prefixes, const char *refname)
55 {
57 - int i;
58 -
56 if (!prefixes->nr)
57 return 1; /* no restriction */
58
62 - for (i = 0; i < prefixes->nr; i++) {
59 + for (size_t i = 0; i < prefixes->nr; i++) {
60 const char *prefix = prefixes->v[i];
61
62 if (starts_with(refname, prefix))
merge.c
+2 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "gettext.h"
@@ -26,11 +25,11 @@ int try_merge_command(struct repository *r,
25 const char *head_arg, struct commit_list *remotes)
26 {
27 struct child_process cmd = CHILD_PROCESS_INIT;
29 - int i, ret;
28 + int ret;
29 struct commit_list *j;
30
31 strvec_pushf(&cmd.args, "merge-%s", strategy);
33 - for (i = 0; i < xopts_nr; i++)
32 + for (size_t i = 0; i < xopts_nr; i++)
33 strvec_pushf(&cmd.args, "--%s", xopts[i]);
34 for (j = common; j; j = j->next)
35 strvec_push(&cmd.args, merge_argument(j->item));
path.c
+2 -3
@@ -3,7 +3,6 @@
3 */
4
5 #define USE_THE_REPOSITORY_VARIABLE
6 -#define DISABLE_SIGN_COMPARE_WARNINGS
6
7 #include "git-compat-util.h"
8 #include "abspath.h"
@@ -1141,12 +1140,12 @@ int strbuf_normalize_path(struct strbuf *src)
1140 */
1141 int longest_ancestor_length(const char *path, struct string_list *prefixes)
1142 {
1144 - int i, max_len = -1;
1143 + int max_len = -1;
1144
1145 if (!strcmp(path, "/"))
1146 return -1;
1147
1149 - for (i = 0; i < prefixes->nr; i++) {
1148 + for (size_t i = 0; i < prefixes->nr; i++) {
1149 const char *ceil = prefixes->items[i].string;
1150 int len = strlen(ceil);
1151
pkt-line.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "copy.h"
3 #include "pkt-line.h"
@@ -41,7 +39,6 @@ static int packet_trace_pack(const char *buf, unsigned int len, int sideband)
39
40 static void packet_trace(const char *buf, unsigned int len, int write)
41 {
44 - int i;
42 struct strbuf out;
43 static int in_pack, sideband;
44
@@ -74,7 +71,7 @@ static void packet_trace(const char *buf, unsigned int len, int write)
71 get_trace_prefix(), write ? '>' : '<');
72
73 /* XXX we should really handle printable utf8 */
77 - for (i = 0; i < len; i++) {
74 + for (unsigned int i = 0; i < len; i++) {
75 /* suppress newlines */
76 if (buf[i] == '\n')
77 continue;
refs/debug.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "hex.h"
3 #include "refs-internal.h"
@@ -85,9 +83,8 @@ static void print_update(int i, const char *refname,
83
84 static void print_transaction(struct ref_transaction *transaction)
85 {
88 - int i;
86 trace_printf_key(&trace_refs, "transaction {\n");
90 - for (i = 0; i < transaction->nr; i++) {
87 + for (size_t i = 0; i < transaction->nr; i++) {
88 struct ref_update *u = transaction->updates[i];
89 print_update(i, u->refname, &u->old_oid, &u->new_oid, u->flags,
90 u->type, u->msg);
send-pack.c
+2 -4
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "config.h"
@@ -73,7 +72,6 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
72 */
73 struct child_process po = CHILD_PROCESS_INIT;
74 FILE *po_in;
76 - int i;
75 int rc;
76
77 trace2_region_enter("send_pack", "pack_objects", the_repository);
@@ -105,9 +103,9 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
103 * parameters by writing to the pipe.
104 */
105 po_in = xfdopen(po.in, "w");
108 - for (i = 0; i < advertised->nr; i++)
106 + for (size_t i = 0; i < advertised->nr; i++)
107 feed_object(&advertised->oid[i], po_in, 1);
110 - for (i = 0; i < negotiated->nr; i++)
108 + for (size_t i = 0; i < negotiated->nr; i++)
109 feed_object(&negotiated->oid[i], po_in, 1);
110
111 while (refs) {
serve.c
+2 -6
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "repository.h"
@@ -164,12 +163,11 @@ void protocol_v2_advertise_capabilities(void)
163 {
164 struct strbuf capability = STRBUF_INIT;
165 struct strbuf value = STRBUF_INIT;
167 - int i;
166
167 /* serve by default supports v2 */
168 packet_write_fmt(1, "version 2\n");
169
172 - for (i = 0; i < ARRAY_SIZE(capabilities); i++) {
170 + for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) {
171 struct protocol_capability *c = &capabilities[i];
172
173 if (c->advertise(the_repository, &value)) {
@@ -195,12 +193,10 @@ void protocol_v2_advertise_capabilities(void)
193
194 static struct protocol_capability *get_capability(const char *key, const char **value)
195 {
198 - int i;
199 -
196 if (!key)
197 return NULL;
198
203 - for (i = 0; i < ARRAY_SIZE(capabilities); i++) {
199 + for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) {
200 struct protocol_capability *c = &capabilities[i];
201 const char *out;
202 if (!skip_prefix(key, c->name, &out))
strvec.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "strvec.h"
3 #include "strbuf.h"
@@ -129,8 +127,7 @@ void strvec_split(struct strvec *array, const char *to_split)
127 void strvec_clear(struct strvec *array)
128 {
129 if (array->v != empty_strvec) {
132 - int i;
133 - for (i = 0; i < array->nr; i++)
130 + for (size_t i = 0; i < array->nr; i++)
131 free((char *)array->v[i]);
132 free(array->v);
133 }
t/helper/test-bloom.c
+2 -8
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "bloom.h"
@@ -12,30 +11,25 @@ static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
11
12 static void add_string_to_filter(const char *data, struct bloom_filter *filter) {
13 struct bloom_key key;
15 - int i;
14
15 fill_bloom_key(data, strlen(data), &key, &settings);
16 printf("Hashes:");
19 - for (i = 0; i < settings.num_hashes; i++){
17 + for (size_t i = 0; i < settings.num_hashes; i++)
18 printf("0x%08x|", key.hashes[i]);
21 - }
19 printf("\n");
20 add_key_to_filter(&key, filter, &settings);
21 clear_bloom_key(&key);
22 }
23
24 static void print_bloom_filter(struct bloom_filter *filter) {
28 - int i;
29 -
25 if (!filter) {
26 printf("No filter.\n");
27 return;
28 }
29 printf("Filter_Length:%d\n", (int)filter->len);
30 printf("Filter_Data:");
36 - for (i = 0; i < filter->len; i++) {
31 + for (size_t i = 0; i < filter->len; i++)
32 printf("%02x|", filter->data[i]);
38 - }
33 printf("\n");
34 }
35
t/helper/test-dump-fsmonitor.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "read-cache-ll.h"
@@ -9,7 +8,6 @@
8 int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED)
9 {
10 struct index_state *istate = the_repository->index;
12 - int i;
11
12 setup_git_directory();
13 if (do_read_index(istate, the_repository->index_file, 0) < 0)
@@ -20,7 +18,7 @@ int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED)
18 }
19 printf("fsmonitor last update %s\n", istate->fsmonitor_last_update);
20
23 - for (i = 0; i < istate->cache_nr; i++)
21 + for (size_t i = 0; i < istate->cache_nr; i++)
22 printf((istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) ? "+" : "-");
23
24 return 0;
t/helper/test-dump-split-index.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "hex.h"
@@ -17,7 +16,6 @@ static void show_bit(size_t pos, void *data UNUSED)
16 int cmd__dump_split_index(int ac UNUSED, const char **av)
17 {
18 struct split_index *si;
20 - int i;
19
20 setup_git_directory();
21
@@ -29,7 +27,7 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
27 return 0;
28 }
29 printf("base %s\n", oid_to_hex(&si->base_oid));
32 - for (i = 0; i < the_repository->index->cache_nr; i++) {
30 + for (size_t i = 0; i < the_repository->index->cache_nr; i++) {
31 struct cache_entry *ce = the_repository->index->cache[i];
32 printf("%06o %s %d\t%s\n", ce->ce_mode,
33 oid_to_hex(&ce->oid), ce_stage(ce), ce->name);
t/helper/test-dump-untracked-cache.c
+3 -4
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "dir.h"
@@ -24,7 +23,7 @@ static int compare_dir(const void *a_, const void *b_)
23
24 static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
25 {
27 - int i, len;
26 + int len;
27 QSORT(ucd->untracked, ucd->untracked_nr, compare_untracked);
28 QSORT(ucd->dirs, ucd->dirs_nr, compare_dir);
29 len = base->len;
@@ -38,9 +37,9 @@ static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
37 if (ucd->valid)
38 fputs(" valid", stdout);
39 printf("\n");
41 - for (i = 0; i < ucd->untracked_nr; i++)
40 + for (size_t i = 0; i < ucd->untracked_nr; i++)
41 printf("%s\n", ucd->untracked[i]);
43 - for (i = 0; i < ucd->dirs_nr; i++)
42 + for (size_t i = 0; i < ucd->dirs_nr; i++)
43 dump(ucd->dirs[i], base);
44 strbuf_setlen(base, len);
45 }
t/helper/test-hash-speed.c
+2 -5
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "test-tool.h"
2 #include "hash.h"
3
@@ -18,12 +16,11 @@ int cmd__hash_speed(int ac, const char **av)
16 unsigned char hash[GIT_MAX_RAWSZ];
17 clock_t initial, start, end;
18 unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
21 - int i;
19 void *p;
20 const struct git_hash_algo *algo = NULL;
21
22 if (ac == 2) {
26 - for (i = 1; i < GIT_HASH_NALGOS; i++) {
23 + for (size_t i = 1; i < GIT_HASH_NALGOS; i++) {
24 if (!strcmp(av[1], hash_algos[i].name)) {
25 algo = &hash_algos[i];
26 break;
@@ -38,7 +35,7 @@ int cmd__hash_speed(int ac, const char **av)
35
36 printf("algo: %s\n", algo->name);
37
41 - for (i = 0; i < ARRAY_SIZE(bufsizes); i++) {
38 + for (size_t i = 0; i < ARRAY_SIZE(bufsizes); i++) {
39 unsigned long j, kb;
40 double kb_per_sec;
41 p = xcalloc(1, bufsizes[i]);
t/helper/test-parse-options.c
+2 -5
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "test-tool.h"
2 #include "parse-options.h"
3 #include "strbuf.h"
@@ -176,7 +174,6 @@ int cmd__parse_options(int argc, const char **argv)
174 OPT_ALIAS('Z', "alias-target", "alias-source"),
175 OPT_END(),
176 };
179 - int i;
177 int ret = 0;
178
179 trace2_cmd_name("_parse_");
@@ -200,10 +197,10 @@ int cmd__parse_options(int argc, const char **argv)
197 show(&expect, &ret, "dry run: %s", dry_run ? "yes" : "no");
198 show(&expect, &ret, "file: %s", file ? file : "(not set)");
199
203 - for (i = 0; i < list.nr; i++)
200 + for (size_t i = 0; i < list.nr; i++)
201 show(&expect, &ret, "list: %s", list.items[i].string);
202
206 - for (i = 0; i < argc; i++)
203 + for (int i = 0; i < argc; i++)
204 show(&expect, &ret, "arg %02d: %s", i, argv[i]);
205
206 expect.strdup_strings = 1;
t/helper/test-reach.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "commit.h"
@@ -14,7 +13,6 @@
13
14 static void print_sorted_commit_ids(struct commit_list *list)
15 {
17 - int i;
16 struct string_list s = STRING_LIST_INIT_DUP;
17
18 while (list) {
@@ -24,7 +22,7 @@ static void print_sorted_commit_ids(struct commit_list *list)
22
23 string_list_sort(&s);
24
27 - for (i = 0; i < s.nr; i++)
25 + for (size_t i = 0; i < s.nr; i++)
26 printf("%s\n", s.items[i].string);
27
28 string_list_clear(&s, 0);
t/helper/test-ref-store.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-tool.h"
4 #include "hex.h"
@@ -25,14 +24,13 @@ struct flag_definition {
24 static unsigned int parse_flags(const char *str, struct flag_definition *defs)
25 {
26 struct string_list masks = STRING_LIST_INIT_DUP;
28 - int i = 0;
27 unsigned int result = 0;
28
29 if (!strcmp(str, "0"))
30 return 0;
31
32 string_list_split(&masks, str, ',', 64);
35 - for (; i < masks.nr; i++) {
33 + for (size_t i = 0; i < masks.nr; i++) {
34 const char *name = masks.items[i].string;
35 struct flag_definition *def = defs;
36 int found = 0;
t/helper/test-tool.c
+1 -4
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "git-compat-util.h"
2 #include "test-tool.h"
3 #include "test-tool-utils.h"
@@ -103,7 +101,6 @@ static NORETURN void die_usage(void)
101
102 int cmd_main(int argc, const char **argv)
103 {
106 - int i;
104 const char *working_directory = NULL;
105 struct option options[] = {
106 OPT_STRING('C', NULL, &working_directory, "directory",
@@ -122,7 +119,7 @@ int cmd_main(int argc, const char **argv)
119 if (working_directory && chdir(working_directory) < 0)
120 die("Could not cd to '%s'", working_directory);
121
125 - for (i = 0; i < ARRAY_SIZE(cmds); i++) {
122 + for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) {
123 if (!strcmp(cmds[i].name, argv[1])) {
124 argv++;
125 argc--;
t/unit-tests/t-example-decorate.c
+2 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "test-lib.h"
4 #include "object.h"
@@ -43,9 +42,9 @@ static void t_lookup(struct test_vars *vars)
42
43 static void t_loop(struct test_vars *vars)
44 {
46 - int i, objects_noticed = 0;
45 + int objects_noticed = 0;
46
48 - for (i = 0; i < vars->n.size; i++) {
47 + for (size_t i = 0; i < vars->n.size; i++) {
48 if (vars->n.entries[i].base)
49 objects_noticed++;
50 }
t/unit-tests/t-prio-queue.c
+1 -3
@@ -1,5 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
2 -
1 #include "test-lib.h"
2 #include "prio-queue.h"
3
@@ -27,7 +25,7 @@ static void test_prio_queue(int *input, size_t input_size,
25 struct prio_queue pq = { intcmp };
26 int j = 0;
27
30 - for (int i = 0; i < input_size; i++) {
28 + for (size_t i = 0; i < input_size; i++) {
29 void *peek, *get;
30 switch(input[i]) {
31 case GET:
tmp-objdir.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "tmp-objdir.h"
@@ -238,7 +237,6 @@ static int migrate_paths(struct strbuf *src, struct strbuf *dst,
237 {
238 size_t src_len = src->len, dst_len = dst->len;
239 struct string_list paths = STRING_LIST_INIT_DUP;
241 - int i;
240 int ret = 0;
241
242 if (read_dir_paths(&paths, src->buf) < 0)
@@ -246,7 +244,7 @@ static int migrate_paths(struct strbuf *src, struct strbuf *dst,
244 paths.cmp = pack_copy_cmp;
245 string_list_sort(&paths);
246
249 - for (i = 0; i < paths.nr; i++) {
247 + for (size_t i = 0; i < paths.nr; i++) {
248 const char *name = paths.items[i].string;
249 enum finalize_object_file_flags flags_copy = flags;
250
trailer.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "config.h"
@@ -523,7 +522,6 @@ static int git_trailer_config(const char *conf_key, const char *value,
522 struct conf_info *conf;
523 char *name = NULL;
524 enum trailer_info_type type;
526 - int i;
525
526 if (!skip_prefix(conf_key, "trailer.", &trailer_item))
527 return 0;
@@ -533,7 +531,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
531 return 0;
532
533 variable_name++;
536 - for (i = 0; i < ARRAY_SIZE(trailer_config_items); i++) {
534 + for (size_t i = 0; i < ARRAY_SIZE(trailer_config_items); i++) {
535 if (strcmp(trailer_config_items[i].name, variable_name))
536 continue;
537 name = xstrndup(trailer_item, variable_name - trailer_item - 1);
transport-helper.c
+6 -8
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "transport.h"
@@ -314,9 +313,9 @@ static int string_list_set_helper_option(struct helper_data *data,
313 struct string_list *list)
314 {
315 struct strbuf buf = STRBUF_INIT;
317 - int i, ret = 0;
316 + int ret = 0;
317
319 - for (i = 0; i < list->nr; i++) {
318 + for (size_t i = 0; i < list->nr; i++) {
319 strbuf_addf(&buf, "option %s ", name);
320 quote_c_style(list->items[i].string, &buf, NULL, 0);
321 strbuf_addch(&buf, '\n');
@@ -334,7 +333,7 @@ static int set_helper_option(struct transport *transport,
333 {
334 struct helper_data *data = transport->data;
335 struct strbuf buf = STRBUF_INIT;
337 - int i, ret, is_bool = 0;
336 + int ret, is_bool = 0;
337
338 get_helper(transport);
339
@@ -345,12 +344,12 @@ static int set_helper_option(struct transport *transport,
344 return string_list_set_helper_option(data, name,
345 (struct string_list *)value);
346
348 - for (i = 0; i < ARRAY_SIZE(unsupported_options); i++) {
347 + for (size_t i = 0; i < ARRAY_SIZE(unsupported_options); i++) {
348 if (!strcmp(name, unsupported_options[i]))
349 return 1;
350 }
351
353 - for (i = 0; i < ARRAY_SIZE(boolean_options); i++) {
352 + for (size_t i = 0; i < ARRAY_SIZE(boolean_options); i++) {
353 if (!strcmp(name, boolean_options[i])) {
354 is_bool = 1;
355 break;
@@ -482,7 +481,6 @@ static int get_exporter(struct transport *transport,
481 {
482 struct helper_data *data = transport->data;
483 struct child_process *helper = get_helper(transport);
485 - int i;
484
485 child_process_init(fastexport);
486
@@ -498,7 +496,7 @@ static int get_exporter(struct transport *transport,
496 if (data->import_marks)
497 strvec_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
498
501 - for (i = 0; i < revlist_args->nr; i++)
499 + for (size_t i = 0; i < revlist_args->nr; i++)
500 strvec_push(&fastexport->args, revlist_args->items[i].string);
501
502 fastexport->git_cmd = 1;
transport.c
+4 -10
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "advice.h"
@@ -48,7 +47,6 @@ static int transport_color_config(void)
47 "color.transport.rejected"
48 }, *key = "color.transport";
49 char *value;
51 - int i;
50 static int initialized;
51
52 if (initialized)
@@ -61,7 +59,7 @@ static int transport_color_config(void)
59 if (!want_color_stderr(transport_use_color))
60 return 0;
61
64 - for (i = 0; i < ARRAY_SIZE(keys); i++)
62 + for (size_t i = 0; i < ARRAY_SIZE(keys); i++)
63 if (!git_config_get_string(keys[i], &value)) {
64 if (!value)
65 return config_error_nonbool(keys[i]);
@@ -154,14 +152,13 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
152 {
153 struct bundle_transport_data *data = transport->data;
154 struct ref *result = NULL;
157 - int i;
155
156 if (for_push)
157 return NULL;
158
159 get_refs_from_bundle_inner(transport);
160
164 - for (i = 0; i < data->header.references.nr; i++) {
161 + for (size_t i = 0; i < data->header.references.nr; i++) {
162 struct string_list_item *e = data->header.references.items + i;
163 const char *name = e->string;
164 struct ref *ref = alloc_ref(name);
@@ -1282,11 +1279,9 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
1279
1280 static void die_with_unpushed_submodules(struct string_list *needs_pushing)
1281 {
1285 - int i;
1286 -
1282 fprintf(stderr, _("The following submodule paths contain changes that can\n"
1283 "not be found on any remote:\n"));
1289 - for (i = 0; i < needs_pushing->nr; i++)
1284 + for (size_t i = 0; i < needs_pushing->nr; i++)
1285 fprintf(stderr, " %s\n", needs_pushing->items[i].string);
1286 fprintf(stderr, _("\nPlease try\n\n"
1287 " git push --recurse-submodules=on-demand\n\n"
@@ -1602,9 +1597,8 @@ int transport_get_remote_bundle_uri(struct transport *transport)
1597 void transport_unlock_pack(struct transport *transport, unsigned int flags)
1598 {
1599 int in_signal_handler = !!(flags & TRANSPORT_UNLOCK_PACK_IN_SIGNAL_HANDLER);
1605 - int i;
1600
1607 - for (i = 0; i < transport->pack_lockfiles.nr; i++)
1601 + for (size_t i = 0; i < transport->pack_lockfiles.nr; i++)
1602 if (in_signal_handler)
1603 unlink(transport->pack_lockfiles.items[i].string);
1604 else
usage.c
+1 -3
@@ -4,8 +4,6 @@
4 * Copyright (C) Linus Torvalds, 2005
5 */
6
7 -#define DISABLE_SIGN_COMPARE_WARNINGS
8 -
7 #include "git-compat-util.h"
8 #include "gettext.h"
9 #include "trace2.h"
@@ -192,7 +190,7 @@ void NORETURN die(const char *err, ...)
190 static const char *fmt_with_err(char *buf, int n, const char *fmt)
191 {
192 char str_error[256], *err;
195 - int i, j;
193 + size_t i, j;
194
195 err = strerror(errno);
196 for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
version.c
+1 -3
@@ -1,4 +1,3 @@
1 -#define DISABLE_SIGN_COMPARE_WARNINGS
1 #include "git-compat-util.h"
2 #include "version.h"
3 #include "strbuf.h"
@@ -25,11 +24,10 @@ const char *git_user_agent_sanitized(void)
24
25 if (!agent) {
26 struct strbuf buf = STRBUF_INIT;
28 - int i;
27
28 strbuf_addstr(&buf, git_user_agent());
29 strbuf_trim(&buf);
32 - for (i = 0; i < buf.len; i++) {
30 + for (size_t i = 0; i < buf.len; i++) {
31 if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
32 buf.buf[i] = '.';
33 }
versioncmp.c
+1 -3
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "config.h"
@@ -78,11 +77,10 @@ static int swap_prereleases(const char *s1,
77 int off,
78 int *diff)
79 {
81 - int i;
80 struct suffix_match match1 = { -1, off, -1 };
81 struct suffix_match match2 = { -1, off, -1 };
82
85 - for (i = 0; i < prereleases->nr; i++) {
83 + for (size_t i = 0; i < prereleases->nr; i++) {
84 const char *suffix = prereleases->items[i].string;
85 int start, suffix_len = strlen(suffix);
86 if (suffix_len < off)