mercurial/patch.py
changeset 7860 162fd31bbd93
parent 7783 2c5b2abfb8be
child 7873 4a4c7f6a5912
child 7971 6ea0318daf75
equal deleted inserted replaced
7857:6af7c0e5908c 7860:162fd31bbd93
  1357         elif line.startswith('-') and not line.startswith('---'):
  1357         elif line.startswith('-') and not line.startswith('---'):
  1358             removes += 1
  1358             removes += 1
  1359     if filename:
  1359     if filename:
  1360         yield (filename, adds, removes)
  1360         yield (filename, adds, removes)
  1361 
  1361 
  1362 def diffstat(lines):
  1362 def diffstat(lines, width=80):
  1363     output = []
  1363     output = []
  1364     stats = list(diffstatdata(lines))
  1364     stats = list(diffstatdata(lines))
  1365     width = util.termwidth() - 2
       
  1366 
  1365 
  1367     maxtotal, maxname = 0, 0
  1366     maxtotal, maxname = 0, 0
  1368     totaladds, totalremoves = 0, 0
  1367     totaladds, totalremoves = 0, 0
  1369     for filename, adds, removes in stats:
  1368     for filename, adds, removes in stats:
  1370         totaladds += adds
  1369         totaladds += adds
  1375     countwidth = len(str(maxtotal))
  1374     countwidth = len(str(maxtotal))
  1376     graphwidth = width - countwidth - maxname
  1375     graphwidth = width - countwidth - maxname
  1377     if graphwidth < 10:
  1376     if graphwidth < 10:
  1378         graphwidth = 10
  1377         graphwidth = 10
  1379 
  1378 
  1380     factor = int(math.ceil(float(maxtotal) / graphwidth))
  1379     factor = max(int(math.ceil(float(maxtotal) / graphwidth)), 1)
  1381 
  1380 
  1382     for filename, adds, removes in stats:
  1381     for filename, adds, removes in stats:
  1383         # If diffstat runs out of room it doesn't print anything, which
  1382         # If diffstat runs out of room it doesn't print anything, which
  1384         # isn't very useful, so always print at least one + or - if there
  1383         # isn't very useful, so always print at least one + or - if there
  1385         # were at least some changes
  1384         # were at least some changes
  1387         minuses = '-' * max(removes/factor, int(bool(removes)))
  1386         minuses = '-' * max(removes/factor, int(bool(removes)))
  1388         output.append(' %-*s |  %*.d %s%s\n' % (maxname, filename, countwidth,
  1387         output.append(' %-*s |  %*.d %s%s\n' % (maxname, filename, countwidth,
  1389                                                 adds+removes, pluses, minuses))
  1388                                                 adds+removes, pluses, minuses))
  1390 
  1389 
  1391     if stats:
  1390     if stats:
  1392         output.append(' %d files changed, %d insertions(+), %d deletions(-)\n' %
  1391         output.append(' %d files changed, %d insertions(+), %d deletions(-)\n'
  1393                       (len(stats), totaladds, totalremoves))
  1392                       % (len(stats), totaladds, totalremoves))
  1394 
  1393 
  1395     return ''.join(output)
  1394     return ''.join(output)