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