[PATCH 1 of 2] log: add --diffstat for diffstat output

Yuya Nishihara yuya at tcha.org
Wed Mar 31 10:38:03 CDT 2010


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1270049712 -32400
# Node ID bf6163e171310bab5eab6a1f562fb1eaae706e14
# Parent  3152f2732ef501fef5dbcbb46acaf528726e2cb9
log: add --diffstat for diffstat output

If --diffstat specified, log shows diffstat in place of patch output.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -807,12 +807,26 @@ class changeset_printer(object):
         self.showpatch(changenode)
 
     def showpatch(self, node):
+        def getdiffopts(diffopts, stat):
+            if stat:
+                diffopts = diffopts.copy()
+                diffopts['unified'] = '0'
+            return patch.diffopts(self.ui, diffopts)
+
         if self.patch:
+            stat = self.diffopts.get('diffstat')
+            diffopts = getdiffopts(self.diffopts, stat)
             prev = self.repo.changelog.parents(node)[0]
             chunks = patch.diff(self.repo, prev, node, match=self.patch,
-                                opts=patch.diffopts(self.ui, self.diffopts))
-            for chunk in chunks:
-                self.ui.write(chunk)
+                                opts=diffopts)
+            if stat:
+                width = self.ui.interactive() and util.termwidth() or 80
+                self.ui.write(patch.diffstat(util.iterlines(chunks),
+                                             width=width,
+                                             git=diffopts.git))
+            else:
+                for chunk in chunks:
+                    self.ui.write(chunk)
             self.ui.write("\n")
 
     def _meaningful_parentrevs(self, log, rev):
@@ -944,7 +958,7 @@ def show_changeset(ui, repo, opts, buffe
     """
     # options
     patch = False
-    if opts.get('patch'):
+    if opts.get('patch') or opts.get('diffstat'):
         patch = matchfn or matchall(repo)
 
     tmpl = opts.get('template')
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3433,6 +3433,7 @@ logopts = [
     ('g', 'git', None, _('use git extended diff format')),
     ('l', 'limit', '', _('limit number of changes displayed')),
     ('M', 'no-merges', None, _('do not show merges')),
+    ('', 'diffstat', None, _('output diffstat-style summary of changes')),
 ] + templateopts
 
 diffopts = [
diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out
--- a/tests/test-debugcomplete.out
+++ b/tests/test-debugcomplete.out
@@ -171,7 +171,7 @@ diff: rev, change, text, git, nodates, s
 export: output, switch-parent, rev, text, git, nodates
 forget: include, exclude
 init: ssh, remotecmd
-log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, prune, patch, git, limit, no-merges, style, template, include, exclude
+log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, prune, patch, git, limit, no-merges, diffstat, style, template, include, exclude
 merge: force, rev, preview
 pull: update, force, rev, branch, ssh, remotecmd
 push: force, rev, branch, ssh, remotecmd
@@ -210,10 +210,10 @@ heads: rev, topo, active, closed, style,
 help: 
 identify: rev, num, id, branch, tags
 import: strip, base, force, no-commit, exact, import-branch, message, logfile, date, user, similarity
-incoming: force, newest-first, bundle, rev, branch, patch, git, limit, no-merges, style, template, ssh, remotecmd
+incoming: force, newest-first, bundle, rev, branch, patch, git, limit, no-merges, diffstat, style, template, ssh, remotecmd
 locate: rev, print0, fullpath, include, exclude
 manifest: rev
-outgoing: force, rev, newest-first, branch, patch, git, limit, no-merges, style, template, ssh, remotecmd
+outgoing: force, rev, newest-first, branch, patch, git, limit, no-merges, diffstat, style, template, ssh, remotecmd
 parents: rev, style, template
 paths: 
 recover: 
diff --git a/tests/test-log b/tests/test-log
--- a/tests/test-log
+++ b/tests/test-log
@@ -118,6 +118,9 @@ hg log -k r1
 echo '% log -d -1'
 hg log -d -1
 
+echo '% log -r tip --diffstat'
+hg log -r tip --diffstat
+
 cd ..
 
 hg init usertest
diff --git a/tests/test-log.out b/tests/test-log.out
--- a/tests/test-log.out
+++ b/tests/test-log.out
@@ -279,6 +279,16 @@ date:        Thu Jan 01 00:00:01 1970 +0
 summary:     r1
 
 % log -d -1
+% log -r tip --diffstat
+changeset:   6:2404bbcab562
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     b1.1
+
+ b1 |  1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
 adding a
 adding b
 changeset:   0:29a4c94f1924


More information about the Mercurial-devel mailing list