@matheusbsbs / matheus-bagliano / commits / d5535ec75c
Fork 0

Use run_command() to spawn external diff programs instead of fork/exec.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Johannes Sixt committed Oct 19, 2007 at 21:47 UTC d5535ec75ce1cdf57ef52b57c58c548121ce99ba
1 file changed +3 -35
diff.c
+3 -35
@@ -9,6 +9,7 @@
9 #include "xdiff-interface.h"
10 #include "color.h"
11 #include "attr.h"
12 +#include "run-command.h"
13
14 #ifdef NO_FAST_WORKING_DIRECTORY
15 #define FAST_WORKING_DIRECTORY 0
@@ -1748,40 +1749,6 @@ static void remove_tempfile_on_signal(int signo)
1749 raise(signo);
1750 }
1751
1751 -static int spawn_prog(const char *pgm, const char **arg)
1752 -{
1753 - pid_t pid;
1754 - int status;
1755 -
1756 - fflush(NULL);
1757 - pid = fork();
1758 - if (pid < 0)
1759 - die("unable to fork");
1760 - if (!pid) {
1761 - execvp(pgm, (char *const*) arg);
1762 - exit(255);
1763 - }
1764 -
1765 - while (waitpid(pid, &status, 0) < 0) {
1766 - if (errno == EINTR)
1767 - continue;
1768 - return -1;
1769 - }
1770 -
1771 - /* Earlier we did not check the exit status because
1772 - * diff exits non-zero if files are different, and
1773 - * we are not interested in knowing that. It was a
1774 - * mistake which made it harder to quit a diff-*
1775 - * session that uses the git-apply-patch-script as
1776 - * the GIT_EXTERNAL_DIFF. A custom GIT_EXTERNAL_DIFF
1777 - * should also exit non-zero only when it wants to
1778 - * abort the entire diff-* session.
1779 - */
1780 - if (WIFEXITED(status) && !WEXITSTATUS(status))
1781 - return 0;
1782 - return -1;
1783 -}
1784 -
1752 /* An external diff command takes:
1753 *
1754 * diff-cmd name infile1 infile1-sha1 infile1-mode \
@@ -1834,7 +1801,8 @@ static void run_external_diff(const char *pgm,
1801 *arg++ = name;
1802 }
1803 *arg = NULL;
1837 - retval = spawn_prog(pgm, spawn_arg);
1804 + fflush(NULL);
1805 + retval = run_command_v_opt(spawn_arg, 0);
1806 remove_tempfile();
1807 if (retval) {
1808 fprintf(stderr, "external diff died, stopping at %s.\n", name);