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

Re: [PATCH 3/3] Color support for "git-add -i"

From
Wincent Colaiuta <win@wincent.com>
Date
Dec 7, 2007, 12:34 UTC
Message-ID
<AEA9FB5E-1ABA-42D6-8FC5-95BAAA9B6BC8@wincent.com>
In-Reply-To
<7vejdzd1aw.fsf@gitster.siamese.dyndns.org>
El 6/12/2007, a las 21:18, Junio C Hamano escribió:
Show 25 quoted lines
> Wincent Colaiuta <win@wincent.com> writes:
>
>> What are the other options?
>>
>> - Make git-add--interactive part of builtin-add so as to be able to
>> use the core.whitespace code directly? (ideally yes and at some point
>> in the future it seems inevitable that this will happen, but it will
>> require a fair bit of work)
>>
>> - Fork a second "git diff-files" process to capture the colorized
>> version of the output? (may set off the "kludge" alarm)
>>
>> - Something else?
>
> - Realize that whitespace clean-up can be risky and change semantics
>   depending on the material you are editing.  Do not do the clean-up
>   during "add -i", but before.  IOW, add an alias that does an
>   equivalent of:
>
> 	git diff HEAD >tmp
>        git apply -R <tmp
>        git apply --whitespace=fix <tmp
>
>   then encourage users to clean-up their whitespace gotchas early (and
>   test the result!), before even attempting to run "git add -i".

In principle I agree with what you're saying but I think I didn't make myself clear; I wasn't talking about actually *cleaning-up* whitespace problems from inside "git add -i", I was talking about *display* of whitespace problems only. In other words, I don't want the situation where I think it's ok to stage a hunk only because I mistakenly think it's free of whitespace problems. In other words, if one part of Git ("git diff") says the diff is "this" and another part ("git add -i") says the diff is "that" and there's a discrepancy, then that sounds like a bug to me.

Seeing as speed is not a concern here (when displaying diffs the bottleneck is really how fast the user can read, not how fast git emits the text), correctness is important, and git-add--interactive will eventually become part of builtin-add anyway, I personally think the optimum solution is this one: run the diff tools twice, once without color and once with; the former is used for internal processing as before and the later is used for display only. This approach has the advantage that the whitespace colorization provided by "git diff-files" can evolve and become more sophisticated (per-path attributes etc) and "git add -i" will automatically benefit from it.

But I wanted to throw the question out there for input first, in any case, I have a patch implementing my proposal and I'll send it out in a minute.

Cheers, Wincent

Previous: Junio C HamanoNext: Jeff King
Message 12 of 18 in “Color support for "git-add -i"”
  1. Color support for "git-add -i"Junio C Hamano, Dec 5, 2007
  2. Johannes SixtDec 5, 2007
  3. Wincent ColaiutaDec 5, 2007
  4. Junio C HamanoDec 5, 2007
  5. 1/3 Documentation: color.* = true means "auto"Junio C Hamano, Dec 6, 2007
  6. 2/3 git config --get-colorboolJunio C Hamano, Dec 6, 2007
  7. 3/3 Color support for "git-add -i"Junio C Hamano, Dec 6, 2007
  8. 0/3 Reroll colorized "git add -i"Junio C Hamano, Dec 6, 2007
  9. Jeff KingDec 6, 2007
  10. Wincent ColaiutaDec 6, 2007
  11. Junio C HamanoDec 6, 2007
  12. Wincent ColaiutaDec 7, 2007
  13. Jeff KingDec 6, 2007
  14. Jeff KingDec 6, 2007
  15. Junio C HamanoDec 6, 2007
  16. Jeff KingDec 6, 2007
  17. Eric WongDec 6, 2007
  18. Wincent ColaiutaDec 5, 2007

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.