# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1600900575 25200
#      Wed Sep 23 15:36:15 2020 -0700
# Branch stable
# Node ID 5ed6efedc457b03eb1abf472aeefb589351ca863
# Parent  5a555d6e0d9090d7751829e86678244367eaabbc
repoview: don't crash if mergestate points to non-existent node

Differential Revision: https://phab.mercurial-scm.org/D9078

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -70,8 +70,10 @@
 
     ms = mergestate.mergestate.read(repo)
     if ms.active():
-        pinned.add(ms.localctx.rev())
-        pinned.add(ms.otherctx.rev())
+        for node in (ms.local, ms.other):
+            rev = cl.index.get_rev(node)
+            if rev is not None:
+                pinned.add(rev)
 
     return pinned
 
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1826,8 +1826,8 @@
     ancestor path: file (node bc7ebe2d260cff30d2a39a130d84add36216f791)
     other path: file (node b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3)
     extra: ancestorlinknode = b73b8c9a4ab4da89a5a35a6f10dfb13edc84ca37
-BROKEN: We should be able to see the log (without the deleted commit, of course)
+We should be able to see the log (without the deleted commit, of course)
   $ hg log -G
-  abort: unknown revision 'b73b8c9a4ab4da89a5a35a6f10dfb13edc84ca37'!
-  [255]
+  @  0:f53e9479dce5 (draft) [tip ] first
+  
   $ cd ..