Skip to content

Commit 219877e

Browse files
peijianjugitster
authored andcommitted
cat-file: add declaration of variable i inside its for loop
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 <[email protected]> Signed-off-by: Eric Ju <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4e26096 commit 219877e

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

builtin/cat-file.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -676,22 +676,18 @@ static void dispatch_calls(struct batch_options *opt,
676676
struct queued_cmd *cmd,
677677
int nr)
678678
{
679-
int i;
680-
681679
if (!opt->buffer_output)
682680
die(_("flush is only for --buffer mode"));
683681

684-
for (i = 0; i < nr; i++)
682+
for (size_t i = 0; i < nr; i++)
685683
cmd[i].fn(opt, cmd[i].line, output, data);
686684

687685
fflush(stdout);
688686
}
689687

690688
static void free_cmds(struct queued_cmd *cmd, size_t *nr)
691689
{
692-
size_t i;
693-
694-
for (i = 0; i < *nr; i++)
690+
for (size_t i = 0; i < *nr; i++)
695691
FREE_AND_NULL(cmd[i].line);
696692

697693
*nr = 0;
@@ -717,7 +713,6 @@ static void batch_objects_command(struct batch_options *opt,
717713
size_t alloc = 0, nr = 0;
718714

719715
while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
720-
int i;
721716
const struct parse_cmd *cmd = NULL;
722717
const char *p = NULL, *cmd_end;
723718
struct queued_cmd call = {0};
@@ -727,7 +722,7 @@ static void batch_objects_command(struct batch_options *opt,
727722
if (isspace(*input.buf))
728723
die(_("whitespace before command: '%s'"), input.buf);
729724

730-
for (i = 0; i < ARRAY_SIZE(commands); i++) {
725+
for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
731726
if (!skip_prefix(input.buf, commands[i].name, &cmd_end))
732727
continue;
733728

fetch-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,8 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
13311331
if (advertise_sid && server_supports_v2("session-id"))
13321332
packet_buf_write(req_buf, "session-id=%s", trace2_session_id());
13331333
if (server_options && server_options->nr) {
1334-
int i;
13351334
ensure_server_supports_v2("server-option");
1336-
for (i = 0; i < server_options->nr; i++)
1335+
for (size_t i = 0; i < server_options->nr; i++)
13371336
packet_buf_write(req_buf, "server-option=%s",
13381337
server_options->items[i].string);
13391338
}

0 commit comments

Comments
 (0)