{"thread":{"id":"55904","subject":"Wrong tabs in terminal output for git diff","startedAt":"2021-06-11T19:26:37Z","lastAt":"2021-06-14T01:26:14Z","messageCount":5,"participants":["Timothy Madden","Felipe Contreras","Phil Hord","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"427146","messageId":"8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com","threadId":"55904","inReplyTo":null,"subject":"Wrong tabs in terminal output for git diff","fromName":"Timothy Madden","fromEmail":"terminatorul@gmail.com","sentAt":"2021-06-11T19:25:24Z","receivedAt":"2021-06-11T19:26:37Z","isPatch":false,"sender":{"key":"terminatorul@gmail.com","avatar":null},"body":"Hello,\n\nFor git diff and git show commands, terminal output appears with wrong \ntab stops (missaligned).\n\nBecause diff operation inserts a new column at character position 1, for \nthe +, - and space characters, the diff content appears shifted to the \nright by 1 column. But not the tab stop positions. So relative to the \ntext, the tab stops now appear off-by-one (shifted to the left).\n\nThis results in text that appearing missaligned, even though the \noriginal file looks fine before the diff.\n\nI believe this is not a new issue, since git gui does the right thing \nand the tab stops are aligned properly in the GUI.\n\nIs it possible please to fix diff output as well, when used in the \nterminal (interactive mode) ?\n\n(I can include screenshots but I am not sure what the mailing list \npolicy is about that)\n\n--\nThank you,\nTimothy Madden\n\n"},{"id":"427152","messageId":"60c3d0dc6a663_8d0f208e2@natae.notmuch","threadId":"55904","inReplyTo":"8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com","subject":"RE: Wrong tabs in terminal output for git diff","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-11T21:08:44Z","receivedAt":"2021-06-11T21:09:04Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Timothy Madden wrote:\n> Is it possible please to fix diff output as well, when used in the \n> terminal (interactive mode) ?\n> \n> (I can include screenshots but I am not sure what the mailing list \n> policy is about that)\n\nYou can upload screenshots to an online service:\nhttps://snipboard.io/\n\n-- \nFelipe Contreras\n"},{"id":"427195","messageId":"CABURp0pUDtKEDcFx+Yh3hZRXnHOzUxiOEU=epBz3SB1O5e2HqA@mail.gmail.com","threadId":"55904","inReplyTo":"8d3f8cf4-24ec-1271-ccd3-70db24f53523@gmail.com","subject":"Re: Wrong tabs in terminal output for git diff","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2021-06-12T23:10:04Z","receivedAt":"2021-06-12T23:10:36Z","isPatch":false,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Fri, Jun 11, 2021 at 12:30 PM Timothy Madden <terminatorul@gmail.com> wrote:\n> For git diff and git show commands, terminal output appears with wrong\n> tab stops (missaligned).\n>\n> Because diff operation inserts a new column at character position 1, for\n> the +, - and space characters, the diff content appears shifted to the\n> right by 1 column. But not the tab stop positions. So relative to the\n> text, the tab stops now appear off-by-one (shifted to the left).\n\nI think \"fixing\" this would require modifying the diff output so it\nwould no longer be correct. If we accept that a switch can make a\nincorrect diff for display only, though, it seems something could be\ndone here.\n\nI think the only approach that can fix the alignment, however, is to\nremove the +/- prefix markers altogether.  We do this now with the\n`--color-words` switch. This kind of solution only works if there is\nsome way to indicate added/removed lines other than the line-prefix\nmarker; ANSI color codes, for example.  Would that work for your\nneeds, or were you thinking of something else?\n"},{"id":"427208","messageId":"YMWD6G14YxfM1uE6@coredump.intra.peff.net","threadId":"55904","inReplyTo":"CABURp0pUDtKEDcFx+Yh3hZRXnHOzUxiOEU=epBz3SB1O5e2HqA@mail.gmail.com","subject":"Re: Wrong tabs in terminal output for git diff","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-06-13T04:04:56Z","receivedAt":"2021-06-13T04:04:59Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jun 12, 2021 at 04:10:04PM -0700, Phil Hord wrote:\n\n> On Fri, Jun 11, 2021 at 12:30 PM Timothy Madden <terminatorul@gmail.com> wrote:\n> > For git diff and git show commands, terminal output appears with wrong\n> > tab stops (missaligned).\n> >\n> > Because diff operation inserts a new column at character position 1, for\n> > the +, - and space characters, the diff content appears shifted to the\n> > right by 1 column. But not the tab stop positions. So relative to the\n> > text, the tab stops now appear off-by-one (shifted to the left).\n> \n> I think \"fixing\" this would require modifying the diff output so it\n> would no longer be correct. If we accept that a switch can make a\n> incorrect diff for display only, though, it seems something could be\n> done here.\n\nWe do have a few \"display only\" modes. You mentioned --color-words, but\n--textconv is similar (and of course --ext-diff can generate whatever it\nwants). I'm not sure how helpful that is, though, because humans end up\nneeding to look at \"real\" diffs that can be applied often enough (and as\nyou note, changing those would break them).\n\nThis could be addressed at the viewing layer, though, which is what's\nconverting the tabstops to screen positions. For example, \"less -x9,17\"\nadjusts the tab stops in the pager to account for the extra leading\ncharacter (and you can put it into $LESS or $GIT_PAGER to have it kick\nin automatically).\n\n> I think the only approach that can fix the alignment, however, is to\n> remove the +/- prefix markers altogether.  We do this now with the\n> `--color-words` switch. This kind of solution only works if there is\n> some way to indicate added/removed lines other than the line-prefix\n> marker; ANSI color codes, for example.  Would that work for your\n> needs, or were you thinking of something else?\n\nThere are other diff-viewing projects which can be used as a Git pager\nto do stuff like this. E.g.:\n\n  https://github.com/so-fancy/diff-so-fancy\n\n-Peff\n"},{"id":"427258","messageId":"xmqqa6nt1bkd.fsf@gitster.g","threadId":"55904","inReplyTo":"YMWD6G14YxfM1uE6@coredump.intra.peff.net","subject":"Re: Wrong tabs in terminal output for git diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-14T01:26:10Z","receivedAt":"2021-06-14T01:26:14Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> We do have a few \"display only\" modes. You mentioned --color-words, but\n> --textconv is similar (and of course --ext-diff can generate whatever it\n> wants). I'm not sure how helpful that is, though, because humans end up\n> needing to look at \"real\" diffs that can be applied often enough (and as\n> you note, changing those would break them).\n\nAdd \"--irreversible-delete\" to the set.  We should perhaps find a\nmigration path to eventually disable these \"display only\" things in\nformat-patch [*1*], if we do not already do so.\n\n> This could be addressed at the viewing layer, though, which is what's\n> converting the tabstops to screen positions. For example, \"less -x9,17\"\n> adjusts the tab stops in the pager to account for the extra leading\n> character (and you can put it into $LESS or $GIT_PAGER to have it kick\n> in automatically).\n\nThat's a cute one (and can be used not just on \"git diff\" output but\non output from \"diff\" by other people).\n\nThanks.\n\n\n[References]\n\n*1* https://lore.kernel.org/git/7vsj8dcdv6.fsf@alter.siamese.dyndns.org/\n\n"}]}