From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: diff --stat
Date: Tue, 14 Feb 2012 14:50:36 -0500 [thread overview]
Message-ID: <20120214195036.GD12072@sigill.intra.peff.net> (raw)
In-Reply-To: <7v4nuub7el.fsf@alter.siamese.dyndns.org>
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
next prev parent reply other threads:[~2012-02-14 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 0:11 diff --stat Junio C Hamano
2012-02-14 19:50 ` Jeff King [this message]
2012-02-14 20:07 ` Junio C Hamano
2012-02-14 20:29 ` Jeff King
2012-02-14 21:49 ` Junio C Hamano
2012-02-14 21:53 ` Jeff King
2012-02-14 22:06 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120214195036.GD12072@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).