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

Re: [PATCH v2] builtin-tag.c: allow arguments in $EDITOR

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 20, 2007, 22:14 UTC
Message-ID
<7vhcidovxt.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<Pine.LNX.4.64.0712201255510.14355@wbgn129.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> Anything wrong with that patch?
>
> http://article.gmane.org/gmane.comp.version-control.git/68444
I think Steven stopped after you poked holes in that patch.
The way scripted commands spawned editor is:
	eval "${GIT_EDITOR:=vi}" '"$@"'

which meant that $IFS characters in $GIT_EDITOR separated words and $environment_variables were substituted.

IOW, this is possible:
	GIT_EDITOR='emacs -l $HOME/my-customization.el'

I think something like this patch is probably more appropriate. It avoids potential bugs in splitting arguments by hand and lets the shell deal with the issue.

---
 builtin-tag.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 274901a..fae2487 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -47,7 +47,19 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
 		editor = "vi";
 
 	if (strcmp(editor, ":")) {
-		const char *args[] = { editor, path, NULL };
+		size_t len = strlen(editor);
+		int i = 0;
+		const char *args[6];
+
+		if (strcspn(editor, "$ \t'") != len) {
+			/* there are specials */
+			args[i++] = "sh";
+			args[i++] = "-c";
+			args[i++] = "$0 \"$@\"";
+		}
+		args[i++] = editor;
+		args[i++] = path;
+		args[i] = NULL;
 
 		if (run_command_v_opt_cd_env(args, 0, NULL, env))
 			die("There was a problem with the editor %s.", editor);

	
Previous: Luciano RochaNext: Steven Grimm
Message 5 of 7 in “builtin-tag.c: allow arguments in $EDITOR”
  1. builtin-tag.c: allow arguments in $EDITORLuciano Rocha, Dec 19, 2007
  2. builtin-tag.c: allow arguments in $EDITORLuciano Rocha, Dec 20, 2007
  3. Johannes SchindelinDec 20, 2007
  4. Luciano RochaDec 20, 2007
  5. Junio C HamanoDec 20, 2007
  6. Steven GrimmDec 21, 2007
  7. Johannes SchindelinDec 22, 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.