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>
Alban Gruin committed
Aug 10, 2018 at 18:51 UTC
2aed01811daee2f412b795ea539a4eb5abb69510
3 files changed
+28
-2
cache.h
+1
@@ -1409,6 +1409,7 @@ extern const char *fmt_name(const char *name, const char *email);
1409
extern const char *ident_default_name(void);
1410
extern const char *ident_default_email(void);
1411
extern const char *git_editor(void);
1412
+extern const char *git_sequence_editor(void);
1413
extern const char *git_pager(int stdout_is_tty);
1414
extern int is_terminal_dumb(void);
1415
extern int git_ident_config(const char *, const char *, void *);
editor.c
+25
-2
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "config.h"
3
#include "strbuf.h"
4
#include "run-command.h"
5
#include "sigchain.h"
@@ -34,10 +35,21 @@ const char *git_editor(void)
35
return editor;
36
}
37
37
-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
38
+const char *git_sequence_editor(void)
39
{
39
- const char *editor = git_editor();
40
+ const char *editor = getenv("GIT_SEQUENCE_EDITOR");
41
+
42
+ if (!editor)
43
+ git_config_get_string_const("sequence.editor", &editor);
44
+ if (!editor)
45
+ editor = git_editor();
46
47
+ return editor;
48
+}
49
+
50
+static int launch_specified_editor(const char *editor, const char *path,
51
+ struct strbuf *buffer, const char *const *env)
52
+{
53
if (!editor)
54
return error("Terminal is dumb, but EDITOR unset");
55
@@ -95,3 +107,14 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
107
return error_errno("could not read file '%s'", path);
108
return 0;
109
}
110
+
111
+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
112
+{
113
+ return launch_specified_editor(git_editor(), path, buffer, env);
114
+}
115
+
116
+int launch_sequence_editor(const char *path, struct strbuf *buffer,
117
+ const char *const *env)
118
+{
119
+ return launch_specified_editor(git_sequence_editor(), path, buffer, env);
120
+}
strbuf.h
+2
@@ -575,6 +575,8 @@ extern void strbuf_add_unique_abbrev(struct strbuf *sb,
575
* file's contents are not read into the buffer upon completion.
576
*/
577
extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
578
+extern int launch_sequence_editor(const char *path, struct strbuf *buffer,
579
+ const char *const *env);
580
581
extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size);
582