Skip to content

Commit 338abb0

Browse files
avargitster
authored andcommitted
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 3f2e229 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit 338abb0

File tree

9 files changed

+13
-14
lines changed

9 files changed

+13
-14
lines changed

builtin/difftool.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ static int run_file_diff(int prompt, const char *prefix,
671671
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
672672
NULL
673673
};
674-
int ret = 0, i;
674+
int i;
675675

676676
if (prompt > 0)
677677
env[2] = "GIT_DIFFTOOL_PROMPT=true";
@@ -682,8 +682,7 @@ static int run_file_diff(int prompt, const char *prefix,
682682
strvec_push(&args, "diff");
683683
for (i = 0; i < argc; i++)
684684
strvec_push(&args, argv[i]);
685-
ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
686-
exit(ret);
685+
return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
687686
}
688687

689688
int cmd_difftool(int argc, const char **argv, const char *prefix)

builtin/merge-ours.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix)
2828
if (read_cache() < 0)
2929
die_errno("read_cache failed");
3030
if (index_differs_from(the_repository, "HEAD", NULL, 0))
31-
exit(2);
32-
exit(0);
31+
return 2;
32+
return 0;
3333
}

builtin/mktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,5 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
189189
used=0; /* reset tree entry buffer for re-use in batch mode */
190190
}
191191
strbuf_release(&sb);
192-
exit(0);
192+
return 0;
193193
}

sh-i18n--envsubst.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ cmd_main (int argc, const char *argv[])
104104
if (ferror (stderr) || fflush (stderr))
105105
{
106106
fclose (stderr);
107-
exit (EXIT_FAILURE);
107+
return (EXIT_FAILURE);
108108
}
109109
if (fclose (stderr) && errno != EBADF)
110-
exit (EXIT_FAILURE);
110+
return (EXIT_FAILURE);
111111

112-
exit (EXIT_SUCCESS);
112+
return (EXIT_SUCCESS);
113113
}
114114

115115
/* Parse the string and invoke the callback each time a $VARIABLE or

shell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int cmd_main(int argc, const char **argv)
177177
default:
178178
continue;
179179
}
180-
exit(cmd->exec(cmd->name, arg));
180+
return cmd->exec(cmd->name, arg);
181181
}
182182

183183
cd_to_homedir();

t/helper/test-hash-speed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ int cmd__hash_speed(int ac, const char **av)
5757
free(p);
5858
}
5959

60-
exit(0);
60+
return 0;
6161
}

t/helper/test-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ int cmd_hash_impl(int ac, const char **av, int algo)
5454
fwrite(hash, 1, algop->rawsz, stdout);
5555
else
5656
puts(hash_to_hex_algop(hash, algop));
57-
exit(0);
57+
return 0;
5858
}

t/helper/test-match-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ int cmd__match_trees(int ac, const char **av)
2323
shift_tree(the_repository, &one->object.oid, &two->object.oid, &shifted, -1);
2424
printf("shifted: %s\n", oid_to_hex(&shifted));
2525

26-
exit(0);
26+
return 0;
2727
}

t/helper/test-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,5 @@ int cmd__reach(int ac, const char **av)
166166
print_sorted_commit_ids(list);
167167
}
168168

169-
exit(0);
169+
return 0;
170170
}

0 commit comments

Comments
 (0)