record: make use of output labeling
authorBrodie Rao <brodie@bitheap.org>
Fri, 02 Apr 2010 15:22:15 -0500
changeset 10825 781689b9b6bb
parent 10824 18def0d5692d
child 10826 717c35d55fb3
record: make use of output labeling
hgext/record.py
--- 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":