Git fork

editor: do not rely on `the_repository` for interactive edits

We implicitly rely on `the_repository` when editing a file interactively
because we call `git_path()`. Adapt the function to instead take a
`struct repository` as a parameter so that we can remove this hidden
dependency.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
419dbb29 61419a42

+13 -8
+2 -1
add-patch.c
··· 1140 1140 "removed, then the edit is\n" 1141 1141 "aborted and the hunk is left unchanged.\n")); 1142 1142 1143 - if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0) 1143 + if (strbuf_edit_interactively(the_repository, &s->buf, 1144 + "addp-hunk-edit.diff", NULL) < 0) 1144 1145 return -1; 1145 1146 1146 1147 /* strip out commented lines */
+8 -5
editor.c
··· 133 133 return launch_specified_editor(git_sequence_editor(), path, buffer, env); 134 134 } 135 135 136 - int strbuf_edit_interactively(struct strbuf *buffer, const char *path, 136 + int strbuf_edit_interactively(struct repository *r, 137 + struct strbuf *buffer, const char *path, 137 138 const char *const *env) 138 139 { 139 - char *path2 = NULL; 140 + struct strbuf sb = STRBUF_INIT; 140 141 int fd, res = 0; 141 142 142 - if (!is_absolute_path(path)) 143 - path = path2 = xstrdup(git_path("%s", path)); 143 + if (!is_absolute_path(path)) { 144 + strbuf_repo_git_path(&sb, r, "%s", path); 145 + path = sb.buf; 146 + } 144 147 145 148 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); 146 149 if (fd < 0) ··· 157 160 unlink(path); 158 161 } 159 162 160 - free(path2); 163 + strbuf_release(&sb); 161 164 return res; 162 165 }
+3 -2
editor.h
··· 1 1 #ifndef EDITOR_H 2 2 #define EDITOR_H 3 3 4 + struct repository; 4 5 struct strbuf; 5 6 6 7 const char *git_editor(void); ··· 28 29 * 29 30 * If `path` is relative, it refers to a file in the `.git` directory. 30 31 */ 31 - int strbuf_edit_interactively(struct strbuf *buffer, const char *path, 32 - const char *const *env); 32 + int strbuf_edit_interactively(struct repository *r, struct strbuf *buffer, 33 + const char *path, const char *const *env); 33 34 34 35 #endif