# Wrong tabs in terminal output for git diff

5 messages from 2021-06-11 to 2021-06-14. Participants: Timothy Madden, Felipe Contreras, Phil Hord, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/55904

## Timothy Madden, 2021-06-11 19:25

Subject: Wrong tabs in terminal output for git diff
Message-ID: <8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com>
URL: https://gitlist.dev/e/8d3f8cf4-24ec-1271-ccd3-70db24f53523%40gmail.com

```
Hello,

For git diff and git show commands, terminal output appears with wrong 
tab stops (missaligned).

Because diff operation inserts a new column at character position 1, for 
the +, - and space characters, the diff content appears shifted to the 
right by 1 column. But not the tab stop positions. So relative to the 
text, the tab stops now appear off-by-one (shifted to the left).

This results in text that appearing missaligned, even though the 
original file looks fine before the diff.

I believe this is not a new issue, since git gui does the right thing 
and the tab stops are aligned properly in the GUI.

Is it possible please to fix diff output as well, when used in the 
terminal (interactive mode) ?

(I can include screenshots but I am not sure what the mailing list 
policy is about that)

--
Thank you,
Timothy Madden


```

## Felipe Contreras, 2021-06-11 21:08

Subject: RE: Wrong tabs in terminal output for git diff
Message-ID: <60c3d0dc6a663_8d0f208e2@natae.notmuch>
URL: https://gitlist.dev/e/60c3d0dc6a663_8d0f208e2%40natae.notmuch
In-Reply-To: <8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com>

```
Timothy Madden wrote:
> Is it possible please to fix diff output as well, when used in the 
> terminal (interactive mode) ?
> 
> (I can include screenshots but I am not sure what the mailing list 
> policy is about that)

You can upload screenshots to an online service:
https://snipboard.io/

-- 
Felipe Contreras

```

## Phil Hord, 2021-06-12 23:10

Subject: Re: Wrong tabs in terminal output for git diff
Message-ID: <CABURp0pUDtKEDcFx+Yh3hZRXnHOzUxiOEU=epBz3SB1O5e2HqA@mail.gmail.com>
URL: https://gitlist.dev/e/CABURp0pUDtKEDcFx%2BYh3hZRXnHOzUxiOEU%3DepBz3SB1O5e2HqA%40mail.gmail.com
In-Reply-To: <8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com>

```
On Fri, Jun 11, 2021 at 12:30 PM Timothy Madden <terminatorul@gmail.com> wrote:
> For git diff and git show commands, terminal output appears with wrong
> tab stops (missaligned).
>
> Because diff operation inserts a new column at character position 1, for
> the +, - and space characters, the diff content appears shifted to the
> right by 1 column. But not the tab stop positions. So relative to the
> text, the tab stops now appear off-by-one (shifted to the left).

I think "fixing" this would require modifying the diff output so it
would no longer be correct. If we accept that a switch can make a
incorrect diff for display only, though, it seems something could be
done here.

I think the only approach that can fix the alignment, however, is to
remove the +/- prefix markers altogether.  We do this now with the
`--color-words` switch. This kind of solution only works if there is
some way to indicate added/removed lines other than the line-prefix
marker; ANSI color codes, for example.  Would that work for your
needs, or were you thinking of something else?

```

## Jeff King, 2021-06-13 04:04

Subject: Re: Wrong tabs in terminal output for git diff
Message-ID: <YMWD6G14YxfM1uE6@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YMWD6G14YxfM1uE6%40coredump.intra.peff.net
In-Reply-To: <CABURp0pUDtKEDcFx+Yh3hZRXnHOzUxiOEU=epBz3SB1O5e2HqA@mail.gmail.com>

```
On Sat, Jun 12, 2021 at 04:10:04PM -0700, Phil Hord wrote:

> On Fri, Jun 11, 2021 at 12:30 PM Timothy Madden <terminatorul@gmail.com> wrote:
> > For git diff and git show commands, terminal output appears with wrong
> > tab stops (missaligned).
> >
> > Because diff operation inserts a new column at character position 1, for
> > the +, - and space characters, the diff content appears shifted to the
> > right by 1 column. But not the tab stop positions. So relative to the
> > text, the tab stops now appear off-by-one (shifted to the left).
> 
> I think "fixing" this would require modifying the diff output so it
> would no longer be correct. If we accept that a switch can make a
> incorrect diff for display only, though, it seems something could be
> done here.

We do have a few "display only" modes. You mentioned --color-words, but
--textconv is similar (and of course --ext-diff can generate whatever it
wants). I'm not sure how helpful that is, though, because humans end up
needing to look at "real" diffs that can be applied often enough (and as
you note, changing those would break them).

This could be addressed at the viewing layer, though, which is what's
converting the tabstops to screen positions. For example, "less -x9,17"
adjusts the tab stops in the pager to account for the extra leading
character (and you can put it into $LESS or $GIT_PAGER to have it kick
in automatically).

> I think the only approach that can fix the alignment, however, is to
> remove the +/- prefix markers altogether.  We do this now with the
> `--color-words` switch. This kind of solution only works if there is
> some way to indicate added/removed lines other than the line-prefix
> marker; ANSI color codes, for example.  Would that work for your
> needs, or were you thinking of something else?

There are other diff-viewing projects which can be used as a Git pager
to do stuff like this. E.g.:

  https://github.com/so-fancy/diff-so-fancy

-Peff

```

## Junio C Hamano, 2021-06-14 01:26

Subject: Re: Wrong tabs in terminal output for git diff
Message-ID: <xmqqa6nt1bkd.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqa6nt1bkd.fsf%40gitster.g
In-Reply-To: <YMWD6G14YxfM1uE6@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> We do have a few "display only" modes. You mentioned --color-words, but
> --textconv is similar (and of course --ext-diff can generate whatever it
> wants). I'm not sure how helpful that is, though, because humans end up
> needing to look at "real" diffs that can be applied often enough (and as
> you note, changing those would break them).

Add "--irreversible-delete" to the set.  We should perhaps find a
migration path to eventually disable these "display only" things in
format-patch [*1*], if we do not already do so.

> This could be addressed at the viewing layer, though, which is what's
> converting the tabstops to screen positions. For example, "less -x9,17"
> adjusts the tab stops in the pager to account for the extra leading
> character (and you can put it into $LESS or $GIT_PAGER to have it kick
> in automatically).

That's a cute one (and can be used not just on "git diff" output but
on output from "diff" by other people).

Thanks.


[References]

*1* https://lore.kernel.org/git/7vsj8dcdv6.fsf@alter.siamese.dyndns.org/


```
