git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* help for git format-patch lost diffstat
@ 2022-04-24  6:41 FanJun Kong
  2022-04-24  6:47 ` FanJun Kong
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: FanJun Kong @ 2022-04-24  6:41 UTC (permalink / raw)
  To: git; +Cc: FanJun Kong

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: help for git format-patch lost diffstat
  2022-04-24  6:41 help for git format-patch lost diffstat FanJun Kong
@ 2022-04-24  6:47 ` FanJun Kong
  2022-04-25  8:09 ` Eric Sunshine
  2022-04-25  8:14 ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: FanJun Kong @ 2022-04-24  6:47 UTC (permalink / raw)
  To: git; +Cc: FanJun Kong

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:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: help for git format-patch lost diffstat
  2022-04-24  6:41 help for git format-patch lost diffstat FanJun Kong
  2022-04-24  6:47 ` FanJun Kong
@ 2022-04-25  8:09 ` Eric Sunshine
  2022-04-25  9:45   ` FanJun Kong
  2022-04-25 17:25   ` Junio C Hamano
  2022-04-25  8:14 ` Junio C Hamano
  2 siblings, 2 replies; 6+ messages in thread
From: Eric Sunshine @ 2022-04-25  8:09 UTC (permalink / raw)
  To: FanJun Kong; +Cc: Git List

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.

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).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: help for git format-patch lost diffstat
  2022-04-24  6:41 help for git format-patch lost diffstat FanJun Kong
  2022-04-24  6:47 ` FanJun Kong
  2022-04-25  8:09 ` Eric Sunshine
@ 2022-04-25  8:14 ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2022-04-25  8:14 UTC (permalink / raw)
  To: FanJun Kong; +Cc: git

FanJun Kong <bh1scw@gmail.com> writes:

> 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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: help for git format-patch lost diffstat
  2022-04-25  8:09 ` Eric Sunshine
@ 2022-04-25  9:45   ` FanJun Kong
  2022-04-25 17:25   ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: FanJun Kong @ 2022-04-25  9:45 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: git

On 25 Apr 22 ◦ 04:09, Eric Sunshine wrote:
> 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~
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: help for git format-patch lost diffstat
  2022-04-25  8:09 ` Eric Sunshine
  2022-04-25  9:45   ` FanJun Kong
@ 2022-04-25 17:25   ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2022-04-25 17:25 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: FanJun Kong, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-25 17:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24  6:41 help for git format-patch lost diffstat FanJun Kong
2022-04-24  6:47 ` FanJun Kong
2022-04-25  8:09 ` Eric Sunshine
2022-04-25  9:45   ` FanJun Kong
2022-04-25 17:25   ` Junio C Hamano
2022-04-25  8:14 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).