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

Re: git_getpass regression?

From
Jeff King <peff@peff.net>
Date
Jun 29, 2012, 20:30 UTC
Message-ID
<20120629203001.GA12937@sigill.intra.peff.net>
In-Reply-To
<CABPQNSZ4NhEA1CBiCBD_YNJZcnK8u=NtQ3PeDa5c0NDROPDyrQ@mail.gmail.com>
On Fri, Jun 29, 2012 at 10:14:35PM +0200, Erik Faye-Lund wrote:
Show 9 quoted lines
> > Backspace shouldn't be making it to git at all; it should be handled at
> > the terminal input layer, because we are not putting the terminal into
> > raw mode.
> 
> I don't get it. How can the terminal ever interpret the backspace, when
> we've already put the character it's supposed to erase in a strbuf? Sure,
> the echo can be correctly dealt with (probably with the exception of the
> border case of erasing characters from the prompt text), but once we've put
> the characters into a buffer, the terminal cannot erase it.

Because a terminal in non-raw mode is typically line-oriented, and your program doesn't get to see any input at all until the user hits enter.

Try this on your linux box:
  strace -e read cat

You should be able to type characters and backspace erase them, all without seeing any activity from strace. When you hit enter, you should see the full text you typed read as a single syscall.

If the backspacing doesn't work, then there is a configuration mismatch between what linux's tty driver expects and what your terminal emulator is sending (the former is probably expecting ^? as the erase character, and the latter is sending ^H).

Show 5 quoted lines
> > If that is the case, I wonder if your 'stty erase' settings
> > do not match what your terminal emulator is sending.
> 
> I have no idea what that even means. And having to fiddle around with
> terminal settings just makes git feel cheap.

But it's not git that is broken. It's your configuration. Fixing git is a band-aid, and other programs will still be broken. Of course, I may be mis-diagnosing your problem. Did you try this:

> > If you run "stty erase ^H" and then run git, does it work?
?
Show 9 quoted lines
> >  I think (3) is the only sane thing,
> > though. Even if we handled \b, that is not what all terminals generate.
> > In particular, most linux terminal emulators these days will generate
> > DEL (aka ^? or 0x7f) on backspace. This problem needs to be solved at
> > the terminal layer, and I suspect is just a configuration issue in your
> > setup.
>
> As I already said, I don't think this is the case. Inserting 0x7f in a
> strbuf does not delete the preceding char...

Of course not. Control characters should be handled by the terminal driver, and shouldn't make it to git at all. Backspacing works perfectly well on correctly configured systems, and it should not be git's responsibility to care about it at all for line-oriented input (and if we _did_ want to handle it ourselves, we should use a real terminal library like readline or curses).

-Peff
Previous: Jeff KingNext: Erik Faye-Lund
Message 3 of 10 in “git_getpass regression?”
  1. Erik Faye-LundJun 29, 2012
  2. Jeff KingJun 29, 2012
  3. Jeff KingJun 29, 2012
  4. Erik Faye-LundJun 30, 2012
  5. Jeff KingJun 30, 2012
  6. Erik Faye-LundJul 3, 2012
  7. Jeff KingJul 3, 2012
  8. Erik Faye-LundJul 3, 2012
  9. Junio C HamanoJul 18, 2012
  10. Erik Faye-LundJul 18, 2012

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.