git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC][PATCH v2 1/2] editor: add a function to launch the sequence editor

From
Alban Gruin <alban.gruin@gmail.com>
Date
Jun 13, 2018, 15:22 UTC
Message-ID
<20180613152211.12580-2-alban.gruin@gmail.com>
In-Reply-To
<20180613152211.12580-1-alban.gruin@gmail.com>

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>
---
 cache.h  |  1 +
 editor.c | 27 +++++++++++++++++++++++++--
 strbuf.h |  2 ++
 3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index 89a107a7f..c124849a1 100644
--- a/cache.h
+++ b/cache.h
@@ -1472,6 +1472,7 @@ extern const char *fmt_name(const char *name, const char *email);
 extern const char *ident_default_name(void);
 extern const char *ident_default_email(void);
 extern const char *git_editor(void);
+extern const char *git_sequence_editor(void);
 extern const char *git_pager(int stdout_is_tty);
 extern int is_terminal_dumb(void);
 extern int git_ident_config(const char *, const char *, void *);
diff --git a/editor.c b/editor.c
index 9a9b4e12d..c985eee1f 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);
+}
diff --git a/strbuf.h b/strbuf.h
index 60a35aef1..66da9822f 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -575,6 +575,8 @@ extern void strbuf_add_unique_abbrev(struct strbuf *sb,
  * file's contents are not read into the buffer upon completion.
  */
 extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
+extern int launch_sequence_editor(const char *path, struct strbuf *buffer,
+				  const char *const *env);
 
 extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size);
 
-- 
2.16.4
Previous: Alban GruinNext: Alban Gruin
Message 9 of 19 in “rebase -i: rewrite the edit-todo functionality in C”
  1. Alban GruinJun 11, 2018
  2. [GSoC][PATCH 1/1] rebase--interactive: rewrite the edit-todo functionality in CAlban Gruin, Jun 11, 2018
  3. Phillip WoodJun 11, 2018
  4. Alban GruinJun 12, 2018
  5. Phillip WoodJun 12, 2018
  6. Elijah NewrenJun 12, 2018
  7. Alban GruinJun 12, 2018
  8. [GSoC][PATCH v2 0/2] rebase -i: rewrite the edit-todo functionality in CAlban Gruin, Jun 13, 2018
  9. [GSoC][PATCH v2 1/2] editor: add a function to launch the sequence editorAlban Gruin, Jun 13, 2018
  10. [GSoC][PATCH v2 2/2] rebase--interactive: rewrite the edit-todo functionality in CAlban Gruin, Jun 13, 2018
  11. Junio C HamanoJun 14, 2018
  12. Alban GruinJun 14, 2018
  13. Elijah NewrenJun 14, 2018
  14. Phillip WoodJun 14, 2018
  15. [GSoC][PATCH v3 0/2] rebase -i: rewrite the edit-todo functionality in CAlban Gruin, Jun 26, 2018
  16. [GSoC][PATCH v3 1/2] editor: add a function to launch the sequence editorAlban Gruin, Jun 26, 2018
  17. [GSoC][PATCH v3 2/2] rebase-interactive: rewrite the edit-todo functionality in CAlban Gruin, Jun 26, 2018
  18. Johannes SchindelinJun 26, 2018
  19. Johannes SchindelinJun 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.