Patchwork [6,of,6,RFC] color: add special case handling for default template labels

login
register
mail settings
Submitter Sean Farley
Date Dec. 24, 2012, 7:03 a.m.
Message ID <eea4451a32d34299a8a4.1356332593@laptop.local>
Download mbox | patch
Permalink /patch/295/
State Superseded
Headers show

Comments

Sean Farley - Dec. 24, 2012, 7:03 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1356329669 21600
# Node ID eea4451a32d34299a8a4107d1a1ea0c977848858
# Parent  414aafdbce3cffe24b69d652055f443d9cad9f68
color: add special case handling for default template labels

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -404,10 +404,26 @@ 
     thing = templater.stringify(thing)
 
     sym = extractsymbol(templater._flatten(args[0]))
     default_label = _labels.get(sym, '')
 
+    # special case handling
+    if 'changeset' in default_label and thing in repo:
+        default_label += ' changeset.' + repo[thing].phasestr()
+
+    if 'file' in default_label:
+        ctx, revcache = mapping['ctx'], mapping['revcache']
+        if 'files' not in revcache:
+            revcache['files'] = repo.status(ctx.p1().node(), ctx.node())[:3]
+
+        if thing in revcache['files'][0]:
+            default_label += ' status.modified'
+        elif thing in revcache['files'][1]:
+            default_label += ' status.added'
+        elif thing in revcache['files'][2]:
+            default_label += ' status.removed'
+
     if default_label:
         label = default_label + ' ' + label
 
     return repo.ui.label(thing, label)