[PATCH 1 of 2 V2] upgrade-repo: colorize some of the output

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Dec 2 05:50:18 EST 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1575038205 -3600
#      Fri Nov 29 15:36:45 2019 +0100
# Node ID eb24da344625c3c7c34ff71abce165889de3cc2f
# Parent  aef7b91dba51b5f3fad8cf675e0b51b35d0fd5bb
# EXP-Topic sidedata-copies-perf
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r eb24da344625
upgrade-repo: colorize some of the output

Having clear color for requirement added and removed is useful.

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -145,6 +145,9 @@ except ImportError:
     b'status.unknown': b'magenta bold underline',
     b'tags.normal': b'green',
     b'tags.local': b'black bold',
+    b'upgrade-repo.requirement.preserved': b'cyan',
+    b'upgrade-repo.requirement.added': b'green',
+    b'upgrade-repo.requirement.removed': b'red',
 }
 
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -1242,25 +1242,31 @@ def upgraderepo(
             ui.warn(msg % b', '.join(sorted(incompatible)))
             revlogs = UPGRADE_ALL_REVLOGS
 
+    def write_labeled(l, label):
+        first = True
+        for r in sorted(l):
+            if not first:
+                ui.write(', ')
+            ui.write(r, label=label)
+            first = False
+
     def printrequirements():
         ui.write(_(b'requirements\n'))
-        ui.write(
-            _(b'   preserved: %s\n')
-            % _(b', ').join(sorted(newreqs & repo.requirements))
+        ui.write(_(b'   preserved: '))
+        write_labeled(
+            newreqs & repo.requirements, "upgrade-repo.requirement.preserved"
         )
-
+        ui.write(('\n'))
+        removed = repo.requirements - newreqs
         if repo.requirements - newreqs:
-            ui.write(
-                _(b'   removed: %s\n')
-                % _(b', ').join(sorted(repo.requirements - newreqs))
-            )
-
-        if newreqs - repo.requirements:
-            ui.write(
-                _(b'   added: %s\n')
-                % _(b', ').join(sorted(newreqs - repo.requirements))
-            )
-
+            ui.write(_(b'   removed: '))
+            write_labeled(removed, "upgrade-repo.requirement.removed")
+            ui.write(('\n'))
+        added = newreqs - repo.requirements
+        if added:
+            ui.write(_(b'   added: '))
+            write_labeled(added, "upgrade-repo.requirement.added")
+            ui.write(('\n'))
         ui.write(b'\n')
 
     def printupgradeactions():


More information about the Mercurial-devel mailing list