This is an archive of the discontinued Mercurial Phabricator instance.

patch: do not cache translated messages (API)
ClosedPublic

Authored by quark on Oct 5 2017, 4:47 PM.

Details

Summary

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.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

quark created this revision.Oct 5 2017, 4:47 PM
quark edited the summary of this revision. (Show Details)Oct 5 2017, 6:41 PM
quark updated this revision to Diff 2491.
yuja requested changes to this revision.Oct 8 2017, 8:41 AM
yuja added a subscriber: yuja.

So the messages may be rolled back, which seems to be against the original
intent, "take messages out of the function so that extensions can add entries."

Since extensions have to wrap the _getmessages() function, the messages
table isn't necessary, so we don't need the callback mechanism, too.
Alternatively, the messages table could keep the raw (untranslated) messages,
to which gettext() will be applied later.

messages = {
    ...
        'discard': "discard change %d/%d to '%s'?",
}
i18nblahblah = messages.... # tell hggettext to extract strings

....
    i18n.gettext(messages[k][op])
This revision now requires changes to proceed.Oct 8 2017, 8:41 AM
quark edited the summary of this revision. (Show Details)Oct 9 2017, 4:40 PM
quark retitled this revision from patch: invalidate messages after encoding change to patch: do not cache translated messages (API).
quark updated this revision to Diff 2537.
yuja accepted this revision.Oct 10 2017, 9:50 AM
This revision is now accepted and ready to land.Oct 10 2017, 9:50 AM
This revision was automatically updated to reflect the committed changes.