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

[PATCH] Allow commit (and tag) messages to be edited when $EDITOR has arguments

From
Steven Grimm <koreth@midwinter.com>
Date
Dec 16, 2007, 01:12 UTC
Message-ID
<20071216011201.GA10867@midwinter.com>

Users who do EDITOR="/usr/bin/emacs -nw" or similar were left unable to edit commit messages once commit became a builtin, because the editor launch code assumed that $EDITOR was a single pathname.

Signed-off-by: Steven Grimm <koreth@midwinter.com>
---
	Looked around but didn't see an existing "build a char* array
	out of a delimited string" function in the git source; if one
	exists, of course it should be used instead of my pair of loops
	here.
 builtin-tag.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 274901a..dace758 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -47,10 +47,35 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
 		editor = "vi";
 
 	if (strcmp(editor, ":")) {
-		const char *args[] = { editor, path, NULL };
+		char *editor_copy, *c;
+		int args_size = 3, args_pos = 0;
+		char **args;
+
+		/* Parse the editor command, since it can contain arguments.
+		 * First count the number of arguments so we can allocate an
+		 * appropriately-sized arg array.
+		 */
+		editor_copy = xstrdup(editor);
+		for (c = editor_copy; *c != '\0'; c++) {
+			if (*c == ' ') {
+				args_size++;
+			}
+		}
+
+		args = xmalloc(sizeof(char *) * args_size);
+		for (c = strtok(editor_copy, " "); c != NULL;
+		     c = strtok(NULL, " ")) {
+			args[args_pos++] = c;
+		}
+
+		args[args_pos++] = path;
+		args[args_pos++] = NULL;
 
 		if (run_command_v_opt_cd_env(args, 0, NULL, env))
 			die("There was a problem with the editor %s.", editor);
+
+		free(args);
+		free(editor_copy);
 	}
 
 	if (!buffer)
-- 
1.5.4.rc0
Next: Johannes Schindelin
Message 1 of 5 in “Allow commit (and tag) messages to be edited when $EDITOR has arguments”
  1. Allow commit (and tag) messages to be edited when $EDITOR has argumentsSteven Grimm, Dec 16, 2007
  2. Johannes SchindelinDec 16, 2007
  3. Allow commit (and tag) messages to be edited when $EDITOR has argumentsSteven Grimm, Dec 16, 2007
  4. Johannes SchindelinDec 16, 2007
  5. Thomas HarningDec 16, 2007

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.