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

diff -U0 occasionally misses a chance to make empty lines context [was: Re: [BUG] difference of info from diff and blame]

From
Thomas Rast <trast@student.ethz.ch>
Date
Jan 12, 2011, 10:20 UTC
Message-ID
<201101121120.26724.trast@student.ethz.ch>
In-Reply-To
<4D2D5E08.9040804@gmail.com>
Ok, so to summarize for late joiners and the new Ccs:
git diff -U0 occasionally gives suboptimal results in hunks like
Semyon Kirnosenko wrote:
Show 21 quoted lines
> 11.01.2011 16:40, Thomas Rast пишет:
> > @@ -108,11 +123,8 @@ jQuery.event = {
> > -			var handler = element["on" + type ], val,
> > -				fn = jQuery.isFunction( element[ type ] );
> > -
> > -			if ( handler ) {
> > -				// Pass along a fake event
> > -				data.unshift( this.fix({ type: type, target: element }) );
> > -	
> > -				// Trigger the event
> > -				if ( (val = handler.apply( element, data )) !== false )
> > -					this.triggered = true;
> > -			}
> > +			var val, ret, fn = jQuery.isFunction( element[ type ] );
> > +			
> > +			// Pass along a fake event
> > +			data.unshift( this.fix({ type: type, target: element }) );
> > +
> > +			// Trigger the event
> > +			if ( (val = this.handle.apply( element, data )) !== false )
> > +				this.triggered = true;

where two of the whitespace lines are the same and thus could have been made context. Oddly enough, this specific line *is* made context for the default -U3. This occasionally causes git-blame (which uses the equivalent of 'git diff -U0' internally) to misattribute blank lines. This does *not* affect correctness of the diff, it is just suboptimal.

My own guess at the problem is
> > I wouldn't be too surprised if it had heuristics that put lines
> > consisting only of whitespace at a lower importance than "actual"
> > lines.
i.e. that it's whitespace-related, and indeed Semyon says
> All cases I have seen were about whitespace lines.

I don't really care, since I haven't seen a single use-case where the attribution of empty lines matters. Still, let's at least bring it to the attention of the people who have worked on libxdiff.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Semyon Kirnosenko
Message 4 of 4 in “[BUG] difference of info from diff and blame”
  1. Semyon KirnosenkoJan 11, 2011
  2. Thomas RastJan 11, 2011
  3. Semyon KirnosenkoJan 12, 2011
  4. diff -U0 occasionally misses a chance to make empty lines context [was: Re: [BUG] difference of info from diff and blame]Thomas Rast, Jan 12, 2011

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.