##// END OF EJS Templates
diff: pass a diff hunks filter function from changeset_printer to patch.diff()...
Denis Laxalde -
r34857:890afefa default
parent child Browse files
Show More
@@ -1494,7 +1494,7 b" def export(repo, revs, fntemplate='hg-%h"
1494 1494
1495 1495 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
1496 1496 changes=None, stat=False, fp=None, prefix='',
1497 root='', listsubrepos=False):
1497 root='', listsubrepos=False, hunksfilterfn=None):
1498 1498 '''show diff or diffstat.'''
1499 1499 if fp is None:
1500 1500 write = ui.write
@@ -1522,14 +1522,16 b' def diffordiffstat(ui, repo, diffopts, n'
1522 1522 if not ui.plain():
1523 1523 width = ui.termwidth()
1524 1524 chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
1525 prefix=prefix, relroot=relroot)
1525 prefix=prefix, relroot=relroot,
1526 hunksfilterfn=hunksfilterfn)
1526 1527 for chunk, label in patch.diffstatui(util.iterlines(chunks),
1527 1528 width=width):
1528 1529 write(chunk, label=label)
1529 1530 else:
1530 1531 for chunk, label in patch.diffui(repo, node1, node2, match,
1531 1532 changes, diffopts, prefix=prefix,
1532 relroot=relroot):
1533 relroot=relroot,
1534 hunksfilterfn=hunksfilterfn):
1533 1535 write(chunk, label=label)
1534 1536
1535 1537 if listsubrepos:
@@ -1591,16 +1593,17 b' class changeset_printer(object):'
1591 1593 if self.footer:
1592 1594 self.ui.write(self.footer)
1593 1595
1594 def show(self, ctx, copies=None, matchfn=None, **props):
1596 def show(self, ctx, copies=None, matchfn=None, hunksfilterfn=None,
1597 **props):
1595 1598 props = pycompat.byteskwargs(props)
1596 1599 if self.buffered:
1597 1600 self.ui.pushbuffer(labeled=True)
1598 self._show(ctx, copies, matchfn, props)
1601 self._show(ctx, copies, matchfn, hunksfilterfn, props)
1599 1602 self.hunk[ctx.rev()] = self.ui.popbuffer()
1600 1603 else:
1601 self._show(ctx, copies, matchfn, props)
1602
1603 def _show(self, ctx, copies, matchfn, props):
1604 self._show(ctx, copies, matchfn, hunksfilterfn, props)
1605
1606 def _show(self, ctx, copies, matchfn, hunksfilterfn, props):
1604 1607 '''show a single changeset or file revision'''
1605 1608 changenode = ctx.node()
1606 1609 rev = ctx.rev()
@@ -1714,7 +1717,7 b' class changeset_printer(object):'
1714 1717 label='log.summary')
1715 1718 self.ui.write("\n")
1716 1719
1717 self.showpatch(ctx, matchfn)
1720 self.showpatch(ctx, matchfn, hunksfilterfn=hunksfilterfn)
1718 1721
1719 1722 def _showobsfate(self, ctx):
1720 1723 obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui)
@@ -1729,7 +1732,7 b' class changeset_printer(object):'
1729 1732 '''empty method used by extension as a hook point
1730 1733 '''
1731 1734
1732 def showpatch(self, ctx, matchfn):
1735 def showpatch(self, ctx, matchfn, hunksfilterfn=None):
1733 1736 if not matchfn:
1734 1737 matchfn = self.matchfn
1735 1738 if matchfn:
@@ -1740,12 +1743,14 b' class changeset_printer(object):'
1740 1743 prev = ctx.p1().node()
1741 1744 if stat:
1742 1745 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
1743 match=matchfn, stat=True)
1746 match=matchfn, stat=True,
1747 hunksfilterfn=hunksfilterfn)
1744 1748 if diff:
1745 1749 if stat:
1746 1750 self.ui.write("\n")
1747 1751 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
1748 match=matchfn, stat=False)
1752 match=matchfn, stat=False,
1753 hunksfilterfn=hunksfilterfn)
1749 1754 self.ui.write("\n")
1750 1755
1751 1756 class jsonchangeset(changeset_printer):
@@ -1762,7 +1767,7 b' class jsonchangeset(changeset_printer):'
1762 1767 else:
1763 1768 self.ui.write("[]\n")
1764 1769
1765 def _show(self, ctx, copies, matchfn, props):
1770 def _show(self, ctx, copies, matchfn, hunksfilterfn, props):
1766 1771 '''show a single changeset or file revision'''
1767 1772 rev = ctx.rev()
1768 1773 if rev is None:
@@ -1896,7 +1901,7 b' class changeset_templater(changeset_prin'
1896 1901 self.footer += templater.stringify(self.t(self._parts['docfooter']))
1897 1902 return super(changeset_templater, self).close()
1898 1903
1899 def _show(self, ctx, copies, matchfn, props):
1904 def _show(self, ctx, copies, matchfn, hunksfilterfn, props):
1900 1905 '''show a single changeset or file revision'''
1901 1906 props = props.copy()
1902 1907 props.update(templatekw.keywords)
@@ -1928,7 +1933,7 b' class changeset_templater(changeset_prin'
1928 1933 # write changeset metadata, then patch if requested
1929 1934 key = self._parts[self._tref]
1930 1935 self.ui.write(templater.stringify(self.t(key, **props)))
1931 self.showpatch(ctx, matchfn)
1936 self.showpatch(ctx, matchfn, hunksfilterfn=hunksfilterfn)
1932 1937
1933 1938 if self._parts['footer']:
1934 1939 if not self.footer:
@@ -2296,7 +2296,8 b' def difffeatureopts(ui, opts=None, untru'
2296 2296 return mdiff.diffopts(**pycompat.strkwargs(buildopts))
2297 2297
2298 2298 def diff(repo, node1=None, node2=None, match=None, changes=None,
2299 opts=None, losedatafn=None, prefix='', relroot='', copy=None):
2299 opts=None, losedatafn=None, prefix='', relroot='', copy=None,
2300 hunksfilterfn=None):
2300 2301 '''yields diff of changes to files between two nodes, or node and
2301 2302 working directory.
2302 2303
@@ -2318,12 +2319,18 b' def diff(repo, node1=None, node2=None, m'
2318 2319 patterns that fall outside it will be ignored.
2319 2320
2320 2321 copy, if not empty, should contain mappings {dst@y: src@x} of copy
2321 information.'''
2322 information.
2323
2324 hunksfilterfn, if not None, should be a function taking a filectx and
2325 hunks generator that may yield filtered hunks.
2326 '''
2322 2327 for fctx1, fctx2, hdr, hunks in diffhunks(
2323 2328 repo, node1=node1, node2=node2,
2324 2329 match=match, changes=changes, opts=opts,
2325 2330 losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
2326 2331 ):
2332 if hunksfilterfn is not None:
2333 hunks = hunksfilterfn(fctx2, hunks)
2327 2334 text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
2328 2335 if hdr and (text or len(hdr) > 1):
2329 2336 yield '\n'.join(hdr) + '\n'
General Comments 0
You need to be logged in to leave comments. Login now