diff --git a/hgext/churn.py b/hgext/churn.py --- a/hgext/churn.py +++ b/hgext/churn.py @@ -150,8 +150,10 @@ def churn(ui, repo, *pats, **opts): if opts.get('diffstat'): width -= 15 def format(name, (added, removed)): - return "%s %15s %s%s\n" % (pad(name, maxname), - '+%d/-%d' % (added, removed), + return "%s %15s %s%s\n" % (ui.label(pad(name, maxname), + 'ui.plain'), + ui.label('+%d/-%d' % (added, removed), + 'ui.plain'), ui.label('+' * charnum(added), 'diffstat.inserted'), ui.label('-' * charnum(removed), @@ -159,14 +161,14 @@ def churn(ui, repo, *pats, **opts): else: width -= 6 def format(name, count): - return "%s %6d %s\n" % (pad(name, maxname), sum(count), - '*' * charnum(sum(count))) + return ui.label("%s %6d %s\n" % (pad(name, maxname), sum(count), + '*' * charnum(sum(count))), 'ui.plain') def charnum(count): return int(round(count * width / maxcount)) for name, count in rate: - ui.write(format(name, count)) + ui.write(format(name, count), label='ui.labeled') cmdtable = { diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -108,7 +108,9 @@ from mercurial.i18n import _ 'status.ignored': 'black bold', 'status.modified': 'blue bold', 'status.removed': 'red bold', - 'status.unknown': 'magenta bold underline'} + 'status.unknown': 'magenta bold underline', + 'ui.labeled': 'none', + 'ui.plain': 'none'} def render_effects(text, effects): @@ -142,6 +144,8 @@ def configstyles(ui): _buffers = None def style(msg, label): + if label in ('ui.plain', 'ui.labeled'): + return msg effects = [] for l in label.split(): s = _styles.get(l, '') diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -2145,17 +2145,17 @@ def guard(ui, repo, *args, **opts): ''' def status(idx): guards = q.series_guards[idx] or ['unguarded'] - ui.write('%s: ' % ui.label(q.series[idx], 'qguard.patch')) + out = ['%s: ' % ui.label(q.series[idx], 'qguard.patch')] for i, guard in enumerate(guards): if guard.startswith('+'): - ui.write(guard, label='qguard.positive') + out.append(ui.label(guard, 'qguard.positive')) elif guard.startswith('-'): - ui.write(guard, label='qguard.negative') + out.append(ui.label(guard, 'qguard.negative')) else: - ui.write(guard, label='qguard.unguarded') + out.append(ui.label(guard, 'qguard.unguarded')) if i != len(guards) - 1: - ui.write(' ') - ui.write('\n') + out.append(ui.label(' ', 'ui.plain')) + ui.write(''.join(out) + '\n', label='ui.labeled') q = repo.mq patch = None args = list(args) @@ -2799,7 +2799,8 @@ def summary(orig, ui, repo, *args, **kwa if u: m.append(ui.label(_("%d unapplied"), 'qseries.unapplied') % u) if m: - ui.write("mq: %s\n" % ', '.join(m)) + ui.write("mq: ") + ui.write(', '.join(m) + '\n', label='ui.labeled') else: ui.note(_("mq: (empty queue)\n")) return r diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3280,22 +3280,22 @@ def summary(ui, repo, **opts): cleanworkdir = False if len(parents) > 1: - t += _(' (merge)') + t += ui.label(_(' (merge)'), 'ui.plain') elif branch != parents[0].branch(): - t += _(' (new branch)') + t += ui.label(_(' (new branch)'), 'ui.plain') elif (parents[0].extra().get('close') and pnode in repo.branchheads(branch, closed=True)): - t += _(' (head closed)') + t += ui.label(_(' (head closed)'), 'ui.plain') elif (not st[0] and not st[1] and not st[2] and not st[7]): - t += _(' (clean)') + t += ui.label(_(' (clean)'), 'ui.plain') cleanworkdir = True elif pnode not in bheads: - t += _(' (new branch head)') + t += ui.label(_(' (new branch head)'), 'ui.plain') if cleanworkdir: - ui.status(_('commit: %s\n') % t.strip()) + ui.status(_('commit: %s\n') % t.strip(), label='ui.labeled') else: - ui.write(_('commit: %s\n') % t.strip()) + ui.write(_('commit: %s\n') % t.strip(), label='ui.labeled') # all ancestors of branch heads - all ancestors of parent = new csets new = [0] * len(repo) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -546,5 +546,9 @@ class ui(object): ui.write(s, 'label') is equivalent to ui.write(ui.label(s, 'label')). + + Callers of ui.label() should pass labeled text back to + ui.write() with a label of 'ui.labeled' so implementations know + that the text has already been escaped and marked up. ''' return msg