"removed, then the edit is\n"
"aborted and the hunk is left unchanged.\n"));
- if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0)
+ if (strbuf_edit_interactively(the_repository, &s->buf,
+ "addp-hunk-edit.diff", NULL) < 0)
return -1;
/* strip out commented lines */
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)
unlink(path);
}
- free(path2);
+ strbuf_release(&sb);
return res;
}
#ifndef EDITOR_H
#define EDITOR_H
+struct repository;
struct strbuf;
const char *git_editor(void);
*
* If `path` is relative, it refers to a file in the `.git` directory.
*/
-int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
- const char *const *env);
+int strbuf_edit_interactively(struct repository *r, struct strbuf *buffer,
+ const char *path, const char *const *env);
#endif