Show More
@@ -1174,14 +1174,16 def diff(ui, repo, *pats, **opts): | |||
|
1174 | 1174 | diffopts = patch.diffopts(ui, opts) |
|
1175 | 1175 | |
|
1176 | 1176 | m = cmdutil.match(repo, pats, opts) |
|
1177 | if stat: | |
|
1177 | 1178 | it = patch.diff(repo, node1, node2, match=m, opts=diffopts) |
|
1178 | if stat: | |
|
1179 | 1179 | width = ui.interactive() and util.termwidth() or 80 |
|
1180 |
|
|
|
1181 |
git=diffopts.git) |
|
|
1180 | for chunk, label in patch.diffstatui(util.iterlines(it), width=width, | |
|
1181 | git=diffopts.git): | |
|
1182 | ui.write(chunk, label=label) | |
|
1182 | 1183 | else: |
|
1183 | for chunk in it: | |
|
1184 | ui.write(chunk) | |
|
1184 | it = patch.diffui(repo, node1, node2, match=m, opts=diffopts) | |
|
1185 | for chunk, label in it: | |
|
1186 | ui.write(chunk, label=label) | |
|
1185 | 1187 | |
|
1186 | 1188 | def export(ui, repo, *changesets, **opts): |
|
1187 | 1189 | """dump the header and diffs for one or more changesets |
@@ -1466,6 +1466,43 def diff(repo, node1=None, node2=None, m | |||
|
1466 | 1466 | else: |
|
1467 | 1467 | return difffn(opts, None) |
|
1468 | 1468 | |
|
1469 | def difflabel(func, *args, **kw): | |
|
1470 | '''yields 2-tuples of (output, label) based on the output of func()''' | |
|
1471 | prefixes = [('diff', 'diff.diffline'), | |
|
1472 | ('copy', 'diff.extended'), | |
|
1473 | ('rename', 'diff.extended'), | |
|
1474 | ('old', 'diff.extended'), | |
|
1475 | ('new', 'diff.extended'), | |
|
1476 | ('deleted', 'diff.extended'), | |
|
1477 | ('---', 'diff.file_a'), | |
|
1478 | ('+++', 'diff.file_b'), | |
|
1479 | ('@@', 'diff.hunk'), | |
|
1480 | ('-', 'diff.deleted'), | |
|
1481 | ('+', 'diff.inserted')] | |
|
1482 | ||
|
1483 | for chunk in func(*args, **kw): | |
|
1484 | lines = chunk.split('\n') | |
|
1485 | for i, line in enumerate(lines): | |
|
1486 | if i != 0: | |
|
1487 | yield ('\n', '') | |
|
1488 | stripline = line | |
|
1489 | if line and line[0] in '+-': | |
|
1490 | # highlight trailing whitespace, but only in changed lines | |
|
1491 | stripline = line.rstrip() | |
|
1492 | for prefix, label in prefixes: | |
|
1493 | if stripline.startswith(prefix): | |
|
1494 | yield (stripline, label) | |
|
1495 | break | |
|
1496 | else: | |
|
1497 | yield (line, '') | |
|
1498 | if line != stripline: | |
|
1499 | yield (line[len(stripline):], 'diff.trailingwhitespace') | |
|
1500 | ||
|
1501 | def diffui(*args, **kw): | |
|
1502 | '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' | |
|
1503 | return difflabel(diff, *args, **kw) | |
|
1504 | ||
|
1505 | ||
|
1469 | 1506 | def _addmodehdr(header, omode, nmode): |
|
1470 | 1507 | if omode != nmode: |
|
1471 | 1508 | header.append('old mode %s\n' % omode) |
@@ -1636,3 +1673,22 def diffstat(lines, width=80, git=False) | |||
|
1636 | 1673 | % (len(stats), totaladds, totalremoves)) |
|
1637 | 1674 | |
|
1638 | 1675 | return ''.join(output) |
|
1676 | ||
|
1677 | def diffstatui(*args, **kw): | |
|
1678 | '''like diffstat(), but yields 2-tuples of (output, label) for | |
|
1679 | ui.write() | |
|
1680 | ''' | |
|
1681 | ||
|
1682 | for line in diffstat(*args, **kw).splitlines(): | |
|
1683 | if line and line[-1] in '+-': | |
|
1684 | name, graph = line.rsplit(' ', 1) | |
|
1685 | yield (name + ' ', '') | |
|
1686 | m = re.search(r'\++', graph) | |
|
1687 | if m: | |
|
1688 | yield (m.group(0), 'diffstat.inserted') | |
|
1689 | m = re.search(r'-+', graph) | |
|
1690 | if m: | |
|
1691 | yield (m.group(0), 'diffstat.deleted') | |
|
1692 | else: | |
|
1693 | yield (line, '') | |
|
1694 | yield ('\n', '') |
General Comments 0
You need to be logged in to leave comments.
Login now