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

Subsystems: the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:00

Johannes Schindelin [off-list ref] 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);
	

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

From: Steven Grimm <hidden>
Date: 2016-06-15 22:44:01

On Dec 20, 2007, at 2:14 PM, Junio C Hamano wrote:
I think Steven stopped after you poked holes in that patch.
Nah, just entered a particularly busy period in my day job and haven't  
had time to do much more git stuff than occasionally skim the mailing  
list. I do plan to revisit that at some point unless the patch in your  
mail ends up being what we go with. (It seems like a sensible approach  
to me.)

-Steve

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:44:01

Hi,

On Thu, 20 Dec 2007, Junio C Hamano wrote:
I think something like this patch is probably more appropriate.
Looks obviously fine, especially thinking about this:
	GIT_EDITOR='emacs -l $HOME/my-customization.el'
Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help