зеркало из https://github.com/microsoft/git.git
Partially un-revert "editor: save and reset terminal after calling EDITOR"
In e3f7e01b50
(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 <johannes.schindelin@gmx.de>
This commit is contained in:
Родитель
e1f86baa8f
Коммит
d5e229528b
8
editor.c
8
editor.c
|
@ -12,6 +12,7 @@
|
|||
#include "run-command.h"
|
||||
#include "sigchain.h"
|
||||
#include "wrapper.h"
|
||||
#include "compat/terminal.h"
|
||||
|
||||
#ifndef DEFAULT_EDITOR
|
||||
#define DEFAULT_EDITOR "vi"
|
||||
|
@ -63,6 +64,7 @@ static int launch_specified_editor(const char *editor, const char *path,
|
|||
return error("Terminal is dumb, but EDITOR unset");
|
||||
|
||||
if (strcmp(editor, ":")) {
|
||||
int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");
|
||||
struct strbuf realpath = STRBUF_INIT;
|
||||
struct child_process p = CHILD_PROCESS_INIT;
|
||||
int ret, sig;
|
||||
|
@ -91,7 +93,11 @@ static int launch_specified_editor(const char *editor, const char *path,
|
|||
strvec_pushv(&p.env, (const char **)env);
|
||||
p.use_shell = 1;
|
||||
p.trace2_child_class = "editor";
|
||||
if (save_and_restore_term)
|
||||
save_and_restore_term = !save_term(1);
|
||||
if (start_command(&p) < 0) {
|
||||
if (save_and_restore_term)
|
||||
restore_term();
|
||||
strbuf_release(&realpath);
|
||||
return error("unable to start editor '%s'", editor);
|
||||
}
|
||||
|
@ -99,6 +105,8 @@ static int launch_specified_editor(const char *editor, const char *path,
|
|||
sigchain_push(SIGINT, SIG_IGN);
|
||||
sigchain_push(SIGQUIT, SIG_IGN);
|
||||
ret = finish_command(&p);
|
||||
if (save_and_restore_term)
|
||||
restore_term();
|
||||
strbuf_release(&realpath);
|
||||
sig = ret - 128;
|
||||
sigchain_pop(SIGINT);
|
||||
|
|
Загрузка…
Ссылка в новой задаче