git_config_maybe_bool()
[gitweb.git] / editor.c
index 3f1375114c989c0d58dd3e2fd285ba149c4e70a2..d8340031d24828483697c10257806efedfe041f5 100644 (file)
--- a/editor.c
+++ b/editor.c
@@ -2,7 +2,11 @@
 #include "strbuf.h"
 #include "run-command.h"
 
-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+#ifndef DEFAULT_EDITOR
+#define DEFAULT_EDITOR "vi"
+#endif
+
+const char *git_editor(void)
 {
        const char *editor = getenv("GIT_EDITOR");
        const char *terminal = getenv("TERM");
@@ -16,32 +20,25 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
                editor = getenv("EDITOR");
 
        if (!editor && terminal_is_dumb)
-               return error("terminal is dumb, but EDITOR unset");
+               return NULL;
+
+       if (!editor)
+               editor = DEFAULT_EDITOR;
+
+       return editor;
+}
+
+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+       const char *editor = git_editor();
 
        if (!editor)
-               editor = "vi";
+               return error("Terminal is dumb, but EDITOR unset");
 
        if (strcmp(editor, ":")) {
-               size_t len = strlen(editor);
-               int i = 0;
-               int failed;
-               const char *args[6];
-               struct strbuf arg0 = STRBUF_INIT;
-
-               if (strcspn(editor, "|&;<>()$`\\\"' \t\n*?[#~=%") != len) {
-                       /* there are specials */
-                       strbuf_addf(&arg0, "%s \"$@\"", editor);
-                       args[i++] = "sh";
-                       args[i++] = "-c";
-                       args[i++] = arg0.buf;
-               }
-               args[i++] = editor;
-               args[i++] = path;
-               args[i] = NULL;
-
-               failed = run_command_v_opt_cd_env(args, 0, NULL, env);
-               strbuf_release(&arg0);
-               if (failed)
+               const char *args[] = { editor, path, NULL };
+
+               if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
                        return error("There was a problem with the editor '%s'.",
                                        editor);
        }