Gmane
From: Johannes Sixt <j6t <at> kdbg.org>
Subject: [Replacement PATCH 1/7] MinGW: truncate exit()'s argument to lowest 8 bits
Newsgroups: gmane.comp.version-control.git
Date: 2009-07-05 18:57:46 GMT (35 weeks, 3 days, 5 hours and 31 minutes ago)
For some reason, MinGW's bash cannot reliably detect failure of the child
process if a negative value is passed to exit(). This fixes it by
truncating the exit code in all calls of exit().

This issue was worked around in run_builtin() of git.c (2488df84 builtin
run_command: do not exit with -1, 2007-11-15). This workaround is no longer
necessary and is reverted.

Suggested-by: Junio C Hamano <gitster <at> pobox.com>
Signed-off-by: Johannes Sixt <j6t <at> kdbg.org>
---
 compat/mingw.h |    2 ++
 git.c          |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 4f7ba4c..c1859c5 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -92,6 +92,8 @@ static inline int fcntl(int fd, int cmd, long arg)
 	errno = EINVAL;
 	return -1;
 }
+/* bash cannot reliably detect negative return codes as failure */
+#define exit(code) exit((code) & 0xff)

 /*
  * simple adaptors
diff --git a/git.c b/git.c
index f4d53f4..65ed733 100644
--- a/git.c
+++ b/git.c
@@ -245,7 +245,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)

 	status = p->fn(argc, argv, prefix);
 	if (status)
-		return status & 0xff;
+		return status;

 	/* Somebody closed stdout? */
 	if (fstat(fileno(stdout), &st))
-- 
1.6.3.3.393.g6b649