##// 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 429 write = fp is None and repo.ui.write or fp.write
430 430 if stat:
431 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 434 else:
434 435 for chunk in chunks:
435 436 write(chunk)
@@ -1098,12 +1098,14 b' def diff(ui, repo, *pats, **opts):'
1098 1098
1099 1099 if stat:
1100 1100 opts['unified'] = '0'
1101 diffopts = patch.diffopts(ui, opts)
1101 1102
1102 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 1105 if stat:
1105 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 1109 else:
1108 1110 for chunk in it:
1109 1111 ui.write(chunk)
@@ -1364,7 +1364,8 b' def diffstatdata(lines):'
1364 1364 for line in lines:
1365 1365 if line.startswith('diff'):
1366 1366 if filename:
1367 yield (filename, adds, removes)
1367 isbinary = adds == 0 and removes == 0
1368 yield (filename, adds, removes, isbinary)
1368 1369 # set numbers to 0 anyway when starting new file
1369 1370 adds, removes = 0, 0
1370 1371 if line.startswith('diff --git'):
@@ -1377,21 +1378,27 b' def diffstatdata(lines):'
1377 1378 elif line.startswith('-') and not line.startswith('---'):
1378 1379 removes += 1
1379 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 1385 output = []
1384 1386 stats = list(diffstatdata(lines))
1385 1387
1386 1388 maxtotal, maxname = 0, 0
1387 1389 totaladds, totalremoves = 0, 0
1388 for filename, adds, removes in stats:
1390 hasbinary = False
1391 for filename, adds, removes, isbinary in stats:
1389 1392 totaladds += adds
1390 1393 totalremoves += removes
1391 1394 maxname = max(maxname, len(filename))
1392 1395 maxtotal = max(maxtotal, adds+removes)
1396 if isbinary:
1397 hasbinary = True
1393 1398
1394 1399 countwidth = len(str(maxtotal))
1400 if hasbinary and countwidth < 3:
1401 countwidth = 3
1395 1402 graphwidth = width - countwidth - maxname - 6
1396 1403 if graphwidth < 10:
1397 1404 graphwidth = 10
@@ -1404,11 +1411,15 b' def diffstat(lines, width=80):'
1404 1411 # if there were at least some changes.
1405 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 1419 pluses = '+' * scale(adds)
1409 1420 minuses = '-' * scale(removes)
1410 1421 output.append(' %-*s | %*s %s%s\n' % (maxname, filename, countwidth,
1411 adds+removes, pluses, minuses))
1422 count, pluses, minuses))
1412 1423
1413 1424 if stats:
1414 1425 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
@@ -29,3 +29,6 b' hg add b'
29 29
30 30 echo '% binary diffstat'
31 31 hg diff --stat
32
33 echo '% binary git diffstat'
34 hg diff --stat --git
@@ -8,5 +8,8 b''
8 8 a | 3 +++
9 9 1 files changed, 3 insertions(+), 0 deletions(-)
10 10 % binary diffstat
11 b | 0
11 b | 0
12 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