git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow commit (and tag) messages to be edited when $EDITOR has arguments
@ 2007-12-16  1:12 Steven Grimm
  2007-12-16  1:41 ` Johannes Schindelin
  2007-12-16  1:41 ` [PATCH] " Thomas Harning
  0 siblings, 2 replies; 5+ messages in thread
From: Steven Grimm @ 2007-12-16  1:12 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-16 15:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-16  1:12 [PATCH] Allow commit (and tag) messages to be edited when $EDITOR has arguments Steven Grimm
2007-12-16  1:41 ` Johannes Schindelin
2007-12-16  7:34   ` [PATCH v2] " Steven Grimm
2007-12-16 15:36     ` Johannes Schindelin
2007-12-16  1:41 ` [PATCH] " Thomas Harning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).