Re: [PATCH v2] diff: Fix modified lines stats with --stat and --numstat
- From
Thomas Guyot <tguyot@gmail.com>
- Date
- Sep 20, 2020, 16:38 UTC
- Message-ID
- <a126bcf6-13f7-48f0-95d9-d934d042d7fd@gmail.com>
- In-Reply-To
- <20200920153915.GB2726066@nand.local>
On 2020-09-20 11:39, Taylor Blau wrote:
Show 33 quoted lines
> On Sun, Sep 20, 2020 at 09:09:46AM -0400, Thomas Guyot-Sionnest wrote: >> In builtin_diffstat(), when both files are coming from "stdin" (which >> could be better described as the file's content being written directly >> into the file object), oideq() compares two null hashes and ignores the >> actual differences for the statistics. >> >> This patch checks if is_stdin flag is set on both sides and compare >> contents directly. >> >> Signed-off-by: Thomas Guyot-Sionnest <tguyot@gmail.com> >> --- >> Range-diff: >> 1: 479c2835fc ! 1: 1f25713d44 diff: Fix modified lines stats with --stat and --numstat >> @@ -20,8 +20,12 @@ >> } >> >> - same_contents = oideq(&one->oid, &two->oid); >> ++ /* What is_stdin really means is that the file's content is only >> ++ * in the filespec's buffer and its oid is zero. We can't compare >> ++ * oid's if both are null and we can just diff the buffers */ >> + if (one->is_stdin && two->is_stdin) >> -+ same_contents = !strcmp(one->data, two->data); >> ++ same_contents = (one->size == two->size ? >> ++ !memcmp(one->data, two->data, one->size) : 0); >> + else >> + same_contents = oideq(&one->oid, &two->oid); > > After reading your explanation in [1], this version makes more sense to > me. > > Thanks. > > [1]: https://lore.kernel.org/git/f4c4cb48-f4b5-3d4d-066d-b94e961dcbb5@gmail.com/
There's a little bit missing... Just before the new code example:, previous to last paragraph:
> it's assumed [we can just call oidcmp()] and I won't make complex
-- Thomas