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

Re: [PATCH] git-add--interactive.perl: Permit word-based diff

From
Jeff King <peff@peff.net>
Date
Jun 18, 2013, 17:23 UTC
Message-ID
<20130618172300.GA3557@sigill.intra.peff.net>
In-Reply-To
<87k3lrzxw7.fsf@hexa.v.cablecom.net>
On Tue, Jun 18, 2013 at 09:22:16AM +0200, Thomas Rast wrote:
> [I don't seem to have received a copy of the original mail, so I can
> only guess...]

Yes, the original doesn't seem to have made it to the list. Sorry, I don't have a copy (I am in the habit of deleting direct mails that are cc'd to the list, as I keep a separate list archive).

Mark, did you happen to send an HTML mail? The list will silently reject such mail.

Show 9 quoted lines
> > Note that the number of lines in your --word-diff=color hunk and the
> > actual diff will not necessarily be the same.  What happens if I split a
> > hunk with your patch?
> 
> If it's actually what you hint at, there's another problem: the word
> diff might not even have the same number of hunks.  For example, a
> long-standing bug (or feature, depending on POV) of word-diff is that it
> does not take opportunities to completely drop hunks that did not make
> any word-level changes.
Yeah, I didn't even think of that.

In general, I think one can assume 1-to-1 correspondence between whole regular diffs and whole word-diffs, but not below that (i.e., neither a correspondence between hunks nor between lines).

With something like contrib/diff-highlight, you get some decoration, and can assume a 1-to-1 line correspondence.

However, I think that when reviewing text (especially re-wrapped paragraphs) that word-diff can be much easier to read, _because_ it throws away the line correspondence. To be correct, though, I think we would have to simply show the whole word-diff for a file and say "is this OK?". Which sort of defeats the purpose of "add -p" as a hunk selector (you could just as easily run "git diff --color-words foo" and "git add foo"). But it does save keystrokes if your workflow is to simply "add -p" everything to double-check it before adding.

So I dunno. I could see myself using it, but I certainly wouldn't want a config variable that turns it on all the time (which is what the original patch did).

-Peff
Previous: Thomas RastNext: Mark Abraham
Message 3 of 5 in “Re: [PATCH] git-add--interactive.perl: Permit word-based diff”
  1. Jeff KingJun 18, 2013
  2. Thomas RastJun 18, 2013
  3. Jeff KingJun 18, 2013
  4. Mark AbrahamJun 18, 2013
  5. Jeff KingJun 18, 2013

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.