diff --git a/mercurial/revlog.py b/mercurial/revlog.py
index 19ac0d8ee9a20e76dc6b0e9d1f976c2996ba53a9_bWVyY3VyaWFsL3JldmxvZy5weQ==..fd1bb7c1be78d15a02761156bb1caaa3ccb304b6_bWVyY3VyaWFsL3JldmxvZy5weQ== 100644
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -751,6 +751,9 @@
 
     def _partialmatch(self, id):
         try:
-            return self.index.partialmatch(id)
+            n = self.index.partialmatch(id)
+            if n and self.hasnode(n):
+                return n
+            return None
         except RevlogError:
             # parsers.c radix tree lookup gave multiple matches
@@ -755,6 +758,7 @@
         except RevlogError:
             # parsers.c radix tree lookup gave multiple matches
-            raise LookupError(id, self.indexfile, _("ambiguous identifier"))
+            # fall through to slow path that filters hidden revisions
+            pass
         except (AttributeError, ValueError):
             # we are pure python, or key was too short to search radix tree
             pass
@@ -768,7 +772,8 @@
                 l = len(id) // 2  # grab an even number of digits
                 prefix = bin(id[:l * 2])
                 nl = [e[7] for e in self.index if e[7].startswith(prefix)]
-                nl = [n for n in nl if hex(n).startswith(id)]
+                nl = [n for n in nl if hex(n).startswith(id) and
+                      self.hasnode(n)]
                 if len(nl) > 0:
                     if len(nl) == 1:
                         self._pcache[id] = nl[0]
diff --git a/tests/test-log.t b/tests/test-log.t
index 19ac0d8ee9a20e76dc6b0e9d1f976c2996ba53a9_dGVzdHMvdGVzdC1sb2cudA==..fd1bb7c1be78d15a02761156bb1caaa3ccb304b6_dGVzdHMvdGVzdC1sb2cudA== 100644
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1223,6 +1223,9 @@
   $ hg log --template='{rev}:{node}\n' --hidden
   1:a765632148dc55d38c35c4f247c618701886cb2f
   0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05
+  $ hg log -r a
+  abort: unknown revision 'a'!
+  [255]
 
 test that parent prevent a changeset to be hidden