Imported Upstream version 2.13.3
[platform/upstream/git.git] / editor.c
index d834003..7519ede 100644 (file)
--- a/editor.c
+++ b/editor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "strbuf.h"
 #include "run-command.h"
+#include "sigchain.h"
 
 #ifndef DEFAULT_EDITOR
 #define DEFAULT_EDITOR "vi"
@@ -36,9 +37,25 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
                return error("Terminal is dumb, but EDITOR unset");
 
        if (strcmp(editor, ":")) {
-               const char *args[] = { editor, path, NULL };
+               const char *args[] = { editor, real_path(path), NULL };
+               struct child_process p = CHILD_PROCESS_INIT;
+               int ret, sig;
 
-               if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
+               p.argv = args;
+               p.env = env;
+               p.use_shell = 1;
+               if (start_command(&p) < 0)
+                       return error("unable to start editor '%s'", editor);
+
+               sigchain_push(SIGINT, SIG_IGN);
+               sigchain_push(SIGQUIT, SIG_IGN);
+               ret = finish_command(&p);
+               sig = ret - 128;
+               sigchain_pop(SIGINT);
+               sigchain_pop(SIGQUIT);
+               if (sig == SIGINT || sig == SIGQUIT)
+                       raise(sig);
+               if (ret)
                        return error("There was a problem with the editor '%s'.",
                                        editor);
        }
@@ -46,7 +63,6 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
        if (!buffer)
                return 0;
        if (strbuf_read_file(buffer, path, 0) < 0)
-               return error("could not read file '%s': %s",
-                               path, strerror(errno));
+               return error_errno("could not read file '%s'", path);
        return 0;
 }