aboutsummaryrefslogtreecommitdiffstats
path: root/editor.c
diff options
context:
space:
mode:
authorAlban Gruin <alban.gruin@gmail.com>2018-08-10 18:51:30 +0200
committerJunio C Hamano <gitster@pobox.com>2018-08-10 11:56:22 -0700
commit2aed01811daee2f412b795ea539a4eb5abb69510 (patch)
treeecdacc2374cea01cbffac405451ec9a42e983a80 /editor.c
parent145e05ac44b4c574fc22e6d3af7c5a14ad9b7335 (diff)
downloadgit-2aed01811daee2f412b795ea539a4eb5abb69510.tar.gz
editor: add a function to launch the sequence editor
As part of the rewrite of interactive rebase, the sequencer will need to open the sequence editor to allow the user to edit the todo list. Instead of duplicating the existing launch_editor() function, this refactors it to a new function, launch_specified_editor(), which takes the editor as a parameter, in addition to the path, the buffer and the environment variables. launch_sequence_editor() is then added to launch the sequence editor. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'editor.c')
-rw-r--r--editor.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/editor.c b/editor.c
index 9a9b4e12d1..c985eee1f9 100644
--- a/editor.c
+++ b/editor.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "strbuf.h"
#include "run-command.h"
#include "sigchain.h"
@@ -34,10 +35,21 @@ const char *git_editor(void)
return editor;
}
-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+const char *git_sequence_editor(void)
{
- const char *editor = git_editor();
+ const char *editor = getenv("GIT_SEQUENCE_EDITOR");
+
+ if (!editor)
+ git_config_get_string_const("sequence.editor", &editor);
+ if (!editor)
+ editor = git_editor();
+ return editor;
+}
+
+static int launch_specified_editor(const char *editor, const char *path,
+ struct strbuf *buffer, const char *const *env)
+{
if (!editor)
return error("Terminal is dumb, but EDITOR unset");
@@ -95,3 +107,14 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
return error_errno("could not read file '%s'", path);
return 0;
}
+
+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+ return launch_specified_editor(git_editor(), path, buffer, env);
+}
+
+int launch_sequence_editor(const char *path, struct strbuf *buffer,
+ const char *const *env)
+{
+ return launch_specified_editor(git_sequence_editor(), path, buffer, env);
+}