[PATCH 2 of 2] changeset templater: ability to display diffstat

Alexander Solovyov piranha at piranha.org.ua
Wed Feb 4 15:57:46 CST 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1231871526 -7200
# Node ID 53e36c83fdb777a7b0d24bc802ef6d82dd341221
# Parent  19a0120d6185e87f215a7c24f39f5c5b94897299
changeset templater: ability to display diffstat

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -827,6 +827,15 @@
                              node=hex(ctx.changeset()[0])))
             return self.t('manifest', **args)
 
+        def showdiffstat(**args):
+            diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node())
+            files, adds, removes = 0, 0, 0
+            for i in patch.diffstatdata(util.iterlines(diff)):
+                files += 1
+                adds += i[1]
+                removes += i[2]
+            return '%s: +%s/-%s' % (files, adds, removes)
+
         defprops = {
             'author': ctx.user(),
             'branches': showbranches,
@@ -843,6 +852,7 @@
             'rev': ctx.rev(),
             'tags': showtags,
             'extras': showextras,
+            'diffstat': showdiffstat,
             }
         props = props.copy()
         props.update(defprops)
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -276,6 +276,8 @@
           was committed. Will be empty if the branch name was default.
     - date: Date information. The date when the changeset was committed.
     - desc: String. The text of the changeset description.
+    - diffstat: String. Statistics of changes in format:
+          "modified files: +added/-removed lines"
     - files: List of strings. All files modified, added, or removed by
           this changeset.
     - file_adds: List of strings. Files added by this changeset.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2015,3 +2015,8 @@
     except ImportError:
         pass
     return 80
+
+def iterlines(iterator):
+    for chunk in iterator:
+        for line in chunk.splitlines():
+            yield line
diff --git a/tests/test-command-template b/tests/test-command-template
--- a/tests/test-command-template
+++ b/tests/test-command-template
@@ -93,7 +93,7 @@
 
 echo "# keys work"
 for key in author branches date desc file_adds file_dels file_mods \
-        files manifest node parents rev tags; do
+        files manifest node parents rev tags diffstat; do
     for mode in '' --verbose --debug; do
         hg log $mode --template "$key$mode: {$key}\n"
     done
diff --git a/tests/test-command-template.out b/tests/test-command-template.out
--- a/tests/test-command-template.out
+++ b/tests/test-command-template.out
@@ -534,6 +534,33 @@
 tags--debug: 
 tags--debug: 
 tags--debug: 
+diffstat: 1: +1/-0
+diffstat: 1: +1/-0
+diffstat: 0: +0/-0
+diffstat: 1: +1/-0
+diffstat: 0: +0/-0
+diffstat: 1: +1/-0
+diffstat: 1: +4/-0
+diffstat: 1: +2/-0
+diffstat: 1: +1/-0
+diffstat--verbose: 1: +1/-0
+diffstat--verbose: 1: +1/-0
+diffstat--verbose: 0: +0/-0
+diffstat--verbose: 1: +1/-0
+diffstat--verbose: 0: +0/-0
+diffstat--verbose: 1: +1/-0
+diffstat--verbose: 1: +4/-0
+diffstat--verbose: 1: +2/-0
+diffstat--verbose: 1: +1/-0
+diffstat--debug: 1: +1/-0
+diffstat--debug: 1: +1/-0
+diffstat--debug: 0: +0/-0
+diffstat--debug: 1: +1/-0
+diffstat--debug: 0: +0/-0
+diffstat--debug: 1: +1/-0
+diffstat--debug: 1: +4/-0
+diffstat--debug: 1: +2/-0
+diffstat--debug: 1: +1/-0
 # filters work
 
 hostname


More information about the Mercurial-devel mailing list