mercurial/patch.py
changeset 14402 f03f08240c32
parent 14401 7bb7be1c1385
child 14418 0174d1f79280
equal deleted inserted replaced
14401:7bb7be1c1385 14402:f03f08240c32
  1719     addresult()
  1719     addresult()
  1720     return results
  1720     return results
  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:
  1743         countwidth = 3
  1730         countwidth = 3
  1744     graphwidth = width - countwidth - maxname - 6
  1731     graphwidth = width - countwidth - maxname - 6
  1751         # If diffstat runs out of room it doesn't print anything,
  1738         # If diffstat runs out of room it doesn't print anything,
  1752         # which isn't very useful, so always print at least one + or -
  1739         # which isn't very useful, so always print at least one + or -
  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:
  1760             count = adds + removes
  1747             count = adds + removes
  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')
  1770                       % (len(stats), totaladds, totalremoves))
  1756                       % (len(stats), totaladds, totalremoves))
  1771 
  1757