comparison mercurial/patch.py @ 7664:3cc74ee75b0d

diffstat: don't fail on merges First version by Alexander Solovyov <piranha@piranha.org.ua>
author Patrick Mezard <pmezard@gmail.com>
date Tue, 13 Jan 2009 20:28:06 +0200
parents ab39d1813e51
children e5f445c94226
comparison
equal deleted inserted replaced
7663:b0a0eb28a933 7664:3cc74ee75b0d
1341 1341
1342 for seqno, rev in enumerate(revs): 1342 for seqno, rev in enumerate(revs):
1343 single(rev, seqno+1, fp) 1343 single(rev, seqno+1, fp)
1344 1344
1345 def diffstatdata(lines): 1345 def diffstatdata(lines):
1346 filename = None 1346 filename, adds, removes = None, 0, 0
1347 for line in lines: 1347 for line in lines:
1348 if line.startswith('diff'): 1348 if line.startswith('diff'):
1349 if filename: 1349 if filename:
1350 yield (filename, adds, removes) 1350 yield (filename, adds, removes)
1351 # set numbers to 0 anyway when starting new file 1351 # set numbers to 0 anyway when starting new file
1352 adds = 0 1352 adds, removes = 0, 0
1353 removes = 0
1354 if line.startswith('diff --git'): 1353 if line.startswith('diff --git'):
1355 filename = gitre.search(line).group(1) 1354 filename = gitre.search(line).group(1)
1356 else: 1355 else:
1357 # format: "diff -r ... -r ... file name" 1356 # format: "diff -r ... -r ... file name"
1358 filename = line.split(None, 5)[-1] 1357 filename = line.split(None, 5)[-1]
1359 elif line.startswith('+') and not line.startswith('+++'): 1358 elif line.startswith('+') and not line.startswith('+++'):
1360 adds += 1 1359 adds += 1
1361 elif line.startswith('-') and not line.startswith('---'): 1360 elif line.startswith('-') and not line.startswith('---'):
1362 removes += 1 1361 removes += 1
1363 yield (filename, adds, removes) 1362 if filename:
1363 yield (filename, adds, removes)
1364 1364
1365 def diffstat(lines): 1365 def diffstat(lines):
1366 output = [] 1366 output = []
1367 stats = list(diffstatdata(lines)) 1367 stats = list(diffstatdata(lines))
1368 width = util.termwidth() - 2 1368 width = util.termwidth() - 2