# HG changeset patch # User Brodie Rao # Date 1256431956 -7200 # Node ID 9b99f158348ade45066f613aa3ea03a6e7bc4e50 # Parent 9e76232fbfbe7118ef92c05b0d887171c88aa0bd color: colorize diff --stat diff -r 9e76232fbfbe -r 9b99f158348a hgext/color.py --- a/hgext/color.py Sun Oct 25 02:52:35 2009 +0200 +++ b/hgext/color.py Sun Oct 25 02:52:36 2009 +0200 @@ -189,9 +189,25 @@ finally: self.ui.write = oldwrite +def colordiffstat(orig, s): + lines = s.split('\n') + for i, line in enumerate(lines): + if line and line[-1] in '+-': + name, graph = line.rsplit(' ', 1) + graph = graph.replace('-', + render_effects('-', _diff_effects['deleted'])) + graph = graph.replace('+', + render_effects('+', _diff_effects['inserted'])) + lines[i] = ' '.join([name, graph]) + orig('\n'.join(lines)) + def colordiff(orig, ui, repo, *pats, **opts): '''run the diff command with colored output''' - oldwrite = extensions.wrapfunction(ui, 'write', colorwrap) + if opts.get('stat'): + wrapper = colordiffstat + else: + wrapper = colorwrap + oldwrite = extensions.wrapfunction(ui, 'write', wrapper) try: orig(ui, repo, *pats, **opts) finally: diff -r 9e76232fbfbe -r 9b99f158348a tests/test-diff-color --- a/tests/test-diff-color Sun Oct 25 02:52:35 2009 +0200 +++ b/tests/test-diff-color Sun Oct 25 02:52:36 2009 +0200 @@ -35,6 +35,9 @@ echo '% --unified=2' hg diff --nodates -U 2 --color=always +echo '% diffstat' +hg diff --stat --color=always + echo "record=" >> $HGRCPATH echo "[ui]" >> $HGRCPATH echo "interactive=true" >> $HGRCPATH diff -r 9e76232fbfbe -r 9b99f158348a tests/test-diff-color.out --- a/tests/test-diff-color.out Sun Oct 25 02:52:35 2009 +0200 +++ b/tests/test-diff-color.out Sun Oct 25 02:52:36 2009 +0200 @@ -23,6 +23,9 @@ +dd a a +% diffstat + a | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) % record diff --git a/a b/a old mode 100644