How to use the templater without color (even when ui has color)

Martin von Zweigbergk martinvonz at google.com
Fri Nov 13 17:20:24 UTC 2020


Hi Yuya,

I recently added support for some templated output in `hg split` (
https://phab.mercurial-scm.org/D9255). I didn't realize when I wrote the
patch that it was producing the templated output for use in a commit
message template. The effect was that color codes ended up in the commit
message template. How should I fix it? The following seems to fix it, but
maybe there's a cleaner way?

```
diff --git a/hgext/split.py b/hgext/split.py
--- a/hgext/split.py
+++ b/hgext/split.py
@@ -142,9 +142,13 @@ def dosplit(ui, repo, tr, ctx, opts):
             header = _(
                 b'HG: Splitting %s. So far it has been split into:\n'
             ) % short(ctx.node())
-            for c in committed:
-                summary = cmdutil.format_changeset_summary(ui, c, b'split')
-                header += _(b'HG: - %s\n') % summary
+            from mercurial import color
+            with ui.configoverride({(b'ui', b'color'): b"no"}, b'split'):
+                color.setup(ui)
+                for c in committed:
+                    summary = cmdutil.format_changeset_summary(ui, c,
b'split')
+                    header += _(b'HG: - %s\n') % summary
+            color.setup(ui)
             header += _(
                 b'HG: Write commit message for the next split changeset.\n'
             )
```


Btw, I noticed that Augie made the same mistake in histedit in
https://phab.mercurial-scm.org/D5742.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20201113/be621ab7/attachment.html>


More information about the Mercurial-devel mailing list