Mercurial > hg
changeset 7879:5c4026a289a4
templater: ability to display diffstat for log-like commands
author | Alexander Solovyov <piranha at piranha.org.ua> |
---|---|
date | Mon, 23 Mar 2009 10:41:42 +0100 |
parents | 8c09952cd39a |
children | 7ca2be800804 |
files | mercurial/cmdutil.py mercurial/help.py mercurial/util.py tests/test-command-template tests/test-command-template.out |
diffstat | 5 files changed, 45 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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.
--- 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
--- 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
--- 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