From: Steven Grimm <koreth@midwinter.com>
To: git@vger.kernel.org
Subject: [PATCH] Allow commit (and tag) messages to be edited when $EDITOR has arguments
Date: Sat, 15 Dec 2007 17:12:01 -0800 [thread overview]
Message-ID: <20071216011201.GA10867@midwinter.com> (raw)
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
next reply other threads:[~2007-12-16 1:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-16 1:12 Steven Grimm [this message]
2007-12-16 1:41 ` [PATCH] Allow commit (and tag) messages to be edited when $EDITOR has arguments 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
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=20071216011201.GA10867@midwinter.com \
--to=koreth@midwinter.com \
--cc=git@vger.kernel.org \
/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).