git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: preparing for 2.34.1

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 22, 2021, 22:28 UTC
Message-ID
<nycvar.QRO.7.76.6.2111222319100.63@tvgsbejvaqbjf.bet>
In-Reply-To
<CAPUEsphNH9pfQoHqVgJfkQCU-Li45dz4QtGtDjWu5bDV9A3PEg@mail.gmail.com>
Hi Carlo,
On Mon, 22 Nov 2021, Carlo Arenas wrote:
Show 11 quoted lines
> On Mon, Nov 22, 2021 at 11:54 AM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > There are a few topics [*] to fix regressions introduced in the
> > previous cycle
>
> There was another regression report[1] that I just fished out of my
> spam folder and that I introduced in 3d411afabc (editor: save and
> reset terminal after calling EDITOR, 2021-10-05), but that I have not
> yet produced a fix for or fully understood.
>
> The gist is that some people seem to be using a hack[2] dscho posted a
You mean
https://lore.kernel.org/git/nycvar.QRO.7.76.6.1903221436590.41@tvgsbejvaqbjf.bet/
right? I.e. figuring out what Git considers its system config location via
	GIT_EDITOR=echo git config --system -e 2>/dev/null
> few years ago to get info from git programmatically and I just didn't
> expect someone would try to invoke the EDITOR unless they had a
> terminal, so the fix might be to just add an isatty(0) call, but
> reverting that commit would be also an option.

The quickest workaround for this is probably to special-case the editor `echo`:

-- snip --
diff --git a/editor.c b/editor.c
index 674309eed8bd..1b97f7da9920 100644
--- a/editor.c
+++ b/editor.c
@@ -51,12 +51,11 @@ const char *git_sequence_editor(void)
 static int launch_specified_editor(const char *editor, const char *path,
 				   struct strbuf *buffer, const char *const *env)
 {
-	int term_fail;
-
 	if (!editor)
 		return error("Terminal is dumb, but EDITOR unset");

 	if (strcmp(editor, ":")) {
+		int save_and_restore_term = strcmp(editor, "echo");
 		struct strbuf realpath = STRBUF_INIT;
 		const char *args[] = { editor, NULL, NULL };
 		struct child_process p = CHILD_PROCESS_INIT;
@@ -86,9 +85,10 @@ static int launch_specified_editor(const char *editor, const char *path,
 		p.env = env;
 		p.use_shell = 1;
 		p.trace2_child_class = "editor";
-		term_fail = save_term(1);
+		if (save_and_restore_term)
+			save_and_restore_term = !save_term(1);
 		if (start_command(&p) < 0) {
-			if (!term_fail)
+			if (save_and_restore_term)
 				restore_term();
 			strbuf_release(&realpath);
 			return error("unable to start editor '%s'", editor);
@@ -97,7 +97,7 @@ 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 (!term_fail)
+		if (!save_and_restore_term)
 			restore_term();
 		strbuf_release(&realpath);
 		sig = ret - 128;
-- snap --

However, I could imagine that other scenarios call for an editor that
_also_ does not run in the terminal, and where also no real terminal is
available for saving and restoring.

I was tempted to suggest an `isatty(2)`, but that probably comes with its
own problems, too.

Ciao,
Dscho

>
> Carlo
>
> [1] https://lore.kernel.org/git/ee302c98-da27-da43-e684-c7ec8b225360@gmx.net/
> [2] https://yhbt.net/lore/all/nycvar.QRO.7.76.6.1903221436590.41@tvgsbejvaqbjf.bet/T/
>
>
Previous: Carlo ArenasNext: Junio C Hamano
Message 3 of 10 in “preparing for 2.34.1”
  1. Junio C HamanoNov 22, 2021
  2. Carlo ArenasNov 22, 2021
  3. Johannes SchindelinNov 22, 2021
  4. Junio C HamanoNov 22, 2021
  5. Johannes SchindelinNov 22, 2021
  6. rsbecker@nexbridge.comNov 22, 2021
  7. Carlo ArenasNov 22, 2021
  8. Derrick StoleeNov 22, 2021
  9. Junio C HamanoNov 22, 2021
  10. preparing for 2.34.1 (2nd round)Junio C Hamano, Nov 23, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.