builtins + test helpers: use return instead of exit() in cmd_*

Change various cmd_* functions that claim to return an "int" to use
"return" instead of exit() to indicate an exit code. These were not
marked with NORETURN, and by directly exit()-ing we'll skip the
cleanup git.c would otherwise do (e.g. closing fd's, erroring if we
can't). See run_builtin() in git.c.

In the case of shell.c and sh-i18n--envsubst.c this was the result of
an incomplete migration to using a cmd_main() in 3f2e2297b9 (add an
extra level of indirection to main(), 2016-07-01).

This was spotted by SunCC 12.5 on Solaris 10 (gcc210 on the gccfarm).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2021-06-08 12:48:03 +02:00 committed by Junio C Hamano
parent 48bf2fa8ba
commit 338abb0f04
9 changed files with 13 additions and 14 deletions

View File

@ -671,7 +671,7 @@ static int run_file_diff(int prompt, const char *prefix,
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
NULL
};
int ret = 0, i;
int i;
if (prompt > 0)
env[2] = "GIT_DIFFTOOL_PROMPT=true";
@ -682,8 +682,7 @@ static int run_file_diff(int prompt, const char *prefix,
strvec_push(&args, "diff");
for (i = 0; i < argc; i++)
strvec_push(&args, argv[i]);
ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
exit(ret);
return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
}
int cmd_difftool(int argc, const char **argv, const char *prefix)

View File

@ -28,6 +28,6 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
if (read_cache() < 0)
die_errno("read_cache failed");
if (index_differs_from(the_repository, "HEAD", NULL, 0))
exit(2);
exit(0);
return 2;
return 0;
}

View File

@ -189,5 +189,5 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
used=0; /* reset tree entry buffer for re-use in batch mode */
}
strbuf_release(&sb);
exit(0);
return 0;
}

View File

@ -104,12 +104,12 @@ cmd_main (int argc, const char *argv[])
if (ferror (stderr) || fflush (stderr))
{
fclose (stderr);
exit (EXIT_FAILURE);
return (EXIT_FAILURE);
}
if (fclose (stderr) && errno != EBADF)
exit (EXIT_FAILURE);
return (EXIT_FAILURE);
exit (EXIT_SUCCESS);
return (EXIT_SUCCESS);
}
/* Parse the string and invoke the callback each time a $VARIABLE or

View File

@ -177,7 +177,7 @@ int cmd_main(int argc, const char **argv)
default:
continue;
}
exit(cmd->exec(cmd->name, arg));
return cmd->exec(cmd->name, arg);
}
cd_to_homedir();

View File

@ -57,5 +57,5 @@ int cmd__hash_speed(int ac, const char **av)
free(p);
}
exit(0);
return 0;
}

View File

@ -54,5 +54,5 @@ int cmd_hash_impl(int ac, const char **av, int algo)
fwrite(hash, 1, algop->rawsz, stdout);
else
puts(hash_to_hex_algop(hash, algop));
exit(0);
return 0;
}

View File

@ -23,5 +23,5 @@ int cmd__match_trees(int ac, const char **av)
shift_tree(the_repository, &one->object.oid, &two->object.oid, &shifted, -1);
printf("shifted: %s\n", oid_to_hex(&shifted));
exit(0);
return 0;
}

View File

@ -166,5 +166,5 @@ int cmd__reach(int ac, const char **av)
print_sorted_commit_ids(list);
}
exit(0);
return 0;
}