logcmdutil: unindent diff generator of changesetprinter
authorYuya Nishihara <yuya@tcha.org>
Sun, 21 Jan 2018 14:37:04 +0900
changeset 36004 d4c210ee894f
parent 36003 fcde8946c553
child 36005 dd77e36eabb6
logcmdutil: unindent diff generator of changesetprinter Prepares for the next few patches which will make matchfn and hunksfilterfn always available.
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 }")