50 lines
1.2 KiB
Diff
50 lines
1.2 KiB
Diff
diff --git a/common-main.c b/common-main.c
|
|
index 0000000000..0000000000 100644
|
|
--- a/common-main.c
|
|
+++ b/common-main.c
|
|
@@ -1,6 +1,27 @@
|
|
#include "git-compat-util.h"
|
|
#include "common-init.h"
|
|
|
|
+#ifdef GITHUG_EMBEDDED_MAIN
|
|
+void githug_exit(int code)
|
|
+{
|
|
+ code &= 0xff;
|
|
+ fflush(stdout);
|
|
+ fflush(stderr);
|
|
+ _exit(code);
|
|
+}
|
|
+
|
|
+int githug_git_main(int argc, const char **argv)
|
|
+{
|
|
+ int result;
|
|
+
|
|
+ init_git(argv);
|
|
+ result = cmd_main(argc, argv);
|
|
+
|
|
+ /* Match Git's real main(), but return instead of calling libc exit(). */
|
|
+ return common_exit(__FILE__, __LINE__, result);
|
|
+}
|
|
+#endif
|
|
+
|
|
int main(int argc, const char **argv)
|
|
{
|
|
int result;
|
|
diff --git a/git-compat-util.h b/git-compat-util.h
|
|
index 0000000000..0000000000 100644
|
|
--- a/git-compat-util.h
|
|
+++ b/git-compat-util.h
|
|
@@ -1047,7 +1047,12 @@ int cmd_main(int, const char **);
|
|
* optionally emit a message before calling the real exit().
|
|
*/
|
|
int common_exit(const char *file, int line, int code);
|
|
+#ifdef GITHUG_EMBEDDED_MAIN
|
|
+NORETURN void githug_exit(int code);
|
|
+#define exit(code) githug_exit(common_exit(__FILE__, __LINE__, (code)))
|
|
+#else
|
|
#define exit(code) exit(common_exit(__FILE__, __LINE__, (code)))
|
|
+#endif
|
|
|
|
/*
|
|
* This include must come after system headers, since it introduces macros that
|