@matheusbsbs / matheus-bagliano / commits / 8babab95af
Fork 0

builtin-commit.c: export GIT_INDEX_FILE for launch_editor as well.

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 <madcoder@debian.org> Acked-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Nov 26, 2007 at 09:59 UTC 8babab95af7c01d9ea75c97ee0df40e5a2170b83
3 files changed +10 -7
builtin-commit.c
+6 -3
@@ -748,9 +748,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
748
749 /* Get the commit message and validate it */
750 header_len = sb.len;
751 - if (!no_edit)
752 - launch_editor(git_path(commit_editmsg), &sb);
753 - else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
751 + if (!no_edit) {
752 + char index[PATH_MAX];
753 + const char *env[2] = { index, NULL };
754 + snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
755 + launch_editor(git_path(commit_editmsg), &sb, env);
756 + } else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
757 rollback_index_files();
758 die("could not read commit message\n");
759 }
builtin-tag.c
+3 -3
@@ -17,7 +17,7 @@ static const char builtin_tag_usage[] =
17
18 static char signingkey[1000];
19
20 -void launch_editor(const char *path, struct strbuf *buffer)
20 +void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
21 {
22 const char *editor, *terminal;
23
@@ -43,7 +43,7 @@ void launch_editor(const char *path, struct strbuf *buffer)
43 if (strcmp(editor, ":")) {
44 const char *args[] = { editor, path, NULL };
45
46 - if (run_command_v_opt(args, 0))
46 + if (run_command_v_opt_cd_env(args, 0, NULL, env))
47 die("There was a problem with the editor %s.", editor);
48 }
49
@@ -312,7 +312,7 @@ static void create_tag(const unsigned char *object, const char *tag,
312 write_or_die(fd, tag_template, strlen(tag_template));
313 close(fd);
314
315 - launch_editor(path, buf);
315 + launch_editor(path, buf, NULL);
316
317 unlink(path);
318 free(path);
strbuf.h
+1 -1
@@ -117,6 +117,6 @@ extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
117 extern int strbuf_getline(struct strbuf *, FILE *, int);
118
119 extern void stripspace(struct strbuf *buf, int skip_comments);
120 -extern void launch_editor(const char *path, struct strbuf *buffer);
120 +extern void launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
121
122 #endif /* STRBUF_H */