Re: Git has two ways to count modified lines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 02.04.22 um 18:49 schrieb Laurent Lyaudet:
> Le mer. 16 mars 2022 à 19:08, Laurent Lyaudet
> <laurent.lyaudet@xxxxxxxxx> a écrit :
>>
> I thought my email was sent to the right mailbox, at least it is what
> says this website :
> https://git-scm.com/community

Sure it was.

>> General questions or comments for the Git community can be sent to
>> the mailing list by using the email address git@xxxxxxxxxxxxxxx.
> Moreover this website is cited in the README here :
> https://github.com/git/git/blob/master/README.md
>> Many Git online resources are accessible from https://git-scm.com/
>> including full documentation and Git related tools.
> Is there any problem with my questions explaining I got no answer,
> please ?
Not really, don't worry.

> I have found a partial explanation for the count differences :
>>  2 files changed, 88 insertions(+), 48 deletions(-)
>>  rewrite src/apps/logs/components/PresenceList.js (61%)
> When committing, a file considered as "rewrite" is counted like m
> lines deleted and n lines added if it had m lines before and n lines
> after.
> Even if the diff is much smaller.

Git stores the file contents before and after your change.  It doesn't
store any diff, but calculates them as needed, e.g. for the commit
confirmation message, or when you run git diff.  So in that sense there
is no "the diff".  The difference between two stored states can be
represented in many ways.

> Hence I answered my question :
>> How can I check how it computed these numbers in the first place ?

The option --break-rewrites controls rewrite detection.  Check out its
description in the documentation of git diff to see how to use it.

> But the two other questions remains :
>> How comes git has two ways to count modified lines ?
> i.e. What is (was) the purpose of this rewrite counting (when coded) ?

Rewrite detection is meant to improve the diff of a file whose content
was replaced with something very different.  Instead of lots of hunks
containing lines that add and remove unrelated stuff, separated by empty
lines etc. that the diff algorithm matches between the sides even though
they are also unrelated, a rewrite diff removes all the old lines en
bloc and then adds all the new ones, which is easier to read in that
case.

>> How can I make git output again the same numbers than just after commit ?

git show --stat --break-rewrites

But I have a question to the list as well: Why is break_opt (the
diff_options member for --break-rewrites) enabled for git commit by
default?  I ask because the last commit that mentioned it, dc6b1d92ca
(wt-status: use settings from git_diff_ui_config, 2018-05-04), claimed
it would turn it off, if I read it correctly.

René




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux