git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Luciano Rocha <luciano@eurotux.com>, git@vger.kernel.org
Subject: Re: [PATCH v2] builtin-tag.c: allow arguments in $EDITOR
Date: Thu, 20 Dec 2007 14:14:38 -0800	[thread overview]
Message-ID: <7vhcidovxt.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0712201255510.14355@wbgn129.biozentrum.uni-wuerzburg.de> (Johannes Schindelin's message of "Thu, 20 Dec 2007 12:58:59 +0100 (CET)")

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);

	

  parent reply	other threads:[~2007-12-20 22:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-19 23:23 [PATCH] builtin-tag.c: allow arguments in $EDITOR Luciano Rocha
2007-12-20  9:57 ` [PATCH v2] " Luciano Rocha
2007-12-20 11:58   ` Johannes Schindelin
2007-12-20 12:06     ` Luciano Rocha
2007-12-20 22:14     ` Junio C Hamano [this message]
2007-12-21  0:33       ` Steven Grimm
2007-12-22 14:50       ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vhcidovxt.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=luciano@eurotux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).