diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-08-13 11:13:25 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-08-13 10:01:00 -0700 |
| commit | 419dbb29d82b78bcaf0ff22ac7d5db7d1c327575 (patch) | |
| tree | 43c8322954e0ad8da0e2e60fd3e692ede6c89b92 /editor.c | |
| parent | 61419a42f641c7b9f7bfc9585e3ec9c393ab0166 (diff) | |
| download | git-419dbb29d82b78bcaf0ff22ac7d5db7d1c327575.tar.xz | |
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>
Diffstat (limited to 'editor.c')
| -rw-r--r-- | editor.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -133,14 +133,17 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer, return launch_specified_editor(git_sequence_editor(), path, buffer, env); } -int strbuf_edit_interactively(struct strbuf *buffer, const char *path, +int strbuf_edit_interactively(struct repository *r, + struct strbuf *buffer, const char *path, const char *const *env) { - char *path2 = NULL; + struct strbuf sb = STRBUF_INIT; int fd, res = 0; - if (!is_absolute_path(path)) - path = path2 = xstrdup(git_path("%s", path)); + if (!is_absolute_path(path)) { + strbuf_repo_git_path(&sb, r, "%s", path); + path = sb.buf; + } fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) @@ -157,6 +160,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path, unlink(path); } - free(path2); + strbuf_release(&sb); return res; } |
