]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-import: localize 'i' into the 'for' loops using it
authorChristian Couder <christian.couder@gmail.com>
Thu, 16 Jul 2026 16:55:14 +0000 (18:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jul 2026 21:11:13 +0000 (14:11 -0700)
In cmd_fast_import(), a local variable 'i' is defined as an
`unsigned int` and then used as a loop counter in four different
`for (i = ...; i < ...; i++) { ... }` loops.

But in three out of the four cases, `unsigned int` isn't the best type
to use.

To give each loop counter the type matching its bound
(int/unsigned/size_t), let's localize 'i' into each loop that uses it.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c

index aa656c5195d3669943d973b226b727e35135c56e..fd4e13b7cad85316f6a439e3b10e0e45a7072654 100644 (file)
@@ -3936,8 +3936,6 @@ int cmd_fast_import(int argc,
                    const char *prefix,
                    struct repository *repo)
 {
-       unsigned int i;
-
        show_usage_if_asked(argc, argv, fast_import_usage);
 
        reset_pack_idx_option(&pack_idx_opts);
@@ -3958,7 +3956,7 @@ int cmd_fast_import(int argc,
         * line to override stream data). But we must do an early parse of any
         * command-line options that impact how we interpret the feature lines.
         */
-       for (i = 1; i < argc; i++) {
+       for (int i = 1; i < argc; i++) {
                const char *arg = argv[i];
                if (*arg != '-' || !strcmp(arg, "--"))
                        break;
@@ -3971,7 +3969,7 @@ int cmd_fast_import(int argc,
        global_prefix = prefix;
 
        rc_free = mem_pool_alloc(&fi_mem_pool, cmd_save * sizeof(*rc_free));
-       for (i = 0; i < (cmd_save - 1); i++)
+       for (unsigned int i = 0; i < (cmd_save - 1); i++)
                rc_free[i].next = &rc_free[i + 1];
        rc_free[cmd_save - 1].next = NULL;
 
@@ -4034,9 +4032,9 @@ int cmd_fast_import(int argc,
 
        if (show_stats) {
                uintmax_t total_count = 0, duplicate_count = 0;
-               for (i = 0; i < ARRAY_SIZE(object_count_by_type); i++)
+               for (size_t i = 0; i < ARRAY_SIZE(object_count_by_type); i++)
                        total_count += object_count_by_type[i];
-               for (i = 0; i < ARRAY_SIZE(duplicate_count_by_type); i++)
+               for (size_t i = 0; i < ARRAY_SIZE(duplicate_count_by_type); i++)
                        duplicate_count += duplicate_count_by_type[i];
 
                fprintf(stderr, "%s statistics:\n", argv[0]);