Patchwork [STABLE] hgweb: show correct error message for i18n environment

login
register
mail settings
Submitter Takumi IINO
Date Feb. 17, 2013, 12:41 p.m.
Message ID <788242e9369672359cf6.1361104879@iino-no-MacBook-Air.local>
Download mbox | patch
Permalink /patch/1023/
State Accepted
Commit 50c922c1b5145dab8baefefb0437d363b6a6c21c
Headers show

Comments

Takumi IINO - Feb. 17, 2013, 12:41 p.m.
# HG changeset patch
# User Takumi IINO <trot.thunder@gmail.com>
# Date 1360919234 -32400
# Branch stable
# Node ID 788242e9369672359cf65a4fd111554674385351
# Parent  227479f61db9d169c1afea6fa0a9dce7288d4932
hgweb: show correct error message for i18n environment

If exception is error.LookupError and running in i18n environment,
below condition is always true.
Because msg is translated and dosen't contain 'manifest'.

    if util.safehasattr(err, 'name') and 'manifest' not in msg:

This patch creates a new exception class and uses it instead of
string match.
Matt Mackall - April 2, 2013, 5:10 a.m.
On Sun, 2013-02-17 at 21:41 +0900, Takumi IINO wrote:
> # HG changeset patch
> # User Takumi IINO <trot.thunder@gmail.com>
> # Date 1360919234 -32400
> # Branch stable
> # Node ID 788242e9369672359cf65a4fd111554674385351
> # Parent  227479f61db9d169c1afea6fa0a9dce7288d4932
> hgweb: show correct error message for i18n environment

Queued for stable, thanks.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -291,16 +291,16 @@ 
             try:
                 return self._manifest[path], self._manifest.flags(path)
             except KeyError:
-                raise error.LookupError(self._node, path,
-                                        _('not found in manifest'))
+                raise error.ManifestLookupError(self._node, path,
+                                                _('not found in manifest'))
         if '_manifestdelta' in self.__dict__ or path in self.files():
             if path in self._manifestdelta:
                 return (self._manifestdelta[path],
                         self._manifestdelta.flags(path))
         node, flag = self._repo.manifest.find(self._changeset[0], path)
         if not node:
-            raise error.LookupError(self._node, path,
-                                    _('not found in manifest'))
+            raise error.ManifestLookupError(self._node, path,
+                                            _('not found in manifest'))
 
         return node, flag
 
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -27,6 +27,9 @@ 
     def __str__(self):
         return RevlogError.__str__(self)
 
+class ManifestLookupError(LookupError):
+    pass
+
 class CommandError(Exception):
     """Exception raised on errors in parsing the command line."""
 
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -245,7 +245,8 @@ 
         except (error.LookupError, error.RepoLookupError), err:
             req.respond(HTTP_NOT_FOUND, ctype)
             msg = str(err)
-            if util.safehasattr(err, 'name') and 'manifest' not in msg:
+            if (util.safehasattr(err, 'name') and
+                not isinstance(err,  error.ManifestLookupError)):
                 msg = 'revision not found: %s' % err.name
             return tmpl('error', error=msg)
         except (error.RepoError, error.RevlogError), inst: