git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sam Kuper <sam.kuper@uclmail.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Re: Bug report: "Use of uninitialized value $_ in print"
Date: Fri, 2 Mar 2018 20:34:30 +0000	[thread overview]
Message-ID: <CAD-Jur+nRsDnV2YrUwC9pt2aLCYHpEunXFKb22KdZ0sKF-Ga+A@mail.gmail.com> (raw)
In-Reply-To: <xmqqefl2cqsd.fsf@gitster-ct.c.googlers.com>

On 02/03/2018, Junio C Hamano <gitster@pobox.com> wrote:
> Jeff King <peff@peff.net> writes:
>> Unfortunately, I don't think there's an easy way to do what you want
>> (show word-diffs but apply the full diff).
>
> The current "word-diff" discards the information on where the lines
> end, and it is pretty much hopeless/useless in the context of "add
> -p".

This is unfortunate.

I am familiar with the model-view-controller ("MVC") paradigm used in
some software packages. I had hoped that Git followed this paradigm
somewhat, and cleanly separated the underlying model of the diff (i.e.
a representation that would be generated in all cases where a diff is
needed), and the view of the diff (i.e. the visual representation,
e.g. word-diff, line diff, colored, non-colored, etc, as requested by
the user).

Such separation of concerns strikes me as being the best approach
here. It could be a lot of work, but I would be grateful if the Git
developers/maintainers could work towards it as an end goal for this
aspect of Git's architecture.

Unfortunately, I am not very familiar with the Git codebase, nor
well-versed in its primary languages, so I can't be of much help here
:(

> It would be a good addition to revamp it so that it keeps the
> original lines in pre/post images but only colors/highlights the
> byte ranges in such a way that (1) on a pre-image line, paint only
> the byte range that do not appear in the post-image, and (2) on a
> post-image line, paint only the byte range that do not appear in the
> pre-image.
>
> E.g. Given these two
>
>     diff --git a/1 b/2
>     index aa49234b68..1cd9f6b5fd 100644
>     --- a/1
>     +++ b/2
>     @@ -1,2 +1 @@
>     -a b c e
>     -f g i j
>     +a b d f g h
>
> the current word-diff would give (I cannot do colors here, so I'll
> upcase the colored letters):
>
>     @@ -1,2 +1 @@
>     a b C ED f g I JH
>
> as the output, but if we produced
>
>     @@ -1,2 +1 @@
>     -a b C E
>     -f g I J
>     +a b D f g H
>
> instead, then colored "add -p" would become easier to see.
>
> And that would be useful outside the context of "add -p", which is a
> huge plus.

This would be much better than the current situation, where the visual
representation gives misleading feedback about the underlying diff,
and where the error I reported crops up.

However, in my opinion your proposed solution would still be not as
good as separating the two concerns, as described earlier in this
email, on two fronts:

1. It would yield, IIUC, less flexibility to create new kinds of view
based on a consistent, standardised underlying model.

2. It is harder to read, for some types of input (e.g. prose) than the
view generated by the existing word-diff algorithm. Your approach, as
outlined in your example above, requires the reader to visually jump
(saccade) between two lines that are separated by an intervening line,
in order to see what has changed. The existing word-diff is much
easier to use: it puts the changes right next to each other, avoiding
line-skipping and allowing horizontal saccades (which are much more
familiar to people used to languages written in left-to-right or
right-to-left scripts).

I don't want to sound negative. As I say, I think your solution is a
big improvement on what currently exists. But I would see it as an
intermediate solution - a stopgap - rather than an endpoint of
development.

In other words, if your solution would be much quicker to implement
than the one I proposed, then please go ahead with yours first, and
please add mine to the longer-term to-do list :)

Thank you again for helping to make Git such a great tool, and for
working tirelessly to improve it further!

P.S. There is a related StackOverflow question here:
https://stackoverflow.com/questions/49058817/git-add-patch-with-word-diff

  reply	other threads:[~2018-03-02 20:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-02  1:19 Bug report: "Use of uninitialized value $_ in print" Sam Kuper
2018-03-02  7:04 ` Jonathan Nieder
2018-03-02 10:46   ` Jeff King
2018-03-02 16:53     ` Junio C Hamano
2018-03-02 16:55       ` Jeff King
2018-03-02 17:15         ` Junio C Hamano
2018-03-03  5:57           ` Jeff King
2018-03-03  5:58             ` [PATCH 1/2] t3701: add a test for interactive.diffFilter Jeff King
2018-03-03  5:58             ` [PATCH 2/2] add--interactive: detect bogus diffFilter output Jeff King
2018-03-05 20:53               ` Junio C Hamano
2018-03-05 20:56                 ` Jeff King
2018-03-05 21:33               ` Ævar Arnfjörð Bjarmason
2018-03-05 22:09                 ` Junio C Hamano
2018-03-05 22:15                   ` Ævar Arnfjörð Bjarmason
2018-03-05 21:54             ` Bug report: "Use of uninitialized value $_ in print" Jonathan Nieder
2018-03-02 17:28   ` Sam Kuper
2018-03-02 10:42 ` Jeff King
2018-03-02 17:30   ` Sam Kuper
2018-03-03  6:02     ` Jeff King
2018-03-02 17:48   ` Junio C Hamano
2018-03-02 20:34     ` Sam Kuper [this message]
2018-03-02 21:53       ` Junio C Hamano
2018-03-03  6:18         ` Jeff King

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=CAD-Jur+nRsDnV2YrUwC9pt2aLCYHpEunXFKb22KdZ0sKF-Ga+A@mail.gmail.com \
    --to=sam.kuper@uclmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).