# HG changeset patch # User Alexander Solovyov # Date 1237801302 -3600 # Node ID 5c4026a289a4caef7f80e55613e093b06bb815c0 # Parent 8c09952cd39abdfe9ebd502f82f14a037d6b8424 templater: ability to display diffstat for log-like commands diff -r 8c09952cd39a -r 5c4026a289a4 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Mon Mar 23 13:15:57 2009 +0100 +++ b/mercurial/cmdutil.py Mon Mar 23 10:41:42 2009 +0100 @@ -830,6 +830,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, @@ -846,6 +855,7 @@ 'rev': ctx.rev(), 'tags': showtags, 'extras': showextras, + 'diffstat': showdiffstat, } props = props.copy() props.update(defprops) diff -r 8c09952cd39a -r 5c4026a289a4 mercurial/help.py --- a/mercurial/help.py Mon Mar 23 13:15:57 2009 +0100 +++ b/mercurial/help.py Mon Mar 23 10:41:42 2009 +0100 @@ -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 -r 8c09952cd39a -r 5c4026a289a4 mercurial/util.py --- a/mercurial/util.py Mon Mar 23 13:15:57 2009 +0100 +++ b/mercurial/util.py Mon Mar 23 10:41:42 2009 +0100 @@ -2017,3 +2017,8 @@ except ImportError: pass return 80 + +def iterlines(iterator): + for chunk in iterator: + for line in chunk.splitlines(): + yield line diff -r 8c09952cd39a -r 5c4026a289a4 tests/test-command-template --- a/tests/test-command-template Mon Mar 23 13:15:57 2009 +0100 +++ b/tests/test-command-template Mon Mar 23 10:41:42 2009 +0100 @@ -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 -r 8c09952cd39a -r 5c4026a289a4 tests/test-command-template.out --- a/tests/test-command-template.out Mon Mar 23 13:15:57 2009 +0100 +++ b/tests/test-command-template.out Mon Mar 23 10:41:42 2009 +0100 @@ -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