Patchwork hidden: extract the code generating "filtered rev" error for wrapping

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2017, 12:28 a.m.
Message ID <95ca6e6b947fcdfd7ce2.1492302495@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20233/
State Accepted
Headers show

Comments

Pierre-Yves David - April 16, 2017, 12:28 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1492272790 -7200
#      Sat Apr 15 18:13:10 2017 +0200
# Node ID 95ca6e6b947fcdfd7ce2daef2de3d13f73aa3f59
# Parent  2bf73e351eb1bb086e30c9f58543817fb05e558c
# EXP-Topic filtererror
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 95ca6e6b947f
hidden: extract the code generating "filtered rev" error for wrapping

The goal is to help experimentation in extensions (ie: evolve) around more
advance messages.
Jun Wu - April 16, 2017, 12:44 a.m.
This change looks good to me.

Excerpts from Pierre-Yves David's message of 2017-04-16 02:28:15 +0200:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1492272790 -7200
> #      Sat Apr 15 18:13:10 2017 +0200
> # Node ID 95ca6e6b947fcdfd7ce2daef2de3d13f73aa3f59
> # Parent  2bf73e351eb1bb086e30c9f58543817fb05e558c
> # EXP-Topic filtererror
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ 
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/  -r 95ca6e6b947f
> hidden: extract the code generating "filtered rev" error for wrapping
> 
> The goal is to help experimentation in extensions (ie: evolve) around more
> advance messages.
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -407,6 +407,19 @@ def makememctx(repo, parents, text, user
>                   date, extra, editor)
>      return ctx
>  
> +def _filterederror(repo, changeid):
> +    """build an exception to be raised about a filtered changeid
> +
> +    This is extracted in a function to help extensions (eg: evolve) to
> +    experiment with various message variants."""
> +    if repo.filtername.startswith('visible'):
> +        msg = _("hidden revision '%s'") % changeid
> +        hint = _('use --hidden to access hidden revisions')
> +        return error.FilteredRepoLookupError(msg, hint=hint)
> +    msg = _("filtered revision '%s' (not in '%s' subset)")
> +    msg %= (changeid, repo.filtername)
> +    return error.FilteredRepoLookupError(msg)
> +
>  class changectx(basectx):
>      """A changecontext object makes access to data related to a particular
>      changeset convenient. It represents a read-only context already present in
> @@ -513,13 +526,7 @@ class changectx(basectx):
>                  pass
>          except (error.FilteredIndexError, error.FilteredLookupError,
>                  error.FilteredRepoLookupError):
> -            if repo.filtername.startswith('visible'):
> -                msg = _("hidden revision '%s'") % changeid
> -                hint = _('use --hidden to access hidden revisions')
> -                raise error.FilteredRepoLookupError(msg, hint=hint)
> -            msg = _("filtered revision '%s' (not in '%s' subset)")
> -            msg %= (changeid, repo.filtername)
> -            raise error.FilteredRepoLookupError(msg)
> +            raise _filterederror(repo, changeid)
>          except IndexError:
>              pass
>          raise error.RepoLookupError(
Yuya Nishihara - April 16, 2017, 10:21 a.m.
On Sat, 15 Apr 2017 17:44:22 -0700, Jun Wu wrote:
> This change looks good to me.
> 
> Excerpts from Pierre-Yves David's message of 2017-04-16 02:28:15 +0200:
> > # HG changeset patch
> > # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> > # Date 1492272790 -7200
> > #      Sat Apr 15 18:13:10 2017 +0200
> > # Node ID 95ca6e6b947fcdfd7ce2daef2de3d13f73aa3f59
> > # Parent  2bf73e351eb1bb086e30c9f58543817fb05e558c
> > # EXP-Topic filtererror
> > # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ 
> > #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/  -r 95ca6e6b947f
> > hidden: extract the code generating "filtered rev" error for wrapping
> > 
> > The goal is to help experimentation in extensions (ie: evolve) around more
> > advance messages.

Sure, queued, thanks.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -407,6 +407,19 @@  def makememctx(repo, parents, text, user
                  date, extra, editor)
     return ctx
 
+def _filterederror(repo, changeid):
+    """build an exception to be raised about a filtered changeid
+
+    This is extracted in a function to help extensions (eg: evolve) to
+    experiment with various message variants."""
+    if repo.filtername.startswith('visible'):
+        msg = _("hidden revision '%s'") % changeid
+        hint = _('use --hidden to access hidden revisions')
+        return error.FilteredRepoLookupError(msg, hint=hint)
+    msg = _("filtered revision '%s' (not in '%s' subset)")
+    msg %= (changeid, repo.filtername)
+    return error.FilteredRepoLookupError(msg)
+
 class changectx(basectx):
     """A changecontext object makes access to data related to a particular
     changeset convenient. It represents a read-only context already present in
@@ -513,13 +526,7 @@  class changectx(basectx):
                 pass
         except (error.FilteredIndexError, error.FilteredLookupError,
                 error.FilteredRepoLookupError):
-            if repo.filtername.startswith('visible'):
-                msg = _("hidden revision '%s'") % changeid
-                hint = _('use --hidden to access hidden revisions')
-                raise error.FilteredRepoLookupError(msg, hint=hint)
-            msg = _("filtered revision '%s' (not in '%s' subset)")
-            msg %= (changeid, repo.filtername)
-            raise error.FilteredRepoLookupError(msg)
+            raise _filterederror(repo, changeid)
         except IndexError:
             pass
         raise error.RepoLookupError(