Patchwork D5485: log: fixes line wrap on diffstat (issue5800)

login
register
mail settings
Submitter phabricator
Date Dec. 30, 2018, 1:27 p.m.
Message ID <527aa6fa4513f9aa099a0ba459493799@localhost.localdomain>
Download mbox | patch
Permalink /patch/37392/
State Not Applicable
Headers show

Comments

phabricator - Dec. 30, 2018, 1:27 p.m.
navaneeth.suresh updated this revision to Diff 12995.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5485?vs=12983&id=12995

REVISION DETAIL
  https://phab.mercurial-scm.org/D5485

AFFECTED FILES
  mercurial/logcmdutil.py

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: yuja, mercurial-devel
Yuya Nishihara - Jan. 2, 2019, 3:51 a.m.
Looks generally good.

Can you add some tests with/without the -T option? There are two callers of
_showpatch().

> +        graphwidth = props.get('graphwidth')
> +        if not graphwidth:
> +            graphwidth = 0

Nit: can be written as `props.get('graphwidth', 0)`.
phabricator - Jan. 2, 2019, 3:52 a.m.
yuja added a comment.


  Looks generally good.
  
  Can you add some tests with/without the -T option? There are two callers of
  _showpatch().
  
  > +        graphwidth = props.get('graphwidth')
  >  +        if not graphwidth:
  >  +            graphwidth = 0
  
  Nit: can be written as `props.get('graphwidth', 0)`.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5485

To: navaneeth.suresh, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -55,8 +55,8 @@ 
     return limit
 
 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
-                   changes=None, stat=False, fp=None, prefix='',
-                   root='', listsubrepos=False, hunksfilterfn=None):
+                   changes=None, stat=False, graphwidth=0, fp=None,
+                   prefix='', root='', listsubrepos=False, hunksfilterfn=None):
     '''show diff or diffstat.'''
     if root:
         relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
@@ -76,7 +76,7 @@ 
         diffopts = diffopts.copy(context=0, noprefix=False)
         width = 80
         if not ui.plain():
-            width = ui.termwidth()
+            width = ui.termwidth() - graphwidth
 
     chunks = repo[node2].diff(repo[node1], match, changes, opts=diffopts,
                               prefix=prefix, relroot=relroot,
@@ -130,12 +130,13 @@ 
     def _makehunksfilter(self, ctx):
         return None
 
-    def showdiff(self, ui, ctx, diffopts, stat=False):
+    def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False):
         repo = ctx.repo()
         node = ctx.node()
         prev = ctx.p1().node()
         diffordiffstat(ui, repo, diffopts, prev, node,
                        match=self._makefilematcher(ctx), stat=stat,
+                       graphwidth=graphwidth,
                        hunksfilterfn=self._makehunksfilter(ctx))
 
 def changesetlabels(ctx):
@@ -193,6 +194,9 @@ 
     def _show(self, ctx, copies, props):
         '''show a single changeset or file revision'''
         changenode = ctx.node()
+        graphwidth = props.get('graphwidth')
+        if not graphwidth:
+            graphwidth = 0
 
         if self.ui.quiet:
             self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
@@ -285,7 +289,7 @@ 
                               label='log.summary')
         self.ui.write("\n")
 
-        self._showpatch(ctx)
+        self._showpatch(ctx, graphwidth)
 
     def _showobsfate(self, ctx):
         # TODO: do not depend on templater
@@ -304,13 +308,15 @@ 
         '''empty method used by extension as a hook point
         '''
 
-    def _showpatch(self, ctx):
+    def _showpatch(self, ctx, graphwidth=0):
         if self._includestat:
-            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
+            self._differ.showdiff(self.ui, ctx, self._diffopts,
+                                  graphwidth, stat=True)
         if self._includestat and self._includediff:
             self.ui.write("\n")
         if self._includediff:
-            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
+            self._differ.showdiff(self.ui, ctx, self._diffopts,
+                                  graphwidth, stat=False)
         if self._includestat or self._includediff:
             self.ui.write("\n")