Skip to content

Commit 07aa886

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Partially un-revert "editor: save and reset terminal after calling EDITOR"
In e3f7e01 (Revert "editor: save and reset terminal after calling EDITOR", 2021-11-22), we reverted the commit wholesale where the terminal state would be saved and restored before/after calling an editor. The reverted commit was intended to fix a problem with Windows Terminal where simply calling `vi` would cause problems afterwards. To fix the problem addressed by the revert, but _still_ keep the problem with Windows Terminal fixed, let's revert the revert, with a twist: we restrict the save/restore _specifically_ to the case where `vi` (or `vim`) is called, and do not do the same for any other editor. This should still catch the majority of the cases, and will bridge the time until the original patch is re-done in a way that addresses all concerns. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a413c81 commit 07aa886

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

editor.c

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "strbuf.h"
44
#include "run-command.h"
55
#include "sigchain.h"
6+
#include "compat/terminal.h"
67

78
#ifndef DEFAULT_EDITOR
89
#define DEFAULT_EDITOR "vi"
@@ -54,6 +55,7 @@ static int launch_specified_editor(const char *editor, const char *path,
5455
return error("Terminal is dumb, but EDITOR unset");
5556

5657
if (strcmp(editor, ":")) {
58+
int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");
5759
struct strbuf realpath = STRBUF_INIT;
5860
const char *args[] = { editor, NULL, NULL };
5961
struct child_process p = CHILD_PROCESS_INIT;
@@ -83,14 +85,20 @@ static int launch_specified_editor(const char *editor, const char *path,
8385
p.env = env;
8486
p.use_shell = 1;
8587
p.trace2_child_class = "editor";
88+
if (save_and_restore_term)
89+
save_and_restore_term = !save_term(1);
8690
if (start_command(&p) < 0) {
91+
if (save_and_restore_term)
92+
restore_term();
8793
strbuf_release(&realpath);
8894
return error("unable to start editor '%s'", editor);
8995
}
9096

9197
sigchain_push(SIGINT, SIG_IGN);
9298
sigchain_push(SIGQUIT, SIG_IGN);
9399
ret = finish_command(&p);
100+
if (save_and_restore_term)
101+
restore_term();
94102
strbuf_release(&realpath);
95103
sig = ret - 128;
96104
sigchain_pop(SIGINT);

0 commit comments

Comments
 (0)