cat-file: declare loop counter inside for()
Some code used in this series declares variable i and only uses it in a for loop, not in any other logic outside the loop. Change the declaration of i to be inside the for loop for readability. While at it, we also change its type from int to size_t where the latter makes more sense. Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Eric Ju <eric.peijian@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Ju committed
Jul 10, 2026 at 18:41 UTC
3f565f7c9fa8795d080ab0bd2e5bf75494c5ff30
2 files changed
+5
-11
builtin/cat-file.c
+4
-9
@@ -723,14 +723,12 @@ static void dispatch_calls(struct batch_options *opt,
723
struct strbuf *output,
724
struct expand_data *data,
725
struct queued_cmd *cmd,
726
- int nr)
726
+ size_t nr)
727
{
728
- int i;
729
-
728
if (!opt->buffer_output)
729
die(_("flush is only for --buffer mode"));
730
733
- for (i = 0; i < nr; i++)
731
+ for (size_t i = 0; i < nr; i++)
732
cmd[i].fn(opt, cmd[i].line, output, data);
733
734
fflush(stdout);
@@ -738,9 +736,7 @@ static void dispatch_calls(struct batch_options *opt,
736
737
static void free_cmds(struct queued_cmd *cmd, size_t *nr)
738
{
741
- size_t i;
742
-
743
- for (i = 0; i < *nr; i++)
739
+ for (size_t i = 0; i < *nr; i++)
740
FREE_AND_NULL(cmd[i].line);
741
742
*nr = 0;
@@ -767,7 +763,6 @@ static void batch_objects_command(struct batch_options *opt,
763
size_t alloc = 0, nr = 0;
764
765
while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
770
- int i;
766
const struct parse_cmd *cmd = NULL;
767
const char *p = NULL, *cmd_end;
768
struct queued_cmd call = {0};
@@ -777,7 +772,7 @@ static void batch_objects_command(struct batch_options *opt,
772
if (isspace(*input.buf))
773
die(_("whitespace before command: '%s'"), input.buf);
774
780
- for (i = 0; i < ARRAY_SIZE(commands); i++) {
775
+ for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
776
if (!skip_prefix(input.buf, commands[i].name, &cmd_end))
777
continue;
778
fetch-pack.c
+1
-2
@@ -1388,9 +1388,8 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
1388
if (advertise_sid && server_supports_v2("session-id"))
1389
packet_buf_write(req_buf, "session-id=%s", trace2_session_id());
1390
if (server_options && server_options->nr) {
1391
- int i;
1391
ensure_server_supports_v2("server-option");
1393
- for (i = 0; i < server_options->nr; i++)
1392
+ for (size_t i = 0; i < server_options->nr; i++)
1393
packet_buf_write(req_buf, "server-option=%s",
1394
server_options->items[i].string);
1395
}