Patchwork [V3] subrepo: make the 'in subrepo' error string easier to find by external tools

login
register
mail settings
Submitter Angel Ezquerra
Date Jan. 9, 2013, 11:45 p.m.
Message ID <6be966cc3c4a8254214c.1357775126@Angel-PC.localdomain>
Download mbox | patch
Permalink /patch/516/
State Accepted
Delegated to: Bryan O'Sullivan
Headers show

Comments

Angel Ezquerra - Jan. 9, 2013, 11:45 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1357231345 -3600
# Node ID 6be966cc3c4a8254214c88aca1badf8e17dd0dca
# Parent  5a1a5555319c13de73e51d271de5356b4a0656d0
subrepo: make the 'in subrepo' error string easier to find by external tools

This patch is meant to make it easier for tools that wrap the mercurial
output (such as TortoiseHg) to find the "in subrepo MYSUBREPO" string that
(since 9e3910db4e78) is appended after subrepo error messages, particularly when
the mercurial output is translated to a non-English language.

The message remains the same but the '%s' that was used to prepend the original
error message in front of the 'in subrepo' string has been moved out of the
translatable string.

As an example of the usefulness of making it easy to look for "in subrepo
MYSUBREPO" strings, TortoiseHg looks for these strings in error messages in
order to "linkify them" (i.e. convert "MYSUBREPO" into alink to the
corresponding subrepo).

The original string made it hard for a tool such as TortoiseHg to look for the
translated string on mercurial's output because the translated string contained
the error message itself. This meant that a regular expression was required to
ignore the error message part. With this change TortoiseHg can just get the
translated "(in subrepo %s)" string, substitute %s for the subrepo path (which
it gets from the subrepo exception) and simply search for the resulting string
(no regular expression needed, or at least a much simpler regular expression
could be used).

Additionaly, the existing string could lead a translator mistakenly assume that
it was possible invert the order of the %s (error and subrepo path) fields,
which would not work because the string interpolation was position based.
Bryan O'Sullivan - Jan. 10, 2013, 10:13 p.m.
On Wed, Jan 9, 2013 at 3:45 PM, Angel Ezquerra <angel.ezquerra@gmail.com>wrote:

> subrepo: make the 'in subrepo' error string easier to find by external
> tools
>

Pushed to crew, thanks.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -29,7 +29,7 @@ 
             raise ex
         except error.Abort, ex:
             subrepo = subrelpath(self)
-            errormsg = _('%s (in subrepo %s)') % (str(ex), subrepo)
+            errormsg = str(ex) + ' ' + _('(in subrepo %s)') % subrepo
             # avoid handling this exception by raising a SubrepoAbort exception
             raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo)
         return res