##// END OF EJS Templates
diffstat: with --git, mark binary files with Bin...
Brodie Rao -
r9642:7d17794f default
parent child Browse files
Show More
@@ -429,7 +429,8 b' class queue(object):'
429 write = fp is None and repo.ui.write or fp.write
429 write = fp is None and repo.ui.write or fp.write
430 if stat:
430 if stat:
431 width = self.ui.interactive() and util.termwidth() or 80
431 width = self.ui.interactive() and util.termwidth() or 80
432 write(patch.diffstat(util.iterlines(chunks), width=width))
432 write(patch.diffstat(util.iterlines(chunks), width=width,
433 git=self.diffopts().git))
433 else:
434 else:
434 for chunk in chunks:
435 for chunk in chunks:
435 write(chunk)
436 write(chunk)
@@ -1098,12 +1098,14 b' def diff(ui, repo, *pats, **opts):'
1098
1098
1099 if stat:
1099 if stat:
1100 opts['unified'] = '0'
1100 opts['unified'] = '0'
1101 diffopts = patch.diffopts(ui, opts)
1101
1102
1102 m = cmdutil.match(repo, pats, opts)
1103 m = cmdutil.match(repo, pats, opts)
1103 it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
1104 it = patch.diff(repo, node1, node2, match=m, opts=diffopts)
1104 if stat:
1105 if stat:
1105 width = ui.interactive() and util.termwidth() or 80
1106 width = ui.interactive() and util.termwidth() or 80
1106 ui.write(patch.diffstat(util.iterlines(it), width=width))
1107 ui.write(patch.diffstat(util.iterlines(it), width=width,
1108 git=diffopts.git))
1107 else:
1109 else:
1108 for chunk in it:
1110 for chunk in it:
1109 ui.write(chunk)
1111 ui.write(chunk)
@@ -1364,7 +1364,8 b' def diffstatdata(lines):'
1364 for line in lines:
1364 for line in lines:
1365 if line.startswith('diff'):
1365 if line.startswith('diff'):
1366 if filename:
1366 if filename:
1367 yield (filename, adds, removes)
1367 isbinary = adds == 0 and removes == 0
1368 yield (filename, adds, removes, isbinary)
1368 # set numbers to 0 anyway when starting new file
1369 # set numbers to 0 anyway when starting new file
1369 adds, removes = 0, 0
1370 adds, removes = 0, 0
1370 if line.startswith('diff --git'):
1371 if line.startswith('diff --git'):
@@ -1377,21 +1378,27 b' def diffstatdata(lines):'
1377 elif line.startswith('-') and not line.startswith('---'):
1378 elif line.startswith('-') and not line.startswith('---'):
1378 removes += 1
1379 removes += 1
1379 if filename:
1380 if filename:
1380 yield (filename, adds, removes)
1381 isbinary = adds == 0 and removes == 0
1382 yield (filename, adds, removes, isbinary)
1381
1383
1382 def diffstat(lines, width=80):
1384 def diffstat(lines, width=80, git=False):
1383 output = []
1385 output = []
1384 stats = list(diffstatdata(lines))
1386 stats = list(diffstatdata(lines))
1385
1387
1386 maxtotal, maxname = 0, 0
1388 maxtotal, maxname = 0, 0
1387 totaladds, totalremoves = 0, 0
1389 totaladds, totalremoves = 0, 0
1388 for filename, adds, removes in stats:
1390 hasbinary = False
1391 for filename, adds, removes, isbinary in stats:
1389 totaladds += adds
1392 totaladds += adds
1390 totalremoves += removes
1393 totalremoves += removes
1391 maxname = max(maxname, len(filename))
1394 maxname = max(maxname, len(filename))
1392 maxtotal = max(maxtotal, adds+removes)
1395 maxtotal = max(maxtotal, adds+removes)
1396 if isbinary:
1397 hasbinary = True
1393
1398
1394 countwidth = len(str(maxtotal))
1399 countwidth = len(str(maxtotal))
1400 if hasbinary and countwidth < 3:
1401 countwidth = 3
1395 graphwidth = width - countwidth - maxname - 6
1402 graphwidth = width - countwidth - maxname - 6
1396 if graphwidth < 10:
1403 if graphwidth < 10:
1397 graphwidth = 10
1404 graphwidth = 10
@@ -1404,11 +1411,15 b' def diffstat(lines, width=80):'
1404 # if there were at least some changes.
1411 # if there were at least some changes.
1405 return max(i * graphwidth // maxtotal, int(bool(i)))
1412 return max(i * graphwidth // maxtotal, int(bool(i)))
1406
1413
1407 for filename, adds, removes in stats:
1414 for filename, adds, removes, isbinary in stats:
1415 if git and isbinary:
1416 count = 'Bin'
1417 else:
1418 count = adds + removes
1408 pluses = '+' * scale(adds)
1419 pluses = '+' * scale(adds)
1409 minuses = '-' * scale(removes)
1420 minuses = '-' * scale(removes)
1410 output.append(' %-*s | %*s %s%s\n' % (maxname, filename, countwidth,
1421 output.append(' %-*s | %*s %s%s\n' % (maxname, filename, countwidth,
1411 adds+removes, pluses, minuses))
1422 count, pluses, minuses))
1412
1423
1413 if stats:
1424 if stats:
1414 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
1425 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
@@ -29,3 +29,6 b' hg add b'
29
29
30 echo '% binary diffstat'
30 echo '% binary diffstat'
31 hg diff --stat
31 hg diff --stat
32
33 echo '% binary git diffstat'
34 hg diff --stat --git
@@ -8,5 +8,8 b''
8 a | 3 +++
8 a | 3 +++
9 1 files changed, 3 insertions(+), 0 deletions(-)
9 1 files changed, 3 insertions(+), 0 deletions(-)
10 % binary diffstat
10 % binary diffstat
11 b | 0
11 b | 0
12 1 files changed, 0 insertions(+), 0 deletions(-)
12 1 files changed, 0 insertions(+), 0 deletions(-)
13 % binary git diffstat
14 b | Bin
15 1 files changed, 0 insertions(+), 0 deletions(-)
General Comments 0
You need to be logged in to leave comments. Login now