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

Re: Bug: git log --numstat counts wrong

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 22, 2011, 17:51 UTC
Message-ID
<7vobycxy71.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vobyd1vmo.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> Alexander Pepper <pepper@inf.fu-berlin.de> writes:
>
>> Am 21.09.2011 um 14:24 schrieb Junio C Hamano:
>>>> $ git log --numstat 48a07e7e533f507228e8d1c99d4d48e175e14260
>>>> [...]
>>>> 11      10      src/java/voldemort/server/storage/StorageService.java
>>> 
>>> Didn't we update it this already? I seem to get 10/9 here not 11/10.
>>
>> Current 'maint' (cd2b8ae9), 'master' (4b5eac7f)...
>
> That's a tad old master you seem to have.
>
> Strangely, bisection points at 27af01d5523, which was supposed to be only
> about performance and never about correctness. There is something fishy
> going on....

In any case, I think the real issue is that depending on how much context you ask, the resulting diff is different (and both are valid diffs). If you ask "log -p" (or "diff" or "show") to produce a patch, then we use the default 3-line context. And then you feed that to an external diffstat to count the number of deleted and added lines to get one set of numbers.

The --numstat (and --diffstat) code seems to be running the internal diff machinery with 0-line context and counting the resulting diff internally.

And of course the results between the above two would be different because diff can match lines differently when given different number of context lines to include in the result.

So perhaps a good sanity-check for you to try (note: not checking your sanity, but checking the sanity of the above analysis) would be to do:

  $ git show 48a07e7e53 -- $that_path | diffstat
  $ git show -U0 48a07e7e53 -- $that_path | diffstat
  $ git show --numstat 48a07e7e53 -- $that_path
  $ git show --stat 48a07e7e53 -- $that_path

and see how they compare (make sure to use the same version of git for these experiments). The first one uses the default 3-lines context, the second one forces 0-line context, and the last two uses 0-line context hardwired in the code.

Applying the following patch should make the last two use the default context or -U$num given from the command line to be consistent with the codepath where we generate textual patches.

 diff.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 9038f19..302ef33 100644
--- a/diff.c
+++ b/diff.c
@@ -2251,6 +2251,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
 		memset(&xpp, 0, sizeof(xpp));
 		memset(&xecfg, 0, sizeof(xecfg));
 		xpp.flags = o->xdl_opts;
+		xecfg.ctxlen = o->context;
+		xecfg.interhunkctxlen = o->interhunkcontext;
 		xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
 			      &xpp, &xecfg);
 	}
Previous: René ScharfeNext: Tay Ray Chuan
Message 12 of 16 in “Bug: git log --numstat counts wrong”
  1. Alexander PepperSep 21, 2011
  2. Junio C HamanoSep 21, 2011
  3. Alexander PepperSep 21, 2011
  4. Alexander PepperSep 21, 2011
  5. Junio C HamanoSep 21, 2011
  6. Alexander PepperSep 22, 2011
  7. Junio C HamanoSep 22, 2011
  8. René ScharfeSep 22, 2011
  9. Tay Ray ChuanSep 23, 2011
  10. Revert removal of multi-match discard heuristic in 27af01Tay Ray Chuan, Sep 25, 2011
  11. René ScharfeSep 25, 2011
  12. Junio C HamanoSep 22, 2011
  13. Tay Ray ChuanSep 23, 2011
  14. Tay Ray ChuanSep 23, 2011
  15. Junio C HamanoSep 23, 2011
  16. Alexander PepperSep 23, 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.