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

Re: Lines missing from git diff-tree -p -c output?

From
Junio C Hamano <gitster@pobox.com>
Date
May 15, 2013, 17:17 UTC
Message-ID
<7vhai4cgco.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130515143508.GO25742@login.drsnuggles.stderr.nl>
Matthijs Kooijman <matthijs@stdin.nl> writes:
Show 20 quoted lines
> $ git diff-tree -p -c HEAD
> d945a51b6ca22e6e8e550c53980d026f11b05158
> diff --combined file
> index 3404f54,0eab113..e8c8c18
> --- a/file
> +++ b/file
> @@@ -1,7 -1,5 +1,6 @@@
>  +LEFT
>   BASE2
>   BASE3
>   BASE4
> - BASE5
> + BASE5MODIFIED
>   BASE6
>
> Here, the header claims that the first head has 7 lines, but there really are
> only 6 (5 lines of context and one delete line). The numbers for the others
> heads are incorrect. In the original diff, the difference was bigger
> (first head was stated to have 28 lines, while the output was similar to
> the above).

The count and the output does look inconsistent. The hunk header claims that it is showing:

 - range 1,7 for the first parent but it should be 1,5 (2, 3, 4, 5 and 6) 
   to match the output.
 - range 1,5 for the second parent (left, 2, 3, 4, 5mod, and 6 -- correct)
 - range 1,6 for the result (left, 2, 3, 4, 5mod and 6 -- correct)

If we resurrect the loss of "BASE1" from the output, then the output should have shown:

  +LEFT
 - BASE1
   BASE2
   BASE3
   BASE4
 - BASE5
 + BASE5MODIFIED
   BASE6

which means the numbers shown for the first parent (1, 2, 3, 4, 5 and 6) should be 1,6.

> Note that to trigger this behaviour, the number of context lines between the
> BASE1 and BASE5 must be _exactly_ 3, more or less prevents this bug from
> occuring.

I think the coalescing of two adjacent hunks into one is painting leading lines "interesting to show context but not worth showing deletion before it" incorrectly.

Does this patch fix the issue?
 combine-diff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/combine-diff.c b/combine-diff.c
index 77d7872..7359b84 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -533,7 +533,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
 		k = find_next(sline, mark, j, cnt, 0);
 		j = adjust_hunk_tail(sline, all_mask, i, j);
 
-		if (k < j + context) {
+		if (k <= j + context) {
 			/* k is interesting and [j,k) are not, but
 			 * paint them interesting because the gap is small.
 			 */
Previous: Matthijs KooijmanNext: Matthijs Kooijman
Message 3 of 8 in “Lines missing from git diff-tree -p -c output?”
  1. Matthijs KooijmanMay 15, 2013
  2. Matthijs KooijmanMay 15, 2013
  3. Junio C HamanoMay 15, 2013
  4. Matthijs KooijmanMay 15, 2013
  5. combine-diff.c: Fix output when changes are exactly 3 lines apartMatthijs Kooijman, May 15, 2013
  6. Junio C HamanoMay 15, 2013
  7. Matthijs KooijmanMay 15, 2013
  8. Junio C HamanoMay 15, 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.