context: rename troubles into instabilities
authorBoris Feld <boris.feld@octobus.net>
Wed, 02 Aug 2017 18:34:39 +0200
changeset 33726 ab0c55c2ad9a
parent 33725 86ea201eaeb9
child 33727 f163edb45c47
context: rename troubles into instabilities Rename troubles context method into instabilities. Copy the old troubles method and add a deprecation warning. This way extensions calling troubles will see the deprecation warning but will not break due to new return values. The renaming is done according to https://www.mercurial-scm.org/wiki/CEDVocabulary. Differential Revision: https://phab.mercurial-scm.org/D238
mercurial/cmdutil.py
mercurial/commands.py
mercurial/context.py
mercurial/exchange.py
mercurial/templatekw.py
--- a/mercurial/cmdutil.py	Tue Aug 08 17:25:38 2017 -0700
+++ b/mercurial/cmdutil.py	Wed Aug 02 18:34:39 2017 +0200
@@ -1466,8 +1466,8 @@
         labels.append('changeset.obsolete')
     if ctx.troubled():
         labels.append('changeset.troubled')
-        for trouble in ctx.troubles():
-            labels.append('trouble.%s' % trouble)
+        for instability in ctx.instabilities():
+            labels.append('trouble.%s' % instability)
     return ' '.join(labels)
 
 class changeset_printer(object):
@@ -1579,7 +1579,8 @@
 
         if ctx.troubled():
             # i18n: column positioning for "hg log"
-            self.ui.write(_("instability: %s\n") % ', '.join(ctx.troubles()),
+            instabilities = ctx.instabilities()
+            self.ui.write(_("instability: %s\n") % ', '.join(instabilities),
                           label='log.trouble')
 
         self._exthook(ctx)
--- a/mercurial/commands.py	Tue Aug 08 17:25:38 2017 -0700
+++ b/mercurial/commands.py	Wed Aug 02 18:34:39 2017 +0200
@@ -4850,9 +4850,10 @@
         if p.obsolete():
             ui.write(_(' (obsolete)'))
         if p.troubled():
+            instabilities = (ui.label(instability, 'trouble.%s' % instability)
+                             for instability in p.instabilities())
             ui.write(' ('
-                     + ', '.join(ui.label(trouble, 'trouble.%s' % trouble)
-                                 for trouble in p.troubles())
+                     + ', '.join(instabilities)
                      + ')')
         ui.write('\n')
         if p.description():
--- a/mercurial/context.py	Tue Aug 08 17:25:38 2017 -0700
+++ b/mercurial/context.py	Wed Aug 02 18:34:39 2017 +0200
@@ -226,21 +226,38 @@
         return self.unstable() or self.bumped() or self.divergent()
 
     def troubles(self):
-        """return the list of troubles affecting this changesets.
+        """Keep the old version around in order to avoid breaking extensions
+        about different return values.
+        """
+        msg = ("'context.troubles' is deprecated, "
+               "use 'context.instabilities'")
+        self._repo.ui.deprecwarn(msg, '4.4')
 
-        Troubles are returned as strings. possible values are:
+        troubles = []
+        if self.unstable():
+            troubles.append('orphan')
+        if self.bumped():
+            troubles.append('bumped')
+        if self.divergent():
+            troubles.append('divergent')
+        return troubles
+
+    def instabilities(self):
+        """return the list of instabilities affecting this changeset.
+
+        Instabilities are returned as strings. possible values are:
         - orphan,
         - phase-divergent,
         - content-divergent.
         """
-        troubles = []
+        instabilities = []
         if self.unstable():
-            troubles.append('orphan')
+            instabilities.append('orphan')
         if self.bumped():
-            troubles.append('phase-divergent')
+            instabilities.append('phase-divergent')
         if self.divergent():
-            troubles.append('content-divergent')
-        return troubles
+            instabilities.append('content-divergent')
+        return instabilities
 
     def parents(self):
         """return contexts for each parent changeset"""
--- a/mercurial/exchange.py	Tue Aug 08 17:25:38 2017 -0700
+++ b/mercurial/exchange.py	Wed Aug 02 18:34:39 2017 +0200
@@ -681,7 +681,9 @@
                 if ctx.obsolete():
                     raise error.Abort(mso % ctx)
                 elif ctx.troubled():
-                    raise error.Abort(mst[ctx.troubles()[0]] % ctx)
+                    # TODO print more than one instability in the abort
+                    # message
+                    raise error.Abort(mst[ctx.instabilities()[0]] % ctx)
 
         discovery.checkheads(pushop)
     return True
--- a/mercurial/templatekw.py	Tue Aug 08 17:25:38 2017 -0700
+++ b/mercurial/templatekw.py	Wed Aug 02 18:34:39 2017 +0200
@@ -783,7 +783,7 @@
     (EXPERIMENTAL)
     """
     args = pycompat.byteskwargs(args)
-    return showlist('trouble', args['ctx'].troubles(), args)
+    return showlist('trouble', args['ctx'].instabilities(), args)
 
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = keywords.values()