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

Re: [PATCH] Add color to git-add--interactive diffs (Total different idea to solve the problem)

From
PBPeter Baumann <waste.manager@gmx.de>
Date
Oct 23, 2007, 05:34 UTC
Message-ID
<20071023053401.GB9330@xp.machine.xx>
In-Reply-To
<Pine.LNX.4.64.0710230054130.25221@racer.site>
On Tue, Oct 23, 2007 at 12:55:44AM +0100, Johannes Schindelin wrote:
Show 18 quoted lines
> Hi,
> 
> On Mon, 22 Oct 2007, Peter Baumann wrote:
> 
> > Wouldn't it make more sense to implement the diff coloring inside git 
> > apply so that you could use something like
> > 
> >         diff file1 file2|git apply --color
> > 
> > to make the generated diff with colors [1]? It already implements the
> > same semantic for generating a diffstat, using
> > 
> >         diff file1 file2|git apply --stat
> 
> No.  In both cases, "git diff" realises that the output is no terminal, 
> and switches off color generation.  (Just try with diff.color=true instead 
> of =auto.)
> 

I didn't mean git-diff here, instead I meant diff, so no coloring involved on the diff side. The git-apply would be enhanced to do the coloring on every diff it gets on its STDIN.

In the git-add -i case, the perl script whould do something along these lines:

	foreach my $file (@files) {
		# read in the diff of a file *WITHOUT* using color
		@diff = `git-diff-files $file`;
		# ... store it away for later use in hunk selection ...
		# print out a nice colored diff for the user
		`echo @diff | git apply --color`
	}

Instead of handcoding the colorization in the git-add--interactive perl script, just enhance git-apply to do the colorization *after the fact* for you on _any_ patch you throw at it in its STDIN.

-Peter
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 9 in “Add color to git-add--interactive diffs (Take 2: now without spurious line break!)”
  1. Add color to git-add--interactive diffs (Take 2: now without spurious line break!)Tom Tobin, Oct 14, 2007
  2. Wincent ColaiutaOct 14, 2007
  3. Johannes SchindelinOct 14, 2007
  4. Andreas EricssonOct 14, 2007
  5. Wincent ColaiutaOct 14, 2007
  6. Peter BaumannOct 22, 2007
  7. Johannes SchindelinOct 22, 2007
  8. Peter BaumannOct 23, 2007
  9. Johannes SchindelinOct 23, 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.