[PATCH 2 of 2] changeset templater: ability to display diffstat
Alexander Solovyov
piranha at piranha.org.ua
Fri Mar 20 19:31:56 UTC 2009
# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1231871526 -7200
# Node ID 470c00359cdb00b4ac5e47fd577bcfa689357bbb
# Parent e2c3a2126a3d5867f52c90d63125e0b807d75d17
changeset templater: ability to display diffstat
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -828,6 +828,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,
@@ -844,6 +853,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
@@ -286,6 +286,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 with the following 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
@@ -2018,3 +2018,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