{"thread":{"id":"57789","subject":"help for git format-patch lost diffstat","startedAt":"2022-04-24T06:41:23Z","lastAt":"2022-04-25T17:26:16Z","messageCount":6,"participants":["FanJun Kong","Eric Sunshine","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"454354","messageId":"20220424064114.nwzldz5s2bnkrlu5@kong-HP","threadId":"57789","inReplyTo":null,"subject":"help for git format-patch lost diffstat","fromName":"FanJun Kong","fromEmail":"bh1scw@gmail.com","sentAt":"2022-04-24T06:41:14Z","receivedAt":"2022-04-24T06:41:23Z","isPatch":false,"sender":{"key":"bh1scw@gmail.com","avatar":null},"body":"Hi, \n\nHere are steps of what I am doing:\n\nFirst, I created two commits to a demo project.\n\nwhen I use command:\ngit format-patch --cover-letter -1\n\ncat 0000-cover-letter.patch\n\nFrom 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001\nFrom: FanJun Kong <bh1scw@gmail.com>\nDate: Sun, 24 Apr 2022 14:31:45 +0800\nSubject: [PATCH 0/1] *** SUBJECT HERE ***\n\n*** BLURB HERE ***\n\nFanJun Kong (1):\n  Second commit.\n\n   1.c | 4 ++++\n   1 file changed, 4 insertions(+)\n\n--\n2.32.0 (Apple Git-132)\n\nok, you can see the cover letter has diffstat, just above \"--\".\n\nThen I change command to:\n\ngit format-patch --cover-letter -2\n\ncat 0000-cover-letter.patch\n\nFrom 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001\nFrom: FanJun Kong <bh1scw@gmail.com>\nDate: Sun, 24 Apr 2022 14:34:48 +0800\nSubject: [PATCH 0/2] *** SUBJECT HERE ***\n\n*** BLURB HERE ***\n\nFanJun Kong (2):\n  First commit.\n  Second commit.\n\n--\n2.32.0 (Apple Git-132)\n\nComparing with last command, I just want to get 2 patches,\nbut this time the diffstat is missing.\n\nI am not sure if this is a bug or I miss some options.\n\nI googled this issue, but not got too much.\n\nThanks for your time.\nFanjun Kong\n"},{"id":"454356","messageId":"20220424064730.fdhrgkkkegxbnn3l@kong-HP","threadId":"57789","inReplyTo":"20220424064114.nwzldz5s2bnkrlu5@kong-HP","subject":"Re: help for git format-patch lost diffstat","fromName":"FanJun Kong","fromEmail":"bh1scw@gmail.com","sentAt":"2022-04-24T06:47:30Z","receivedAt":"2022-04-24T06:47:39Z","isPatch":false,"sender":{"key":"bh1scw@gmail.com","avatar":null},"body":"BTW:\n\nI tried 4 different version of git:\n\ngit version 2.34.1  fedora\ngit version 2.32.0 (Apple Git-132)\ngit version 2.36.0  ubuntu\ngit version 2.30.2  debian\n\nThe result of test is all the same.\n\nOn 24 Apr 22 ◦ 14:41, FanJun Kong wrote:\n> Hi, \n> \n> Here are steps of what I am doing:\n> \n> First, I created two commits to a demo project.\n> \n> when I use command:\n> git format-patch --cover-letter -1\n> \n> cat 0000-cover-letter.patch\n> \n> From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001\n> From: FanJun Kong <bh1scw@gmail.com>\n> Date: Sun, 24 Apr 2022 14:31:45 +0800\n> Subject: [PATCH 0/1] *** SUBJECT HERE ***\n> \n> *** BLURB HERE ***\n> \n> FanJun Kong (1):\n>   Second commit.\n> \n>    1.c | 4 ++++\n>    1 file changed, 4 insertions(+)\n> \n> --\n> 2.32.0 (Apple Git-132)\n> \n> ok, you can see the cover letter has diffstat, just above \"--\".\n> \n> Then I change command to:\n> \n> git format-patch --cover-letter -2\n> \n> cat 0000-cover-letter.patch\n> \n> From 2e62ef46d5627319c4cb11be81079e3364fca40c Mon Sep 17 00:00:00 2001\n> From: FanJun Kong <bh1scw@gmail.com>\n> Date: Sun, 24 Apr 2022 14:34:48 +0800\n> Subject: [PATCH 0/2] *** SUBJECT HERE ***\n> \n> *** BLURB HERE ***\n> \n> FanJun Kong (2):\n>   First commit.\n>   Second commit.\n> \n> --\n> 2.32.0 (Apple Git-132)\n> \n> Comparing with last command, I just want to get 2 patches,\n> but this time the diffstat is missing.\n> \n> I am not sure if this is a bug or I miss some options.\n> \n> I googled this issue, but not got too much.\n> \n> Thanks for your time.\n> Fanjun Kong\n"},{"id":"454369","messageId":"CAPig+cQsGZ5Uw13vr5r_SZ9APZwovtxSW5N4QGpieHRx1_6zRg@mail.gmail.com","threadId":"57789","inReplyTo":"20220424064114.nwzldz5s2bnkrlu5@kong-HP","subject":"Re: help for git format-patch lost diffstat","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2022-04-25T08:09:00Z","receivedAt":"2022-04-25T08:09:16Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 24, 2022 at 9:00 AM FanJun Kong <bh1scw@gmail.com> wrote:\n> First, I created two commits to a demo project.\n>\n> when I use command:\n> git format-patch --cover-letter -1\n> [...]\n> FanJun Kong (1):\n>   First commit.\n>    1.c | 4 ++++\n>    1 file changed, 4 insertions(+)\n>\n> ok, you can see the cover letter has diffstat, just above \"--\".\n>\n> git format-patch --cover-letter -2\n> [...]\n> FanJun Kong (2):\n>   First commit.\n>   Second commit.\n>\n> Comparing with last command, I just want to get 2 patches,\n> but this time the diffstat is missing.\n>\n> I am not sure if this is a bug or I miss some options.\n\nThis is expected behavior according to this code in\nmake_cover_letter() in builtin/log.c:\n\n    /* We can only do diffstat with a unique reference point */\n    if (origin)\n        show_diffstat(rev, origin, head);\n\nThe problem is that when you format both patches of a two-commit\nrepository, `origin` is NULL because there is no commit preceding the\ninitial commit; the initial commit is the root of the history. Thus,\nthere is nothing prior to the first patch against which to create a\ndiffstat.\n\nI have not investigated, but it may be possible to teach\nshow_diffstat() how to generate a diffstat against the \"emptiness\"\npreceding the initial commit, but nobody has done so yet. Perhaps this\nwould be a good project for someone interested in contributing to the\nproject (or perhaps not -- as mentioned, I haven't investigated how\nhard this would be).\n"},{"id":"454370","messageId":"xmqqk0bdy3zn.fsf@gitster.g","threadId":"57789","inReplyTo":"20220424064114.nwzldz5s2bnkrlu5@kong-HP","subject":"Re: help for git format-patch lost diffstat","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-04-25T08:14:04Z","receivedAt":"2022-04-25T08:15:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"FanJun Kong <bh1scw@gmail.com> writes:\n\n> First, I created two commits to a demo project.\n>\n> when I use command:\n> git format-patch --cover-letter -1\n> ...\n> Then I change command to:\n>\n> git format-patch --cover-letter -2\n\n\nHere is _one_ way I just came up with, that gives you a result\nidentical to what you reported, and it is a perfectly understandable\nand expected outcome in _this_ scenario.\n\nPreparation goes like this.  Go to any single-parent commit and\nrevert it.\n\n  $ git checkout --detach seen^2\n  $ GIT_EDITOR=: git revert HEAD\n\nNow we have two commits.  Try formatting the topmost one:\n\n  $ git format-patch --stdout --cover-letter -1 |\n    sed -e \"1,/^$/d\" -e \"/^-- /q\"\n  *** BLURB HERE ***\n\n  Junio C Hamano (1):\n    Revert \"ci: call `finalize_test_case_output` a little later\"\n\n   t/test-lib.sh | 11 +++++------\n   1 file changed, 5 insertions(+), 6 deletions(-)\n\n  -- \n\nNow try formatting the twomost two:\n\n  $ git format-patch --stdout --cover-letter -2 |\n    sed -e \"1,/^$/d\" -e \"/^-- /q\"\n  *** BLURB HERE ***\n\n  Johannes Schindelin (1):\n    ci: call `finalize_test_case_output` a little later\n\n  Junio C Hamano (1):\n    Revert \"ci: call `finalize_test_case_output` a little later\"\n\n\n  -- \n\nThe topmost commit had some effect on a single file, but when the\neffect of two topmost commits are taken together, they cancel out.\n\nI am not saying these two commits are what you have, but the outcome\nobviously depends on what these two commits are, and if you do not\nshow them, nobody would be able to help you.\n\n"},{"id":"454375","messageId":"20220425094550.e6vw6xwtk4dcstyd@kong-HP","threadId":"57789","inReplyTo":"CAPig+cQsGZ5Uw13vr5r_SZ9APZwovtxSW5N4QGpieHRx1_6zRg@mail.gmail.com","subject":"Re: help for git format-patch lost diffstat","fromName":"FanJun Kong","fromEmail":"bh1scw@gmail.com","sentAt":"2022-04-25T09:45:50Z","receivedAt":"2022-04-25T09:45:59Z","isPatch":false,"sender":{"key":"bh1scw@gmail.com","avatar":null},"body":"On 25 Apr 22 ◦ 04:09, Eric Sunshine wrote:\n> On Sun, Apr 24, 2022 at 9:00 AM FanJun Kong <bh1scw@gmail.com> wrote:\n> > First, I created two commits to a demo project.\n> >\n> > when I use command:\n> > git format-patch --cover-letter -1\n> > [...]\n> > FanJun Kong (1):\n> >   First commit.\n> >    1.c | 4 ++++\n> >    1 file changed, 4 insertions(+)\n> >\n> > ok, you can see the cover letter has diffstat, just above \"--\".\n> >\n> > git format-patch --cover-letter -2\n> > [...]\n> > FanJun Kong (2):\n> >   First commit.\n> >   Second commit.\n> >\n> > Comparing with last command, I just want to get 2 patches,\n> > but this time the diffstat is missing.\n> >\n> > I am not sure if this is a bug or I miss some options.\n> \n> This is expected behavior according to this code in\n> make_cover_letter() in builtin/log.c:\n> \n>     /* We can only do diffstat with a unique reference point */\n>     if (origin)\n>         show_diffstat(rev, origin, head);\n> \n> The problem is that when you format both patches of a two-commit\n> repository, `origin` is NULL because there is no commit preceding the\n> initial commit; the initial commit is the root of the history. Thus,\n> there is nothing prior to the first patch against which to create a\n> diffstat.\n> \nVery clear explanation, yeah~\n> I have not investigated, but it may be possible to teach\n> show_diffstat() how to generate a diffstat against the \"emptiness\"\n> preceding the initial commit, but nobody has done so yet. Perhaps this\n> would be a good project for someone interested in contributing to the\n> project (or perhaps not -- as mentioned, I haven't investigated how\n> hard this would be).\n\nFrom my point of view, it is a bug, but it doesn't affect too much.\nI agree with your suggestion, this is a nice chance to learn how\nto submit patches to upstream.\n"},{"id":"454388","messageId":"xmqqo80pvzwd.fsf@gitster.g","threadId":"57789","inReplyTo":"CAPig+cQsGZ5Uw13vr5r_SZ9APZwovtxSW5N4QGpieHRx1_6zRg@mail.gmail.com","subject":"Re: help for git format-patch lost diffstat","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-04-25T17:25:22Z","receivedAt":"2022-04-25T17:26:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> The problem is that when you format both patches of a two-commit\n> repository, `origin` is NULL because there is no commit preceding the\n> initial commit; the initial commit is the root of the history. Thus,\n> there is nothing prior to the first patch against which to create a\n> diffstat.\n>\n> I have not investigated, but it may be possible to teach\n> show_diffstat() how to generate a diffstat against the \"emptiness\"\n> preceding the initial commit, but nobody has done so yet. Perhaps this\n> would be a good project for someone interested in contributing to the\n> project (or perhaps not -- as mentioned, I haven't investigated how\n> hard this would be).\n\nYeah, it is like the \"--root\" option to allow us stop treating a\nroot commit as any special and instead consider it is adding\neverything it has relative to the empty tree, which sounds like a\nquite sensible thing to do.\n\nThanks.\n"}]}