diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -830,6 +830,15 @@ class changeset_templater(changeset_prin 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, @@ -846,6 +855,7 @@ class changeset_templater(changeset_prin '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 @@ PYTHONPATH:: 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 @@ -2017,3 +2017,8 @@ def termwidth(): 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 @@ cat changelog 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: 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