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

Subsystems: the rest

DORMANTno replies

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

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

From: Luciano Rocha <hidden>
Date: 2016-06-15 22:44:00

The previous sh version of git-commit evaluated the value of the defined
editor, thus allowing arguments.

Make the builtin version work the same, by adding an explicit check for
arguments in the editor command, and extract them to an additional argument.

Signed-off-by: Luciano Rocha <redacted>
---
 builtin-tag.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

I personally use EDITOR="gvim -f", thus this patch.

Created on top of ce85b053d827e2f7c2ee2683cc09393e4768cc22, 
git-describe is now: v1.5.4-rc0-75-g5f791e5
diff --git a/builtin-tag.c b/builtin-tag.c
index 274901a..57dcfe0 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -46,7 +46,18 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
 	if (!editor)
 		editor = "vi";
 
-	if (strcmp(editor, ":")) {
+	if (strstr(editor, " -")) {
+		char *editor_cmd = xstrdup(editor);
+		char *editor_sep = strstr(editor_cmd, " -");
+		const char *args[] = { editor_cmd, editor_sep + 1,
+			path, NULL };
+
+		*editor_sep = '\0';
+
+		if (run_command_v_opt_cd_env(args, 0, NULL, env))
+			die("There was a problem with the editor %s.",
+					editor_cmd);
+	} else if (strcmp(editor, ":")) {
 		const char *args[] = { editor, path, NULL };
 
 		if (run_command_v_opt_cd_env(args, 0, NULL, env))
-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>

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

From: Luciano Rocha <hidden>
Date: 2016-06-15 22:44:00

The previous sh version of git-commit evaluated the value of the defined
editor, thus allowing arguments.

Make the builtin version work the same, by adding an explicit check for
arguments in the editor command, and extract them to an additional argument.

Signed-off-by: Luciano Rocha <redacted>
---
 builtin-tag.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

I personally use EDITOR="gvim -f", thus this patch.
Now with free() of temporary buffer.
diff --git a/builtin-tag.c b/builtin-tag.c
index 274901a..0e8575e 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -46,7 +46,19 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
 	if (!editor)
 		editor = "vi";
 
-	if (strcmp(editor, ":")) {
+	if (strstr(editor, " -")) {
+		char *editor_cmd = xstrdup(editor);
+		char *editor_sep = strstr(editor_cmd, " -");
+		const char *args[] = { editor_cmd, editor_sep + 1,
+			path, NULL };
+
+		*editor_sep = '\0';
+
+		if (run_command_v_opt_cd_env(args, 0, NULL, env))
+			die("There was a problem with the editor %s.",
+					editor_cmd);
+		free(editor_cmd);
+	} else if (strcmp(editor, ":")) {
 		const char *args[] = { editor, path, NULL };
 
 		if (run_command_v_opt_cd_env(args, 0, NULL, env))
-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>

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

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

Hi,

On Thu, 20 Dec 2007, Luciano Rocha wrote:
The previous sh version of git-commit evaluated the value of the defined 
editor, thus allowing arguments.

Make the builtin version work the same, by adding an explicit check for 
arguments in the editor command, and extract them to an additional 
argument.
Anything wrong with that patch?

http://article.gmane.org/gmane.comp.version-control.git/68444

Ciao,
Dscho

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

From: Luciano Rocha <hidden>
Date: 2016-06-15 22:44:00

On Thu, Dec 20, 2007 at 12:58:59PM +0100, Johannes Schindelin wrote:
Hi,

On Thu, 20 Dec 2007, Luciano Rocha wrote:
quoted
The previous sh version of git-commit evaluated the value of the defined 
editor, thus allowing arguments.

Make the builtin version work the same, by adding an explicit check for 
arguments in the editor command, and extract them to an additional 
argument.
Anything wrong with that patch?

http://article.gmane.org/gmane.comp.version-control.git/68444
No, I just missed it in the mailing list. That patch also supports any
number of whitespace/arguments.

-- 
Luciano Rocha [off-list ref]
Eurotux Informática, S.A. <http://www.eurotux.com/>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help