Patchwork D3143: context: move handling of filtering error to revsymbol() (API)

login
register
mail settings
Submitter phabricator
Date April 6, 2018, 12:42 p.m.
Message ID <244695fcba28daaa08ac3e1a75451bfb@localhost.localdomain>
Download mbox | patch
Permalink /patch/30435/
State Not Applicable
Headers show

Comments

phabricator - April 6, 2018, 12:42 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGecd3f6909184: context: move handling of filtering error to revsymbol() (API) (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3143?vs=7754&id=7775

REVISION DETAIL
  https://phab.mercurial-scm.org/D3143

AFFECTED FILES
  mercurial/context.py
  mercurial/localrepo.py
  mercurial/scmutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -451,7 +451,36 @@ 
         msg = ("symbol (%s of type %s) was not a string, did you mean "
                "repo[symbol]?" % (symbol, type(symbol)))
         raise error.ProgrammingError(msg)
-    return repo[symbol]
+    try:
+        return repo[symbol]
+    except (error.FilteredIndexError, error.FilteredLookupError,
+            error.FilteredRepoLookupError):
+        raise _filterederror(repo, symbol)
+
+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'):
+
+        # Check if the changeset is obsolete
+        unfilteredrepo = repo.unfiltered()
+        ctx = revsymbol(unfilteredrepo, changeid)
+
+        # If the changeset is obsolete, enrich the message with the reason
+        # that made this changeset not visible
+        if ctx.obsolete():
+            msg = obsutil._getfilteredreason(repo, changeid, ctx)
+        else:
+            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)
 
 def revsingle(repo, revspec, default='.', localalias=None):
     if not revspec and revspec != 0:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -802,7 +802,8 @@ 
         try:
             self[changeid]
             return True
-        except error.RepoLookupError:
+        except (error.RepoLookupError, error.FilteredIndexError,
+                error.FilteredLookupError):
             return False
 
     def __nonzero__(self):
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -33,7 +33,6 @@ 
     fileset,
     match as matchmod,
     obsolete as obsmod,
-    obsutil,
     patch,
     pathutil,
     phases,
@@ -378,31 +377,6 @@ 
 
         return r
 
-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'):
-
-        # Check if the changeset is obsolete
-        unfilteredrepo = repo.unfiltered()
-        ctx = unfilteredrepo[changeid]
-
-        # If the changeset is obsolete, enrich the message with the reason
-        # that made this changeset not visible
-        if ctx.obsolete():
-            msg = obsutil._getfilteredreason(repo, changeid, ctx)
-        else:
-            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
@@ -501,7 +475,7 @@ 
                 pass
         except (error.FilteredIndexError, error.FilteredLookupError,
                 error.FilteredRepoLookupError):
-            raise _filterederror(repo, changeid)
+            raise
         except IndexError:
             pass
         raise error.RepoLookupError(