fast-import: localize 'i' into the 'for' loops using it
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>
Christian Couder committed
Jul 16, 2026 at 18:55 UTC
0892b3df6f40f798dfe9d9e4c000b027141a2cd6
1 file changed
+4
-6
builtin/fast-import.c
+4
-6
@@ -3936,8 +3936,6 @@ int cmd_fast_import(int argc,
3936
const char *prefix,
3937
struct repository *repo)
3938
{
3939
- unsigned int i;
3940
-
3939
show_usage_if_asked(argc, argv, fast_import_usage);
3940
3941
reset_pack_idx_option(&pack_idx_opts);
@@ -3958,7 +3956,7 @@ int cmd_fast_import(int argc,
3956
* line to override stream data). But we must do an early parse of any
3957
* command-line options that impact how we interpret the feature lines.
3958
*/
3961
- for (i = 1; i < argc; i++) {
3959
+ for (int i = 1; i < argc; i++) {
3960
const char *arg = argv[i];
3961
if (*arg != '-' || !strcmp(arg, "--"))
3962
break;
@@ -3971,7 +3969,7 @@ int cmd_fast_import(int argc,
3969
global_prefix = prefix;
3970
3971
rc_free = mem_pool_alloc(&fi_mem_pool, cmd_save * sizeof(*rc_free));
3974
- for (i = 0; i < (cmd_save - 1); i++)
3972
+ for (unsigned int i = 0; i < (cmd_save - 1); i++)
3973
rc_free[i].next = &rc_free[i + 1];
3974
rc_free[cmd_save - 1].next = NULL;
3975
@@ -4034,9 +4032,9 @@ int cmd_fast_import(int argc,
4032
4033
if (show_stats) {
4034
uintmax_t total_count = 0, duplicate_count = 0;
4037
- for (i = 0; i < ARRAY_SIZE(object_count_by_type); i++)
4035
+ for (size_t i = 0; i < ARRAY_SIZE(object_count_by_type); i++)
4036
total_count += object_count_by_type[i];
4039
- for (i = 0; i < ARRAY_SIZE(duplicate_count_by_type); i++)
4037
+ for (size_t i = 0; i < ARRAY_SIZE(duplicate_count_by_type); i++)
4038
duplicate_count += duplicate_count_by_type[i];
4039
4040
fprintf(stderr, "%s statistics:\n", argv[0]);