From b38dd9e7151f118b989f8c9851bc38a8a8733eaf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 13 Dec 2019 08:08:00 +0000 Subject: strbuf: add a helper function to call the editor "on an strbuf" This helper supports the scenario where Git has a populated `strbuf` and wants to let the user edit it interactively. In `git add -p`, we will use this to allow interactive hunk editing: the diff hunks are already in memory, but we need to write them out to a file so that an editor can be launched, then read everything back once the user is done editing. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- strbuf.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 84cf969721..bfa66569a4 100644 --- a/strbuf.h +++ b/strbuf.h @@ -621,6 +621,17 @@ int launch_editor(const char *path, struct strbuf *buffer, int launch_sequence_editor(const char *path, struct strbuf *buffer, const char *const *env); +/* + * In contrast to `launch_editor()`, this function writes out the contents + * of the specified file first, then clears the `buffer`, then launches + * the editor and reads back in the file contents into the `buffer`. + * Finally, it deletes the temporary file. + * + * 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); + void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, -- cgit v1.2.3