Skip to content

Commit

Permalink
cat-file: add declaration of variable i inside its for loop
Browse files Browse the repository at this point in the history
Some code 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.

Helped-by: Christian Couder <[email protected]>
Signed-off-by: Eric Ju <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peijianju authored and gitster committed Sep 27, 2024
1 parent 33426e4 commit df8c5dd
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,22 +673,18 @@ static void dispatch_calls(struct batch_options *opt,
struct queued_cmd *cmd,
int nr)
{
int i;

if (!opt->buffer_output)
die(_("flush is only for --buffer mode"));

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

fflush(stdout);
}

static void free_cmds(struct queued_cmd *cmd, size_t *nr)
{
size_t i;

for (i = 0; i < *nr; i++)
for (size_t i = 0; i < *nr; i++)
FREE_AND_NULL(cmd[i].line);

*nr = 0;
Expand All @@ -714,7 +710,6 @@ static void batch_objects_command(struct batch_options *opt,
size_t alloc = 0, nr = 0;

while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
int i;
const struct parse_cmd *cmd = NULL;
const char *p = NULL, *cmd_end;
struct queued_cmd call = {0};
Expand All @@ -724,7 +719,7 @@ static void batch_objects_command(struct batch_options *opt,
if (isspace(*input.buf))
die(_("whitespace before command: '%s'"), input.buf);

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

Expand Down

0 comments on commit df8c5dd

Please sign in to comment.