##// END OF EJS Templates
patch: use diffstatsum in diffstat
Matt Mackall -
r14402:f03f0824 default
parent child Browse files
Show More
@@ -1721,22 +1721,9 b' def diffstatdata(lines):'
1721
1721
1722 def diffstat(lines, width=80, git=False):
1722 def diffstat(lines, width=80, git=False):
1723 output = []
1723 output = []
1724 stats = list(diffstatdata(lines))
1724 stats = diffstatdata(lines)
1725
1725 maxname, totaladds, totalremoves, hasbinary = diffstatsum(stats)
1726 maxtotal, maxname = 0, 0
1726 maxtotal = totaladds + totalremoves
1727 totaladds, totalremoves = 0, 0
1728 hasbinary = False
1729
1730 sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename))
1731 for filename, adds, removes, isbinary in stats]
1732
1733 for filename, adds, removes, isbinary, namewidth in sized:
1734 totaladds += adds
1735 totalremoves += removes
1736 maxname = max(maxname, namewidth)
1737 maxtotal = max(maxtotal, adds + removes)
1738 if isbinary:
1739 hasbinary = True
1740
1727
1741 countwidth = len(str(maxtotal))
1728 countwidth = len(str(maxtotal))
1742 if hasbinary and countwidth < 3:
1729 if hasbinary and countwidth < 3:
@@ -1753,7 +1740,7 b' def diffstat(lines, width=80, git=False)'
1753 # if there were at least some changes.
1740 # if there were at least some changes.
1754 return max(i * graphwidth // maxtotal, int(bool(i)))
1741 return max(i * graphwidth // maxtotal, int(bool(i)))
1755
1742
1756 for filename, adds, removes, isbinary, namewidth in sized:
1743 for filename, adds, removes, isbinary in stats:
1757 if git and isbinary:
1744 if git and isbinary:
1758 count = 'Bin'
1745 count = 'Bin'
1759 else:
1746 else:
@@ -1761,9 +1748,8 b' def diffstat(lines, width=80, git=False)'
1761 pluses = '+' * scale(adds)
1748 pluses = '+' * scale(adds)
1762 minuses = '-' * scale(removes)
1749 minuses = '-' * scale(removes)
1763 output.append(' %s%s | %*s %s%s\n' %
1750 output.append(' %s%s | %*s %s%s\n' %
1764 (filename, ' ' * (maxname - namewidth),
1751 (filename, ' ' * (maxname - encoding.colwidth(filename)),
1765 countwidth, count,
1752 countwidth, count, pluses, minuses))
1766 pluses, minuses))
1767
1753
1768 if stats:
1754 if stats:
1769 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
1755 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
General Comments 0
You need to be logged in to leave comments. Login now