threads / discuss / 57789

help for git format-patch lost diffstat

Subject: help for git format-patch lost diffstat

## tl;dr

6 messages between Apr 24, 2022 and Apr 25, 2022.

replies: 5people: 3as markdown or json

FanJun Kong· Apr 24, 2022, 06:41 UTC · lore
Hi, 
Here are steps of what I am doing:
First, I created two commits to a demo project.

when I use command: git format-patch --cover-letter -1

cat 0000-cover-letter.patch
From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001
From: FanJun Kong <bh1scw@gmail.com>
Date: Sun, 24 Apr 2022 14:31:45 +0800
Subject: [PATCH 0/1] *** SUBJECT HERE ***
*** BLURB HERE ***
FanJun Kong (1):
  Second commit.
   1.c | 4 ++++
   1 file changed, 4 insertions(+)

-- 2.32.0 (Apple Git-132)

ok, you can see the cover letter has diffstat, just above "--".
Then I change command to:
git format-patch --cover-letter -2
cat 0000-cover-letter.patch
From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001
From: FanJun Kong <bh1scw@gmail.com>
Date: Sun, 24 Apr 2022 14:34:48 +0800
Subject: [PATCH 0/2] *** SUBJECT HERE ***
*** BLURB HERE ***
FanJun Kong (2):
  First commit.
  Second commit.

-- 2.32.0 (Apple Git-132)

Comparing with last command, I just want to get 2 patches, but this time the diffstat is missing.

I am not sure if this is a bug or I miss some options.
I googled this issue, but not got too much.

Thanks for your time. Fanjun Kong

FanJun Kong· Apr 24, 2022, 06:47 UTC · re: FanJun Kong · lore

Re: help for git format-patch lost diffstat

BTW:
I tried 4 different version of git:

git version 2.34.1 fedora git version 2.32.0 (Apple Git-132) git version 2.36.0 ubuntu git version 2.30.2 debian

The result of test is all the same.
On 24 Apr 22 ◦ 14:41, FanJun Kong wrote:
Show 58 quoted lines
> Hi, 
> 
> Here are steps of what I am doing:
> 
> First, I created two commits to a demo project.
> 
> when I use command:
> git format-patch --cover-letter -1
> 
> cat 0000-cover-letter.patch
> 
> From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001
> From: FanJun Kong <bh1scw@gmail.com>
> Date: Sun, 24 Apr 2022 14:31:45 +0800
> Subject: [PATCH 0/1] *** SUBJECT HERE ***
> 
> *** BLURB HERE ***
> 
> FanJun Kong (1):
>   Second commit.
> 
>    1.c | 4 ++++
>    1 file changed, 4 insertions(+)
> 
> --
> 2.32.0 (Apple Git-132)
> 
> ok, you can see the cover letter has diffstat, just above "--".
> 
> Then I change command to:
> 
> git format-patch --cover-letter -2
> 
> cat 0000-cover-letter.patch
> 
> From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001
> From: FanJun Kong <bh1scw@gmail.com>
> Date: Sun, 24 Apr 2022 14:34:48 +0800
> Subject: [PATCH 0/2] *** SUBJECT HERE ***
> 
> *** BLURB HERE ***
> 
> FanJun Kong (2):
>   First commit.
>   Second commit.
> 
> --
> 2.32.0 (Apple Git-132)
> 
> Comparing with last command, I just want to get 2 patches,
> but this time the diffstat is missing.
> 
> I am not sure if this is a bug or I miss some options.
> 
> I googled this issue, but not got too much.
> 
> Thanks for your time.
> Fanjun Kong
Eric Sunshine· Apr 25, 2022, 08:09 UTC · re: FanJun Kong · lore

Re: help for git format-patch lost diffstat

On Sun, Apr 24, 2022 at 9:00 AM FanJun Kong <bh1scw@gmail.com> wrote:
Show 22 quoted lines
> First, I created two commits to a demo project.
>
> when I use command:
> git format-patch --cover-letter -1
> [...]
> FanJun Kong (1):
>   First commit.
>    1.c | 4 ++++
>    1 file changed, 4 insertions(+)
>
> ok, you can see the cover letter has diffstat, just above "--".
>
> git format-patch --cover-letter -2
> [...]
> FanJun Kong (2):
>   First commit.
>   Second commit.
>
> Comparing with last command, I just want to get 2 patches,
> but this time the diffstat is missing.
>
> I am not sure if this is a bug or I miss some options.

This is expected behavior according to this code in make_cover_letter() in builtin/log.c:

    /* We can only do diffstat with a unique reference point */
    if (origin)
        show_diffstat(rev, origin, head);

The problem is that when you format both patches of a two-commit repository, `origin` is NULL because there is no commit preceding the initial commit; the initial commit is the root of the history. Thus, there is nothing prior to the first patch against which to create a diffstat.

