[PATCH] color: colorize output of hg resolve -l
Georg Brandl
georg at python.org
Thu Jan 7 12:57:39 CST 2010
# HG changeset patch
# User Georg Brandl <georg at python.org>
# Date 1262890269 -3600
# Node ID 0b8709b4296d5ed62c051be83c8da6c5b2af572c
# Parent 843f6ee6d14bf7ce2004cf3583ca67c75308f4bc
color: colorize output of hg resolve -l
diff -r 843f6ee6d14b -r 0b8709b4296d hgext/color.py
--- a/hgext/color.py Thu Jan 07 16:06:36 2010 +0100
+++ b/hgext/color.py Thu Jan 07 19:51:09 2010 +0100
@@ -18,8 +18,8 @@
'''colorize output from some commands
-This extension modifies the status command to add color to its output
-to reflect file status, the qseries command to add color to reflect
+This extension modifies the status and resolve commands to add color to their
+output to reflect file status, the qseries command to add color to reflect
patch status (applied, unapplied, missing), and to diff-related
commands to highlight additions, removals, diff headers, and trailing
whitespace.
@@ -57,6 +57,9 @@
diff.changed = white
diff.trailingwhitespace = bold red_background
+ resolve.unresolved = red bold
+ resolve.resolved = green bold
+
bookmarks.current = green
'''
@@ -95,18 +98,16 @@
stop = '\033[' + str(_effect_params['none']) + 'm'
return ''.join([start, text, stop])
-def colorstatus(orig, ui, repo, *pats, **opts):
- '''run the status command with colored output'''
-
- delimiter = opts['print0'] and '\0' or '\n'
+def _colorstatuslike(abbreviations, effectdefs, orig, ui, repo, *pats, **opts):
+ delimiter = opts.get('print0') and '\0' or '\n'
nostatus = opts.get('no_status')
opts['no_status'] = False
- # run status and capture its output
+ # run original command and capture its output
ui.pushbuffer()
retval = orig(ui, repo, *pats, **opts)
# filter out empty strings
- lines_with_status = [ line for line in ui.popbuffer().split(delimiter) if line ]
+ lines_with_status = [line for line in ui.popbuffer().split(delimiter) if line]
if nostatus:
lines = [l[2:] for l in lines_with_status]
@@ -115,13 +116,14 @@
# apply color to output and display it
for i in xrange(len(lines)):
- status = _status_abbreviations[lines_with_status[i][0]]
- effects = _status_effects[status]
+ status = abbreviations[lines_with_status[i][0]]
+ effects = effectdefs[status]
if effects:
lines[i] = render_effects(lines[i], effects)
ui.write(lines[i] + delimiter)
return retval
+
_status_abbreviations = { 'M': 'modified',
'A': 'added',
'R': 'removed',
@@ -140,6 +142,23 @@
'clean': ['none'],
'copied': ['none'], }
+def colorstatus(orig, ui, repo, *pats, **opts):
+ '''run the status command with colored output'''
+ return _colorstatuslike(_status_abbreviations, _status_effects,
+ orig, ui, repo, *pats, **opts)
+
+
+_resolve_abbreviations = { 'U': 'unresolved',
+ 'R': 'resolved', }
+
+_resolve_effects = { 'unresolved': ['red', 'bold'],
+ 'resolved': ['green', 'bold'], }
+
+def colorresolve(orig, ui, repo, *pats, **opts):
+ return _colorstatuslike(_resolve_abbreviations, _resolve_effects,
+ orig, ui, repo, *pats, **opts)
+
+
_bookmark_effects = { 'current': ['green'] }
def colorbookmarks(orig, ui, repo, *pats, **opts):
@@ -270,6 +289,7 @@
_setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
_setupcmd(ui, 'tip', commands.table, None, _diff_effects)
_setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
+ _setupcmd(ui, 'resolve', commands.table, colorresolve, _resolve_effects)
try:
mq = extensions.find('mq')
diff -r 843f6ee6d14b -r 0b8709b4296d tests/test-resolve-color
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-resolve-color Thu Jan 07 19:51:09 2010 +0100
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "color=" >> $HGRCPATH
+
+hg init repo1
+cd repo1
+echo "file a" > a
+echo "file b" > b
+hg add a b
+hg commit -m "initial"
+echo "file a change 1" > a
+echo "file b change 1" > b
+hg commit -m "head 1"
+hg update 0
+echo "file a change 2" > a
+echo "file b change 2" > b
+hg commit -m "head 2"
+hg merge
+hg resolve -m b
+echo "hg resolve with one unresolved, one resolved:"
+hg resolve --color=always -l
diff -r 843f6ee6d14b -r 0b8709b4296d tests/test-resolve-color.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-resolve-color.out Thu Jan 07 19:51:09 2010 +0100
@@ -0,0 +1,13 @@
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+merging a
+warning: conflicts during merge.
+merging a failed!
+merging b
+warning: conflicts during merge.
+merging b failed!
+0 files updated, 0 files merged, 0 files removed, 2 files unresolved
+use 'hg resolve' to retry unresolved file merges or 'hg update -C' to abandon
+hg resolve with one unresolved, one resolved:
+[0;31;1mU a[0m
+[0;32;1mR b[0m
More information about the Mercurial-devel
mailing list