# HG changeset patch # User Yuya Nishihara # Date 1516513024 -32400 # Node ID d4c210ee894f2703eb10d2557fef9113a5bb1a52 # Parent fcde8946c553a7d6a13ba21e5dcd32c79aa5598f logcmdutil: unindent diff generator of changesetprinter Prepares for the next few patches which will make matchfn and hunksfilterfn always available. diff -r fcde8946c553 -r d4c210ee894f mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py Sun Jan 21 14:07:52 2018 +0900 +++ b/mercurial/logcmdutil.py Sun Jan 21 14:37:04 2018 +0900 @@ -282,24 +282,25 @@ def _showpatch(self, ctx): matchfn = self._makefilematcher(ctx) hunksfilterfn = self._makehunksfilter(ctx) - if matchfn: - stat = self.diffopts.get('stat') - diff = self.diffopts.get('patch') - diffopts = patch.diffallopts(self.ui, self.diffopts) - node = ctx.node() - prev = ctx.p1().node() - if stat: - diffordiffstat(self.ui, self.repo, diffopts, prev, node, - match=matchfn, stat=True, - hunksfilterfn=hunksfilterfn) - if diff: - if stat: - self.ui.write("\n") - diffordiffstat(self.ui, self.repo, diffopts, prev, node, - match=matchfn, stat=False, - hunksfilterfn=hunksfilterfn) - if stat or diff: - self.ui.write("\n") + if not matchfn: + return + stat = self.diffopts.get('stat') + diff = self.diffopts.get('patch') + diffopts = patch.diffallopts(self.ui, self.diffopts) + node = ctx.node() + prev = ctx.p1().node() + if stat: + diffordiffstat(self.ui, self.repo, diffopts, prev, node, + match=matchfn, stat=True, + hunksfilterfn=hunksfilterfn) + if stat and diff: + self.ui.write("\n") + if diff: + diffordiffstat(self.ui, self.repo, diffopts, prev, node, + match=matchfn, stat=False, + hunksfilterfn=hunksfilterfn) + if stat or diff: + self.ui.write("\n") class jsonchangeset(changesetprinter): '''format changeset information.''' @@ -383,22 +384,21 @@ for k, v in copies)) matchfn = self._makefilematcher(ctx) - if matchfn: - stat = self.diffopts.get('stat') - diff = self.diffopts.get('patch') - diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) - node, prev = ctx.node(), ctx.p1().node() - if stat: - self.ui.pushbuffer() - diffordiffstat(self.ui, self.repo, diffopts, prev, node, - match=matchfn, stat=True) - self.ui.write((',\n "diffstat": "%s"') - % j(self.ui.popbuffer())) - if diff: - self.ui.pushbuffer() - diffordiffstat(self.ui, self.repo, diffopts, prev, node, - match=matchfn, stat=False) - self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) + stat = self.diffopts.get('stat') + diff = self.diffopts.get('patch') + diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) + node, prev = ctx.node(), ctx.p1().node() + if matchfn and stat: + self.ui.pushbuffer() + diffordiffstat(self.ui, self.repo, diffopts, prev, node, + match=matchfn, stat=True) + self.ui.write((',\n "diffstat": "%s"') + % j(self.ui.popbuffer())) + if matchfn and diff: + self.ui.pushbuffer() + diffordiffstat(self.ui, self.repo, diffopts, prev, node, + match=matchfn, stat=False) + self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) self.ui.write("\n }")