I have not investigated, but it may be possible to teach show_diffstat() how to generate a diffstat against the "emptiness" preceding the initial commit, but nobody has done so yet. Perhaps this would be a good project for someone interested in contributing to the project (or perhaps not -- as mentioned, I haven't investigated how hard this would be).

FanJun Kong· Apr 25, 2022, 09:45 UTC · re: Eric Sunshine · lore

Re: help for git format-patch lost diffstat

On 25 Apr 22 ◦ 04:09, Eric Sunshine wrote:
Show 37 quoted lines
> On Sun, Apr 24, 2022 at 9:00 AM FanJun Kong <bh1scw@gmail.com> wrote:
> > First, I created two commits to a demo project.
> >
> > when I use command:
> > git format-patch --cover-letter -1
> > [...]
> > FanJun Kong (1):
> >   First commit.
> >    1.c | 4 ++++
> >    1 file changed, 4 insertions(+)
> >
> > ok, you can see the cover letter has diffstat, just above "--".
> >
> > git format-patch --cover-letter -2
> > [...]
> > FanJun Kong (2):
> >   First commit.
> >   Second commit.
> >
> > Comparing with last command, I just want to get 2 patches,
> > but this time the diffstat is missing.
> >
> > I am not sure if this is a bug or I miss some options.
> 
> This is expected behavior according to this code in
> make_cover_letter() in builtin/log.c:
> 
>     /* We can only do diffstat with a unique reference point */
>     if (origin)
>         show_diffstat(rev, origin, head);
> 
> The problem is that when you format both patches of a two-commit
> repository, `origin` is NULL because there is no commit preceding the
> initial commit; the initial commit is the root of the history. Thus,
> there is nothing prior to the first patch against which to create a
> diffstat.
> 
Very clear explanation, yeah~
Show 6 quoted lines
> I have not investigated, but it may be possible to teach
> show_diffstat() how to generate a diffstat against the "emptiness"
> preceding the initial commit, but nobody has done so yet. Perhaps this
> would be a good project for someone interested in contributing to the
> project (or perhaps not -- as mentioned, I haven't investigated how
> hard this would be).

From my point of view, it is a bug, but it doesn't affect too much. I agree with your suggestion, this is a nice chance to learn how to submit patches to upstream.

Junio C Hamano· Apr 25, 2022, 17:25 UTC · re: Eric Sunshine · lore

Re: help for git format-patch lost diffstat

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 12 quoted lines
> The problem is that when you format both patches of a two-commit
> repository, `origin` is NULL because there is no commit preceding the
> initial commit; the initial commit is the root of the history. Thus,
> there is nothing prior to the first patch against which to create a
> diffstat.
>
> I have not investigated, but it may be possible to teach
> show_diffstat() how to generate a diffstat against the "emptiness"
> preceding the initial commit, but nobody has done so yet. Perhaps this
> would be a good project for someone interested in contributing to the
> project (or perhaps not -- as mentioned, I haven't investigated how
> hard this would be).

Yeah, it is like the "--root" option to allow us stop treating a root commit as any special and instead consider it is adding everything it has relative to the empty tree, which sounds like a quite sensible thing to do.

Thanks.
Junio C Hamano· Apr 25, 2022, 08:14 UTC · re: FanJun Kong · lore

Re: help for git format-patch lost diffstat

FanJun Kong <bh1scw@gmail.com> writes:
Show 8 quoted lines
> First, I created two commits to a demo project.
>
> when I use command:
> git format-patch --cover-letter -1
> ...
> Then I change command to:
>
> git format-patch --cover-letter -2

Here is _one_ way I just came up with, that gives you a result identical to what you reported, and it is a perfectly understandable and expected outcome in _this_ scenario.

Preparation goes like this. Go to any single-parent commit and revert it.

  $ git checkout --detach seen^2
  $ GIT_EDITOR=: git revert HEAD
Now we have two commits.  Try formatting the topmost one:
  $ git format-patch --stdout --cover-letter -1 |
    sed -e "1,/^$/d" -e "/^-- /q"
  *** BLURB HERE ***
  Junio C Hamano (1):
    Revert "ci: call `finalize_test_case_output` a little later"
   t/test-lib.sh | 11 +++++------
   1 file changed, 5 insertions(+), 6 deletions(-)
  -- 
Now try formatting the twomost two:
  $ git format-patch --stdout --cover-letter -2 |
    sed -e "1,/^$/d" -e "/^-- /q"
  *** BLURB HERE ***
  Johannes Schindelin (1):
    ci: call `finalize_test_case_output` a little later
  Junio C Hamano (1):
    Revert "ci: call `finalize_test_case_output` a little later"
  -- 

The topmost commit had some effect on a single file, but when the effect of two topmost commits are taken together, they cancel out.

I am not saying these two commits are what you have, but the outcome obviously depends on what these two commits are, and if you do not show them, nobody would be able to help you.

← back to recent threads