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

[PATCH/RFC/GSoC 16/17] editor: implement git_sequence_editor() and launch_sequence_editor()

From
Paul Tan <pyokagan@gmail.com>
Date
Mar 12, 2016, 10:46 UTC
Message-ID
<1457779597-6918-17-git-send-email-pyokagan@gmail.com>
In-Reply-To
<1457779597-6918-1-git-send-email-pyokagan@gmail.com>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 cache.h  |  1 +
 editor.c | 27 +++++++++++++++++++++++++--
 strbuf.h |  1 +
 3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index aa5e97c..d7a6fc6 100644
--- a/cache.h
+++ b/cache.h
@@ -1222,6 +1222,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 git_ident_config(const char *, const char *, void *);
 
diff --git a/editor.c b/editor.c
index 01c644c..4c5874b 100644
--- a/editor.c
+++ b/editor.c
@@ -29,10 +29,22 @@ 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 *sequence_editor = getenv("GIT_SEQUENCE_EDITOR");
+
+	if (sequence_editor && *sequence_editor)
+		return sequence_editor;
 
+	git_config_get_string_const("sequence.editor", &sequence_editor);
+	if (sequence_editor && *sequence_editor)
+		return sequence_editor;
+
+	return git_editor();
+}
+
+static int launch_specific_editor(const char *editor, const char *path, struct strbuf *buffer, const char *const *env)
+{
 	if (!editor)
 		return error("Terminal is dumb, but EDITOR unset");
 
@@ -65,5 +77,16 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 	if (strbuf_read_file(buffer, path, 0) < 0)
 		return error("could not read file '%s': %s",
 				path, strerror(errno));
+
 	return 0;
 }
+
+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+	return launch_specific_editor(git_editor(), path, buffer, env);
+}
+
+int launch_sequence_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+	return launch_specific_editor(git_sequence_editor(), path, buffer, env);
+}
diff --git a/strbuf.h b/strbuf.h
index f72fd14..aebdcd7 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -524,6 +524,7 @@ 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.7.0
Previous: Paul TanNext: Johannes Schindelin
Message 47 of 59 in “A barebones git-rebase in C”
  1. 00/17 A barebones git-rebase in CPaul Tan, Mar 12, 2016
  2. 01/17 perf: introduce performance tests for git-rebasePaul Tan, Mar 12, 2016
  3. Johannes SchindelinMar 16, 2016
  4. Paul TanMar 16, 2016
  5. Johannes SchindelinMar 16, 2016
  6. Thomas GummererMar 18, 2016
  7. Johannes SchindelinMar 18, 2016
  8. Thomas GummererMar 20, 2016
  9. Johannes SchindelinMar 21, 2016
  10. 02/17 sha1_name: implement get_oid() and friendsPaul Tan, Mar 12, 2016
  11. 03/17 builtin-rebase: implement skeletal builtin rebasePaul Tan, Mar 12, 2016
  12. Stefan BellerMar 14, 2016
  13. Johannes SchindelinMar 15, 2016
  14. 04/17 builtin-rebase: parse rebase arguments into a common rebase_options structPaul Tan, Mar 12, 2016
  15. Stefan BellerMar 14, 2016
  16. Johannes SchindelinMar 15, 2016
  17. 05/17 rebase-options: implement rebase_options_load() and rebase_options_save()Paul Tan, Mar 12, 2016
  18. Stefan BellerMar 14, 2016
  19. Johannes SchindelinMar 16, 2016
  20. Paul TanMar 16, 2016
  21. Johannes SchindelinMar 16, 2016
  22. Paul TanMar 21, 2016
  23. Paul TanMar 16, 2016
  24. Stefan BellerMar 16, 2016
  25. 06/17 rebase-am: introduce am backend for builtin rebasePaul Tan, Mar 12, 2016
  26. Johannes SchindelinMar 16, 2016
  27. 07/17 rebase-common: implement refresh_and_write_cache()Paul Tan, Mar 12, 2016
  28. Junio C HamanoMar 14, 2016
  29. Paul TanMar 16, 2016
  30. 08/17 rebase-common: let refresh_and_write_cache() take a flags argumentPaul Tan, Mar 12, 2016
  31. 09/17 rebase-common: implement cache_has_unstaged_changes()Paul Tan, Mar 12, 2016
  32. Johannes SchindelinMar 14, 2016
  33. Junio C HamanoMar 14, 2016
  34. Johannes SchindelinMar 15, 2016
  35. Duy NguyenMar 15, 2016
  36. Johannes SchindelinMar 15, 2016
  37. 10/17 rebase-common: implement cache_has_uncommitted_changes()Paul Tan, Mar 12, 2016
  38. 11/17 rebase-merge: introduce merge backend for builtin rebasePaul Tan, Mar 12, 2016
  39. 12/17 rebase-todo: introduce rebase_todo_itemPaul Tan, Mar 12, 2016
  40. Christian CouderMar 14, 2016
  41. Johannes SchindelinMar 14, 2016
  42. Paul TanMar 16, 2016
  43. Johannes SchindelinMar 16, 2016
  44. 13/17 rebase-todo: introduce rebase_todo_listPaul Tan, Mar 12, 2016
  45. 14/17 status: use rebase_todo_listPaul Tan, Mar 12, 2016
  46. 15/17 wrapper: implement append_file()Paul Tan, Mar 12, 2016
  47. 16/17 editor: implement git_sequence_editor() and launch_sequence_editor()Paul Tan, Mar 12, 2016
  48. Johannes SchindelinMar 15, 2016
  49. Paul TanMar 16, 2016
  50. Johannes SchindelinMar 16, 2016
  51. 17/17 rebase-interactive: introduce interactive backend for builtin rebasePaul Tan, Mar 12, 2016
  52. Johannes SchindelinMar 15, 2016
  53. Paul TanMar 15, 2016
  54. Johannes SchindelinMar 15, 2016
  55. Duy NguyenMar 14, 2016
  56. Stefan BellerMar 14, 2016
  57. Junio C HamanoMar 14, 2016
  58. Paul TanMar 16, 2016
  59. Johannes SchindelinMar 14, 2016

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.