From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, chris.torek@gmail.com,
phillip.wood@dunelm.org.uk, Johannes.Schindelin@gmx.de,
"Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [RFC PATCH 3/3] fixup! editor: allow for saving/restoring terminal state
Date: Wed, 1 Dec 2021 19:54:46 -0800 [thread overview]
Message-ID: <20211202035446.1154-4-carenas@gmail.com> (raw)
In-Reply-To: <20211202035446.1154-1-carenas@gmail.com>
Use DEFAULT_EDITOR instead of another hardcoding of "vi".
Do a minor refactoring to avoid having to call isatty(2) twice,
and while at it, a related reformatting that avoids an overlong
line.
Only check if we should enable saving/restoring the terminal if
the session is interactive.
Add documentation for the configuration variable.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
All of the commit message is meant to be thrown away once/if
this is squashed into the previous commit.
Signed-off-by could be transformed into a Helped-by if anything
could be of use here otherwise.
Documentation/config.txt | 2 ++
Documentation/config/editor.txt | 8 ++++++++
editor.c | 10 ++++++----
3 files changed, 16 insertions(+), 4 deletions(-)
create mode 100644 Documentation/config/editor.txt
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1167e88e34..342f3cc183 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -361,6 +361,8 @@ include::config/diff.txt[]
include::config/difftool.txt[]
+include::config/editor.txt[]
+
include::config/extensions.txt[]
include::config/fastimport.txt[]
diff --git a/Documentation/config/editor.txt b/Documentation/config/editor.txt
new file mode 100644
index 0000000000..b65c2810fa
--- /dev/null
+++ b/Documentation/config/editor.txt
@@ -0,0 +1,8 @@
+editor.stty::
+ A boolean variable that tells git to save and restore its
+ terminal settings when the editor is invoked, to avoid
+ being affected by garbled input/output, if it misbehaves.
++
+It defaults to 'true' if your editor is "vi" (which is
+also the default if there is no `core.editor`), or to
+'false' otherwise.
diff --git a/editor.c b/editor.c
index 70d3f80966..12180039d2 100644
--- a/editor.c
+++ b/editor.c
@@ -50,7 +50,7 @@ const char *git_sequence_editor(void)
static int prepare_term(const char *editor)
{
- int need_saverestore = !strcmp(editor, "vi");
+ int need_saverestore = !strcmp(editor, DEFAULT_EDITOR);
git_config_get_bool("editor.stty", &need_saverestore);
if (need_saverestore)
@@ -68,8 +68,10 @@ static int launch_specified_editor(const char *editor, const char *path,
struct strbuf realpath = STRBUF_INIT;
const char *args[] = { editor, NULL, NULL };
struct child_process p = CHILD_PROCESS_INIT;
- int ret, sig, need_restore = 0;
- int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && isatty(2);
+ int ret, sig, need_restore;
+ int is_interactive = isatty(2);
+ int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) &&
+ is_interactive;
if (print_waiting_for_editor) {
/*
@@ -94,7 +96,7 @@ static int launch_specified_editor(const char *editor, const char *path,
p.env = env;
p.use_shell = 1;
p.trace2_child_class = "editor";
- need_restore = prepare_term(editor);
+ need_restore = is_interactive ? prepare_term(editor) : 0;
if (start_command(&p) < 0) {
if (need_restore)
restore_term();
--
2.34.1.460.g364565cfab
prev parent reply other threads:[~2021-12-02 3:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-02 3:54 [RFC PATCH 0/3] editor: teach it to protect itself from rogue editors Carlo Marcelo Arenas Belón
2021-12-02 3:54 ` [RFC PATCH 1/3] terminal: teach save_term to fail when not foreground Carlo Marcelo Arenas Belón
2021-12-02 3:54 ` [RFC PATCH 2/3] editor: allow for saving/restoring terminal state Carlo Marcelo Arenas Belón
2021-12-02 6:35 ` Junio C Hamano
2021-12-02 3:54 ` Carlo Marcelo Arenas Belón [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211202035446.1154-4-carenas@gmail.com \
--to=carenas@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chris.torek@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).