Re: diff --stat

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

 



On Mon, Feb 13, 2012 at 04:11:46PM -0800, Junio C Hamano wrote:

> Hrm, what is wrong with this picture?
> 
> $ git -c diff.color.old=red show --format='%s' --stat
> Merge branch 'jk/diff-highlight' into pu
> 
>  contrib/diff-highlight/README         |  109 ++++++++++++++++++++++++++++++--
>  contrib/diff-highlight/diff-highlight |  109 ++++++++++++++++++++++++---------
>  2 files changed, 181 insertions(+), 37 deletions(-)
> 
> They both have 109 lines changed but the end of the graph lines do not
> coincide...

I think it is rounding error. The first one is +102/-7, and the second
one is +79/-30. When we get to scale_linear, we try to scale 109 change
markers into a 33-character width. So the right scaling factor is ~.303.
So our "true" scaled widths should be:

       README, added: 30.9
     README, deleted:  2.1
    highlight, added: 23.9
  highlight, deleted:  9.1

However, we're dealing with integer numbers of characters, so we need to
round. In this case, it seems that our rounding produces (30, 2) in the
first instance and (24, 9) in the second. Which is odd.  You'd think
we'd either always round to the nearest integer, or always round down.
But we end up rounding 30.9 down and 23.9 up.  So it may be a subtle
loss-of-precision error in scale_linear.

Hmm. Looking at scale_linear, the formula is:

   return ((it - 1) * (width - 1) + max_change - 1) / (max_change - 1);

I don't see how that can be accurate, since the magnitude of the "-1"
tweak will vary based on the value of "it". This code is due to
3ed74e6, but I don't quite follow the logic in the commit message.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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]