changeset 34566:60213a2eca81

patch: do not cache translated messages (API) Previously the code caches `i18n._` results in module variables. That causes issues after an encoding change. Instead of invalidating them manually, we now just recalculate the translated messages every time `filterpatch` gets called. This makes test-commit-interactive.t pass regardless of whether chg or demandimport is used or not. .. api: `patch.messages` now lives in `patch.getmessages()`. Extensions adding new messages should now wrap the `patch.getmessages` method instead of changing `patch.messages` directly. Differential Revision: https://phab.mercurial-scm.org/D959
author Jun Wu <quark@fb.com>
date Thu, 05 Oct 2017 13:38:48 -0700
parents 4aa57627692a
children 1b261be2033b
files mercurial/patch.py
diffstat 1 files changed, 46 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Mon Oct 09 10:09:36 2017 -0700
+++ b/mercurial/patch.py	Thu Oct 05 13:38:48 2017 -0700
@@ -994,53 +994,56 @@
     def __repr__(self):
         return '<hunk %r@%d>' % (self.filename(), self.fromline)
 
-messages = {
-    'multiple': {
-        'discard': _("discard change %d/%d to '%s'?"),
-        'record': _("record change %d/%d to '%s'?"),
-        'revert': _("revert change %d/%d to '%s'?"),
-    },
-    'single': {
-        'discard': _("discard this change to '%s'?"),
-        'record': _("record this change to '%s'?"),
-        'revert': _("revert this change to '%s'?"),
-    },
-    'help': {
-        'discard': _('[Ynesfdaq?]'
-                     '$$ &Yes, discard this change'
-                     '$$ &No, skip this change'
-                     '$$ &Edit this change manually'
-                     '$$ &Skip remaining changes to this file'
-                     '$$ Discard remaining changes to this &file'
-                     '$$ &Done, skip remaining changes and files'
-                     '$$ Discard &all changes to all remaining files'
-                     '$$ &Quit, discarding no changes'
-                     '$$ &? (display help)'),
-        'record': _('[Ynesfdaq?]'
-                    '$$ &Yes, record this change'
-                    '$$ &No, skip this change'
-                    '$$ &Edit this change manually'
-                    '$$ &Skip remaining changes to this file'
-                    '$$ Record remaining changes to this &file'
-                    '$$ &Done, skip remaining changes and files'
-                    '$$ Record &all changes to all remaining files'
-                    '$$ &Quit, recording no changes'
-                    '$$ &? (display help)'),
-        'revert': _('[Ynesfdaq?]'
-                    '$$ &Yes, revert this change'
-                    '$$ &No, skip this change'
-                    '$$ &Edit this change manually'
-                    '$$ &Skip remaining changes to this file'
-                    '$$ Revert remaining changes to this &file'
-                    '$$ &Done, skip remaining changes and files'
-                    '$$ Revert &all changes to all remaining files'
-                    '$$ &Quit, reverting no changes'
-                    '$$ &? (display help)')
+def getmessages():
+    return {
+        'multiple': {
+            'discard': _("discard change %d/%d to '%s'?"),
+            'record': _("record change %d/%d to '%s'?"),
+            'revert': _("revert change %d/%d to '%s'?"),
+        },
+        'single': {
+            'discard': _("discard this change to '%s'?"),
+            'record': _("record this change to '%s'?"),
+            'revert': _("revert this change to '%s'?"),
+        },
+        'help': {
+            'discard': _('[Ynesfdaq?]'
+                         '$$ &Yes, discard this change'
+                         '$$ &No, skip this change'
+                         '$$ &Edit this change manually'
+                         '$$ &Skip remaining changes to this file'
+                         '$$ Discard remaining changes to this &file'
+                         '$$ &Done, skip remaining changes and files'
+                         '$$ Discard &all changes to all remaining files'
+                         '$$ &Quit, discarding no changes'
+                         '$$ &? (display help)'),
+            'record': _('[Ynesfdaq?]'
+                        '$$ &Yes, record this change'
+                        '$$ &No, skip this change'
+                        '$$ &Edit this change manually'
+                        '$$ &Skip remaining changes to this file'
+                        '$$ Record remaining changes to this &file'
+                        '$$ &Done, skip remaining changes and files'
+                        '$$ Record &all changes to all remaining files'
+                        '$$ &Quit, recording no changes'
+                        '$$ &? (display help)'),
+            'revert': _('[Ynesfdaq?]'
+                        '$$ &Yes, revert this change'
+                        '$$ &No, skip this change'
+                        '$$ &Edit this change manually'
+                        '$$ &Skip remaining changes to this file'
+                        '$$ Revert remaining changes to this &file'
+                        '$$ &Done, skip remaining changes and files'
+                        '$$ Revert &all changes to all remaining files'
+                        '$$ &Quit, reverting no changes'
+                        '$$ &? (display help)')
+        }
     }
-}
 
 def filterpatch(ui, headers, operation=None):
     """Interactively filter patch chunks into applied-only chunks"""
+    messages = getmessages()
+
     if operation is None:
         operation = 'record'