]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtins + test helpers: use return instead of exit() in cmd_*
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 8 Jun 2021 10:48:03 +0000 (12:48 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Jun 2021 00:15:58 +0000 (09:15 +0900)
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>
builtin/difftool.c
builtin/merge-ours.c
builtin/mktree.c
sh-i18n--envsubst.c
shell.c
t/helper/test-hash-speed.c
t/helper/test-hash.c
t/helper/test-match-trees.c
t/helper/test-reach.c

index 6e18e623fddfbfb33a3de9f4df8cabbbc048ed51..6861f33db6e9ad3eaa8b56029c2801d300e44710 100644 (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)
index 4594507420533262a7b6611386a340cfdb96b25f..3583cff71c7c7a6d1e78fc7e3a6f902015f0741f 100644 (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;
 }
index 891991b00d673457ecdc6d82d1aa400a9eff03e9..ae78ca1c02981a6d846027d7ce01484e5e3a1851 100644 (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;
 }
index e7430b9aa8ecf136a7d625ee059822e1e1a74b26..6cd307ac2c65a2825e467aeb9c1e6abfe8cc7e70 100644 (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
diff --git a/shell.c b/shell.c
index cef7ffdc9e1d3040930841134577c591cf02f650..811e13b9c9597e9c89bf773a1065819d48a2277c 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -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();
index 432233c7f0e54c306e6f0462ce3d4ab75a31fe61..f40d9ad0c2ddd293f2b1a1e7e142885ede078ae6 100644 (file)
@@ -57,5 +57,5 @@ int cmd__hash_speed(int ac, const char **av)
                free(p);
        }
 
-       exit(0);
+       return 0;
 }
index 0a31de66f3542500fe4b9b0ddafe6619178d3218..261c545b9d199c6ba8c87eaaab7ce8da4f5cba69 100644 (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;
 }
index b9fd427571e6265dbc3be8b6e93acbb6eba61c56..4079fdee06776c8179fbc15283141f3890ff013e 100644 (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;
 }
index cda804ed79d0760e5a2b4708d3c4096e9f1d6540..2f65c7f6a55bc146ea69ea9ef85d45a1f6172ac3 100644 (file)
@@ -166,5 +166,5 @@ int cmd__reach(int ac, const char **av)
                print_sorted_commit_ids(list);
        }
 
-       exit(0);
+       return 0;
 }