OSDN Git Service

tag.c: whitespace breakages fix
[git-core/git.git] / editor.c
index 3f13751..615f575 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,10 +20,20 @@ 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);