Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 14400:cd1ca2556cac
diffstatdata: no longer a generator
This produces a smallish amount of data and all consumers needed to
buffer it anyway.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 21 May 2011 15:01:28 -0500 |
parents | bb5cbc16349e |
children | 7bb7be1c1385 |
comparison
equal
deleted
inserted
replaced
14399:71938479eff9 | 14400:cd1ca2556cac |
---|---|
1682 yield text | 1682 yield text |
1683 | 1683 |
1684 def diffstatdata(lines): | 1684 def diffstatdata(lines): |
1685 diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') | 1685 diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') |
1686 | 1686 |
1687 results = [] | |
1687 filename, adds, removes = None, 0, 0 | 1688 filename, adds, removes = None, 0, 0 |
1689 | |
1690 def addresult(): | |
1691 if filename: | |
1692 isbinary = adds == 0 and removes == 0 | |
1693 results.append((filename, adds, removes, isbinary)) | |
1694 | |
1688 for line in lines: | 1695 for line in lines: |
1689 if line.startswith('diff'): | 1696 if line.startswith('diff'): |
1690 if filename: | 1697 addresult() |
1691 isbinary = adds == 0 and removes == 0 | |
1692 yield (filename, adds, removes, isbinary) | |
1693 # set numbers to 0 anyway when starting new file | 1698 # set numbers to 0 anyway when starting new file |
1694 adds, removes = 0, 0 | 1699 adds, removes = 0, 0 |
1695 if line.startswith('diff --git'): | 1700 if line.startswith('diff --git'): |
1696 filename = gitre.search(line).group(1) | 1701 filename = gitre.search(line).group(1) |
1697 elif line.startswith('diff -r'): | 1702 elif line.startswith('diff -r'): |
1699 filename = diffre.search(line).group(1) | 1704 filename = diffre.search(line).group(1) |
1700 elif line.startswith('+') and not line.startswith('+++'): | 1705 elif line.startswith('+') and not line.startswith('+++'): |
1701 adds += 1 | 1706 adds += 1 |
1702 elif line.startswith('-') and not line.startswith('---'): | 1707 elif line.startswith('-') and not line.startswith('---'): |
1703 removes += 1 | 1708 removes += 1 |
1704 if filename: | 1709 addresult() |
1705 isbinary = adds == 0 and removes == 0 | 1710 return results |
1706 yield (filename, adds, removes, isbinary) | |
1707 | 1711 |
1708 def diffstat(lines, width=80, git=False): | 1712 def diffstat(lines, width=80, git=False): |
1709 output = [] | 1713 output = [] |
1710 stats = list(diffstatdata(lines)) | 1714 stats = list(diffstatdata(lines)) |
1711 | 1715 |