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

Re: git log --numstat disagrees with git apply --numstat

From
Jeff King <peff@peff.net>
Date
Dec 12, 2008, 01:52 UTC
Message-ID
<20081212015254.GA23128@sigill.intra.peff.net>
In-Reply-To
<20081211235337.GK32487@spearce.org>
On Thu, Dec 11, 2008 at 03:53:37PM -0800, Shawn O. Pearce wrote:
> I've found a case where git apply --numstat and git log --numstat
> produce different results for the same commit.

"git apply" doesn't actually do the diff; it just calculates based on what it sees in the patch. So the real issue is "git log -p" and "git log --numstat" produce different patches. And you can see it by instrumenting like this:

diff --git a/diff.c b/diff.c
index af822c1..fce93db 100644
--- a/diff.c
+++ b/diff.c
@@ -726,6 +726,8 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
 	struct diffstat_t *diffstat = priv;
 	struct diffstat_file *x = diffstat->files[diffstat->nr - 1];
 
+	fwrite(line, 1, len, stderr);
+
 	if (line[0] == '+')
 		x->added++;
 	else if (line[0] == '-')

and then comparing what diffstat_consume gets versus the patch,
something like:

    what="9bda5ece org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java"
    git log -p -1 --pretty=format: $what | grep '^[-+@]' >a
    git log --numstat -1 --pretty=format: $what 2>b >/dev/null
    diff -u a b

It looks like it is just a place where two different valid diffs can be
constructed:

    +-
    +-              for (final RevCommit p : c.parents) {
    +-                      if ((p.flags & SEEN) != 0)
     +              for (;;) {
     +                      final RevCommit c = pending.pop();
     +                      if (c == null)
    @@ -67,19 +68,20 @@
     +                              p.flags |= SEEN;
     +                              pending.add(p);
     +                      }
    --              for (final RevCommit p : c.parents) {
    --                      if ((p.flags & SEEN) != 0)
    ++

which is probably just due to different xdi settings being used between
the two codepaths. I haven't looked closely to see which different
options we are feeding to xdiff.

-Peff
Previous: Shawn O. PearceNext: Jeff King
Message 2 of 6 in “git log --numstat disagrees with git apply --numstat”
  1. Shawn O. PearceDec 11, 2008
  2. Jeff KingDec 12, 2008
  3. Jeff KingDec 12, 2008
  4. Jeff KingDec 12, 2008
  5. Junio C HamanoDec 15, 2008
  6. Jeff KingDec 15, 2008

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.