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