Patchwork [2,of,2] log: consume --stat/patch options at constructor of changesetprinter

login
register
mail settings
Submitter Yuya Nishihara
Date May 6, 2018, 2:41 a.m.
Message ID <f949e389b8697ce73ebb.1525574485@mimosa>
Download mbox | patch
Permalink /patch/31271/
State Accepted
Headers show

Comments

Yuya Nishihara - May 6, 2018, 2:41 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524984721 -32400
#      Sun Apr 29 15:52:01 2018 +0900
# Node ID f949e389b8697ce73ebb432d9002d7a85959773a
# Parent  5ab73949f3870cfaa4b16180511f22a8f51130a8
log: consume --stat/patch options at constructor of changesetprinter

The variable name, self.diffopts, was confusing. Let's split it to two
booleans.

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -155,7 +155,8 @@  class changesetprinter(object):
         self.buffered = buffered
         self._differ = differ or changesetdiffer()
         self._diffopts = patch.diffallopts(ui, diffopts)
-        self.diffopts = diffopts or {}
+        self._includestat = diffopts and diffopts.get('stat')
+        self._includediff = diffopts and diffopts.get('patch')
         self.header = {}
         self.hunk = {}
         self.lastheader = None
@@ -299,15 +300,13 @@  class changesetprinter(object):
         '''
 
     def _showpatch(self, ctx):
-        stat = self.diffopts.get('stat')
-        diff = self.diffopts.get('patch')
-        if stat:
+        if self._includestat:
             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
-        if stat and diff:
+        if self._includestat and self._includediff:
             self.ui.write("\n")
-        if diff:
+        if self._includediff:
             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
-        if stat or diff:
+        if self._includestat or self._includediff:
             self.ui.write("\n")
 
 class changesetformatter(changesetprinter):
@@ -368,13 +367,11 @@  class changesetformatter(changesetprinte
                 fm.data(copies=fm.formatdict(copies,
                                              key='name', value='source'))
 
-        stat = self.diffopts.get('stat')
-        diff = self.diffopts.get('patch')
-        if stat:
+        if self._includestat:
             self.ui.pushbuffer()
             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
             fm.data(diffstat=self.ui.popbuffer())
-        if diff:
+        if self._includediff:
             self.ui.pushbuffer()
             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
             fm.data(diff=self.ui.popbuffer())