diff hgext/record.py @ 10825:781689b9b6bb

record: make use of output labeling
author Brodie Rao <brodie@bitheap.org>
date Fri, 02 Apr 2010 15:22:15 -0500
parents d7732d2df54a
children 301633755dec
line wrap: on
line diff
--- a/hgext/record.py	Fri Apr 02 15:22:14 2010 -0500
+++ b/hgext/record.py	Fri Apr 02 15:22:15 2010 -0500
@@ -520,7 +520,18 @@
                 os.rmdir(backupdir)
             except OSError:
                 pass
-    return cmdutil.commit(ui, repo, recordfunc, pats, opts)
+
+    # wrap ui.write so diff output can be labeled/colorized
+    def wrapwrite(orig, *args, **kw):
+        label = kw.pop('label', '')
+        for chunk, l in patch.difflabel(lambda: args):
+            orig(chunk, label=label + l)
+    oldwrite = ui.write
+    extensions.wrapfunction(ui, 'write', wrapwrite)
+    try:
+        return cmdutil.commit(ui, repo, recordfunc, pats, opts)
+    finally:
+        ui.write = oldwrite
 
 cmdtable = {
     "record":