[PATCH] color: allow multiple args to ui.write()

Kevin Bullock kbullock+mercurial at ringworld.org
Tue Sep 29 23:59:23 CDT 2009


Hello all--

The latest rev of the shelve extension throws an exception for me when  
I try to get help from the interactive shelve prompt ('?'). It only  
occurs when the color extension is enabled. The exception is:

TypeError: colorwrap() takes exactly 2 arguments (3 given)

The problem stems from this line in hgshelve.py:

320:                     if l: ui.write(_(l.strip()), '\n')

hgshelve calls ui.write() with multiple arguments, which is fine for  
the non-wrapped implementation. The color extension, however, wraps  
ui.write() with a function with the following signature:

def colorwrap(orig, s):

No *args paramater to this function makes hgshelve explode as described.

So here's a patch to make colorwrap() accept multiple arguments. As  
implemented, it only colorizes the first argument; I'm not sure that's  
the right way to do it and would welcome feedback.

Pacem in terris / Mir / Shanti / Salaam / Heiwa
Kevin R. Bullock


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1254286182 18000
# Node ID 2f3b58a20333d575acebdf28201d6a72624ba41b
# Parent  7f691058d62965f55051f2a2b253d094a721f1ac
color: allow multiple args to ui.write()

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -163,7 +163,7 @@
                     'missing': ['red', 'bold'],
                     'unapplied': ['black', 'bold'], }

-def colorwrap(orig, s):
+def colorwrap(orig, s, *args):
      '''wrap ui.write for colored diff output'''
      lines = s.split('\n')
      for i, line in enumerate(lines):
@@ -178,7 +178,7 @@
          if line != stripline:
              lines[i] += render_effects(
                  line[len(stripline):], _diff_effects 
['trailingwhitespace'])
-    orig('\n'.join(lines))
+    orig('\n'.join(lines), *args)

  def colorshowpatch(orig, self, node):
      '''wrap cmdutil.changeset_printer.showpatch with colored output'''



More information about the Mercurial-devel mailing list