Mercurial > hg
changeset 9330:be2a13153372
diffstat: scale adds/removes proportionally to graph width
The previous method of scaling had a tendency to include graph lines that
went past the output width when the file with the most changes had a very
large number of changes.
author | Brodie Rao <me+hg@dackz.net> |
---|---|
date | Mon, 10 Aug 2009 22:59:29 +0200 |
parents | 567648eab1dd |
children | 9d68d9deda51 |
files | mercurial/patch.py |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Fri Aug 07 21:15:01 2009 +0200 +++ b/mercurial/patch.py Mon Aug 10 22:59:29 2009 +0200 @@ -9,7 +9,7 @@ from i18n import _ from node import hex, nullid, short import base85, cmdutil, mdiff, util, diffhelpers, copies -import cStringIO, email.Parser, os, re, math +import cStringIO, email.Parser, os, re import sys, tempfile, zlib gitre = re.compile('diff --git a/(.*) b/(.*)') @@ -1429,18 +1429,21 @@ maxtotal = max(maxtotal, adds+removes) countwidth = len(str(maxtotal)) - graphwidth = width - countwidth - maxname + graphwidth = width - countwidth - maxname - 6 if graphwidth < 10: graphwidth = 10 - factor = max(int(math.ceil(float(maxtotal) / graphwidth)), 1) + def scale(i): + if maxtotal <= graphwidth: + return i + # If diffstat runs out of room it doesn't print anything, + # which isn't very useful, so always print at least one + or - + # if there were at least some changes. + return max(i * graphwidth // maxtotal, int(bool(i))) for filename, adds, removes in stats: - # If diffstat runs out of room it doesn't print anything, which - # isn't very useful, so always print at least one + or - if there - # were at least some changes - pluses = '+' * max(adds // factor, int(bool(adds))) - minuses = '-' * max(removes // factor, int(bool(removes))) + pluses = '+' * scale(adds) + minuses = '-' * scale(removes) output.append(' %-*s | %*.d %s%s\n' % (maxname, filename, countwidth, adds+removes, pluses, minuses))