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

login
register
mail settings
Submitter phabricator
Date Jan. 2, 2019, 11:32 a.m.
Message ID <36eb5e94943a652dc06452ef69f2cf88@localhost.localdomain>
Download mbox | patch
Permalink /patch/37421/
State Not Applicable
Headers show

Comments

phabricator - Jan. 2, 2019, 11:32 a.m.
navaneeth.suresh updated this revision to Diff 12996.

REPOSITORY
  rHG Mercurial

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

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

AFFECTED FILES
  mercurial/logcmdutil.py
  tests/test-log.t

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: yuja, mercurial-devel
Yuya Nishihara - Jan. 3, 2019, 9:21 a.m.
Queued, thanks.

>  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,

Reordered arguments to fix mq failure. Next time, please run all tests.
phabricator - Jan. 3, 2019, 9:27 a.m.
yuja added a comment.


  Queued, thanks.
  
  >   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,
  
  Reordered arguments to fix mq failure. Next time, please run all tests.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -2637,3 +2637,121 @@ 
      summary:     A1B1C1
   
   $ cd ..
+
+--- going to test line wrap fix on using both --stat and -G (issue5800)
+  $ hg init issue5800
+  $ cd issue5800
+  $ touch a
+  $ hg ci -Am 'add a'
+  adding a
+---- now we are going to add 300 lines to a
+  $ for i in $(seq 1 300); do echo $i >> a; done
+  $ hg ci -m 'modify a'
+  $ hg log
+  changeset:   1:a98683e6a834
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     modify a
+  
+  changeset:   0:ac82d8b1f7c4
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add a
+  
+---- now visualise the changes we made without template
+  $ hg log -l1 -r a98683e6a834 --stat -G
+  @  changeset:   1:a98683e6a834
+  |  tag:         tip
+  ~  user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+---- with template
+  $ hg log -l1 -r a98683e6a834 --stat -G -T bisect
+  @  changeset:   1:a98683e6a834
+  |  bisect:
+  ~  tag:         tip
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T changelog
+  1970-01-01  test  <test>
+  
+  @  	* a:
+  |  	modify a
+  ~  	[a98683e6a834] [tip]
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T compact
+  @  1[tip]   a98683e6a834   1970-01-01 00:00 +0000   test
+  |    modify a
+  ~
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T default
+  @  changeset:   1:a98683e6a834
+  |  tag:         tip
+  ~  user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T phases
+  @  changeset:   1:a98683e6a834
+  |  tag:         tip
+  ~  phase:       draft
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T show
+  @  changeset:   1:a98683e6a834
+  |  tag:         tip
+  ~  user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T status
+  @  changeset:   1:a98683e6a834
+  |  tag:         tip
+  ~  user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     modify a
+     files:
+     M a
+  
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  $ hg log -l1 -r a98683e6a834 --stat -G -T xml
+  <?xml version="1.0"?>
+  <log>
+  @  <logentry revision="1" node="a98683e6a8340830a7683909768b62871e84bc9d">
+  |  <tag>tip</tag>
+  ~  <author email="test">test</author>
+     <date>1970-01-01T00:00:00+00:00</date>
+     <msg xml:space="preserve">modify a</msg>
+     </logentry>
+      a |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      1 files changed, 300 insertions(+), 0 deletions(-)
+  
+  </log>
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,7 @@ 
     def _show(self, ctx, copies, props):
         '''show a single changeset or file revision'''
         changenode = ctx.node()
+        graphwidth = props.get('graphwidth', 0)
 
         if self.ui.quiet:
             self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
@@ -285,7 +287,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 +306,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")
 
@@ -433,6 +437,7 @@ 
         props['ctx'] = ctx
         props['index'] = index = next(self._counter)
         props['revcache'] = {'copies': copies}
+        graphwidth = props.get('graphwidth', 0)
 
         # write separator, which wouldn't work well with the header part below
         # since there's inherently a conflict between header (across items) and
@@ -453,7 +458,7 @@ 
         # write changeset metadata, then patch if requested
         key = self._parts[self._tref]
         self.ui.write(self.t.render(key, props))
-        self._showpatch(ctx)
+        self._showpatch(ctx, graphwidth)
 
         if self._parts['footer']:
             if not self.footer: