Skip to content

Commit 2aed018

Browse files
agrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 145e05a commit 2aed018

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ extern const char *fmt_name(const char *name, const char *email);
14091409
extern const char *ident_default_name(void);
14101410
extern const char *ident_default_email(void);
14111411
extern const char *git_editor(void);
1412+
extern const char *git_sequence_editor(void);
14121413
extern const char *git_pager(int stdout_is_tty);
14131414
extern int is_terminal_dumb(void);
14141415
extern int git_ident_config(const char *, const char *, void *);

editor.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "config.h"
23
#include "strbuf.h"
34
#include "run-command.h"
45
#include "sigchain.h"
@@ -34,10 +35,21 @@ const char *git_editor(void)
3435
return editor;
3536
}
3637

37-
int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
38+
const char *git_sequence_editor(void)
3839
{
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();
4046

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+
{
4153
if (!editor)
4254
return error("Terminal is dumb, but EDITOR unset");
4355

@@ -95,3 +107,14 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
95107
return error_errno("could not read file '%s'", path);
96108
return 0;
97109
}
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ extern void strbuf_add_unique_abbrev(struct strbuf *sb,
575575
* file's contents are not read into the buffer upon completion.
576576
*/
577577
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);
578580

579581
extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size);
580582

0 commit comments

Comments
 (0)