[PATCH 2 of 2] color: add diff highlighting support for commands with --patch argument

Georg Brandl georg at python.org
Sat Nov 22 13:26:23 CST 2008


# HG changeset patch
# User Georg Brandl <georg at python.org>
# Date 1227379971 -3600
# Node ID 7278621243705bb14203c7873af2f17338e1b36d
# Parent  39692450743df595714eb748f525db24ee6c1887
color: add diff highlighting support for commands with --patch argument

diff -r 39692450743d -r 727862124370 hgext/color.py
--- a/hgext/color.py	Sat Nov 22 19:31:05 2008 +0100
+++ b/hgext/color.py	Sat Nov 22 19:52:51 2008 +0100
@@ -149,11 +149,11 @@
                     'clean': ('none', ),
                     'copied': ('none', ), }
 
-def colordiff(orig, ui, repo, *pats, **opts):
-    '''run the diff command with colored output'''
+def _colordiff_inner(ui, orig, *args, **kwds):
+    '''run the diff command or showpath() with colored output'''
 
     ui.pushbuffer()
-    retval = orig(ui, repo, *pats, **opts)
+    retval = orig(*args, **kwds)
     lines = ui.popbuffer().splitlines()
     for line in lines:
         for prefix, style in _diff_prefixes:
@@ -165,6 +165,12 @@
         else:
             sys.stdout.write(line + '\n')
     return retval
+
+def colordiff(orig, ui, repo, *pats, **opts):
+    return _colordiff_inner(ui, orig, ui, repo, *pats, **opts)
+
+def showpatch_color(orig, self, node):
+    return _colordiff_inner(self.ui, orig, self, node)
 
 _diff_prefixes = [ ('diff', 'diffline'),
                    ('copy', 'extended'),
@@ -217,6 +223,8 @@
     '''Initialize the extension.'''
     _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
     _setupcmd(ui, 'diff', commands.table, colordiff, _diff_effects)
+    extensions.wrapfunction(cmdutil.changeset_printer,
+                            'showpatch', showpatch_color)
     if ui.config('extensions', 'hgext.mq') is not None or \
             ui.config('extensions', 'mq') is not None:
         from hgext import mq


More information about the Mercurial-devel mailing list