From 8babab95af7c01d9ea75c97ee0df40e5a2170b83 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 26 Nov 2007 09:59:27 +0100 Subject: [PATCH] builtin-commit.c: export GIT_INDEX_FILE for launch_editor as well. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The editor program to let the user edit the log message used to get GIT_INDEX_FILE environment variable pointing at the right file, but this was lost when git-commit was rewritten in C. Signed-off-by: Pierre Habouzit Acked-by: Kristian Høgsberg Signed-off-by: Junio C Hamano --- builtin-commit.c | 9 ++++++--- builtin-tag.c | 6 +++--- strbuf.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/builtin-commit.c b/builtin-commit.c index 4de316a36..f60bd7f4d 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -748,9 +748,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix) /* Get the commit message and validate it */ header_len = sb.len; - if (!no_edit) - launch_editor(git_path(commit_editmsg), &sb); - else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { + if (!no_edit) { + char index[PATH_MAX]; + const char *env[2] = { index, NULL }; + snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); + launch_editor(git_path(commit_editmsg), &sb, env); + } else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { rollback_index_files(); die("could not read commit message\n"); } diff --git a/builtin-tag.c b/builtin-tag.c index 566b9d186..7626da3f4 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -17,7 +17,7 @@ static const char builtin_tag_usage[] = static char signingkey[1000]; -void launch_editor(const char *path, struct strbuf *buffer) +void launch_editor(const char *path, struct strbuf *buffer, const char *const *env) { const char *editor, *terminal; @@ -43,7 +43,7 @@ void launch_editor(const char *path, struct strbuf *buffer) if (strcmp(editor, ":")) { const char *args[] = { editor, path, NULL }; - if (run_command_v_opt(args, 0)) + if (run_command_v_opt_cd_env(args, 0, NULL, env)) die("There was a problem with the editor %s.", editor); } @@ -312,7 +312,7 @@ static void create_tag(const unsigned char *object, const char *tag, write_or_die(fd, tag_template, strlen(tag_template)); close(fd); - launch_editor(path, buf); + launch_editor(path, buf, NULL); unlink(path); free(path); diff --git a/strbuf.h b/strbuf.h index 8334a9bad..36d61db65 100644 --- a/strbuf.h +++ b/strbuf.h @@ -117,6 +117,6 @@ extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint); extern int strbuf_getline(struct strbuf *, FILE *, int); extern void stripspace(struct strbuf *buf, int skip_comments); -extern void launch_editor(const char *path, struct strbuf *buffer); +extern void launch_editor(const char *path, struct strbuf *buffer, const char *const *env); #endif /* STRBUF_H */ -- 2.26.2