Patchwork filemerge: store error messages in module variables

login
register
mail settings
Submitter Stanislau Hlebik
Date May 18, 2017, 4:49 p.m.
Message ID <a1bf790daa1dcaf534c7.1495126151@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/20675/
State Superseded
Headers show

Comments

Stanislau Hlebik - May 18, 2017, 4:49 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1495125989 25200
#      Thu May 18 09:46:29 2017 -0700
# Node ID a1bf790daa1dcaf534c766b961951947d69938ae
# Parent  8a87bfc5bebbbe0ac996ac8e047a029eb931af45
filemerge: store error messages in module variables

Copytracing may be disabled because it's too slow (see
experimental.disablecopytrace config option). In that case user may get errors
like 'local changed FILE which other deleted'. It would be nice to give user a
hint to rerun command with `--config experimental.disablecopytrace=False`. To
make it possible let's extract error message to variables so that extension may
overwrite them.
Katsunori FUJIWARA - May 18, 2017, 7:36 p.m.
At Thu, 18 May 2017 09:49:11 -0700,
Stanislau Hlebik wrote:
> 
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1495125989 25200
> #      Thu May 18 09:46:29 2017 -0700
> # Node ID a1bf790daa1dcaf534c766b961951947d69938ae
> # Parent  8a87bfc5bebbbe0ac996ac8e047a029eb931af45
> filemerge: store error messages in module variables
> 
> Copytracing may be disabled because it's too slow (see
> experimental.disablecopytrace config option). In that case user may get errors
> like 'local changed FILE which other deleted'. It would be nice to give user a
> hint to rerun command with `--config experimental.disablecopytrace=False`. To
> make it possible let's extract error message to variables so that extension may
> overwrite them.
> 
> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
> --- a/mercurial/filemerge.py
> +++ b/mercurial/filemerge.py
> @@ -49,6 +49,17 @@
>  mergeonly = 'mergeonly'  # just the full merge, no premerge
>  fullmerge = 'fullmerge'  # both premerge and merge
>  
> +_localchangedotherdeletedmsg = (
> +    "local%(l)s changed %(fd)s which other%(o)s deleted\n"
> +    "use (c)hanged version, (d)elete, or leave (u)nresolved?"
> +    "$$ &Changed $$ &Delete $$ &Unresolved")
> +
> +_otherchangedlocaldeletedmsg = (
> +    "other%(o)s changed %(fd)s which local%(l)s deleted\n"
> +    "use (c)hanged version, leave (d)eleted, or "
> +    "leave (u)nresolved?"
> +    "$$ &Changed $$ &Deleted $$ &Unresolved")
> +
>  class absentfilectx(object):
>      """Represents a file that's ostensibly in a context but is actually not
>      present in it.
> @@ -250,16 +261,11 @@
>      try:
>          if fco.isabsent():
>              index = ui.promptchoice(
> -                _("local%(l)s changed %(fd)s which other%(o)s deleted\n"
> -                  "use (c)hanged version, (d)elete, or leave (u)nresolved?"
> -                  "$$ &Changed $$ &Delete $$ &Unresolved") % prompts, 2)
> +                _(_localchangedotherdeletedmsg) % prompts, 2)
>              choice = ['local', 'other', 'unresolved'][index]
>          elif fcd.isabsent():
>              index = ui.promptchoice(
> -                _("other%(o)s changed %(fd)s which local%(l)s deleted\n"
> -                  "use (c)hanged version, leave (d)eleted, or "
> -                  "leave (u)nresolved?"
> -                  "$$ &Changed $$ &Deleted $$ &Unresolved") % prompts, 2)
> +                _(_otherchangedlocaldeletedmsg) % prompts, 2)
>              choice = ['other', 'local', 'unresolved'][index]

These messages aren't translated at runtime, even though "_()" is
applied on actual messages at runtime, because xgettext picks up only
static string literals, on which "_()" is directly applied.

Of course, these messages are translated in cases below, but we
shouldn't expect such "accidental" cases.

  - *.po file contains corresponded message entries, because it isn't
    updated by recent source

  - there is another code path, in which "_()" is applied on same
    message string literal

Please refer to similar module variables defined in crecord.py and
wireporot.py.

  https://www.mercurial-scm.org/repo/hg/file/4.2/mercurial/crecord.py#l33
  https://www.mercurial-scm.org/repo/hg/file/4.2/mercurial/wireproto.py#l37


>          else:
>              index = ui.promptchoice(
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -49,6 +49,17 @@ 
 mergeonly = 'mergeonly'  # just the full merge, no premerge
 fullmerge = 'fullmerge'  # both premerge and merge
 
+_localchangedotherdeletedmsg = (
+    "local%(l)s changed %(fd)s which other%(o)s deleted\n"
+    "use (c)hanged version, (d)elete, or leave (u)nresolved?"
+    "$$ &Changed $$ &Delete $$ &Unresolved")
+
+_otherchangedlocaldeletedmsg = (
+    "other%(o)s changed %(fd)s which local%(l)s deleted\n"
+    "use (c)hanged version, leave (d)eleted, or "
+    "leave (u)nresolved?"
+    "$$ &Changed $$ &Deleted $$ &Unresolved")
+
 class absentfilectx(object):
     """Represents a file that's ostensibly in a context but is actually not
     present in it.
@@ -250,16 +261,11 @@ 
     try:
         if fco.isabsent():
             index = ui.promptchoice(
-                _("local%(l)s changed %(fd)s which other%(o)s deleted\n"
-                  "use (c)hanged version, (d)elete, or leave (u)nresolved?"
-                  "$$ &Changed $$ &Delete $$ &Unresolved") % prompts, 2)
+                _(_localchangedotherdeletedmsg) % prompts, 2)
             choice = ['local', 'other', 'unresolved'][index]
         elif fcd.isabsent():
             index = ui.promptchoice(
-                _("other%(o)s changed %(fd)s which local%(l)s deleted\n"
-                  "use (c)hanged version, leave (d)eleted, or "
-                  "leave (u)nresolved?"
-                  "$$ &Changed $$ &Deleted $$ &Unresolved") % prompts, 2)
+                _(_otherchangedlocaldeletedmsg) % prompts, 2)
             choice = ['other', 'local', 'unresolved'][index]
         else:
             index = ui.promptchoice(