# HG changeset patch # User Georg Brandl # Date 2010-01-09 09:47:47 # Node ID 51421ab573deb8a85085371f746fe64c565b8ad1 # Parent 98f630e15d8245b85e9bdd7addcc1a7e7e141f65 color: colorize output of hg resolve -l diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -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 @@ Default effects may be overridden from t diff.changed = white diff.trailingwhitespace = bold red_background + resolve.unresolved = red bold + resolve.resolved = green bold + bookmarks.current = green ''' @@ -95,14 +98,13 @@ def render_effects(text, effects): 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): + '''run a status-like command with colorized output''' + 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 @@ -115,13 +117,14 @@ def colorstatus(orig, ui, repo, *pats, * # 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 +143,27 @@ def colorstatus(orig, ui, repo, *pats, * '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): + '''run the resolve command with colored output''' + if not opts.get('list'): + # only colorize for resolve -l + return 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 +294,7 @@ def extsetup(ui): _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 --git a/tests/test-status-color b/tests/test-status-color --- a/tests/test-status-color +++ b/tests/test-status-color @@ -98,3 +98,23 @@ assert "-q" "-u" 1 assert "-m" "-a" 1 assert "-r" "-d" 1 +cd .. + +# test 'resolve -l' +hg init repo4 +cd repo4 +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 --git a/tests/test-status-color.out b/tests/test-status-color.out --- a/tests/test-status-color.out +++ b/tests/test-status-color.out @@ -132,3 +132,16 @@ M modified R removed ! deleted ? unknown +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: +U a +R b