# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1603506008 14400
#      Fri Oct 23 22:20:08 2020 -0400
# Branch stable
# Node ID 341e014fe0fbcf50a244c4b644b27ed87643829f
# Parent  e0ad11ab80529b702afc901da0c3e5f7bf57df2b
repoview: only pin obsolete wdir parents while there are unresolved conflicts

I noticed after doing an update from an obsolete revision with a dirty wdir that
the obsolete commit stayed visible for no obvious reason.  It was decided in
85b03b1e4715 not to clear mergestate once all of the conflicts were resolved, in
order to allow re-resolving.  Since the point of pinning the obsolete parents
was to allow resolving in the first place (aaeccdb6e654), it makes sense to also
gate it on whether or not there are any remaining files to resolve.  This might
result in pinning again if files are marked unresolved again, but that seems
reasonable, given that it still solves the original issue.

Note that this isn't purely cosmetic- pushing with a pinned obsolete revision is
likely to cause complaints about pushing multiple heads or other unexpected
errors.  So the faster it comes out of that state, the better.

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

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -69,7 +69,7 @@
     from . import mergestate
 
     ms = mergestate.mergestate.read(repo)
-    if ms.active():
+    if ms.active() and ms.unresolvedcount():
         for node in (ms.local, ms.other):
             rev = cl.index.get_rev(node)
             if rev is not None:
diff --git a/tests/test-rebase-check-restore.t b/tests/test-rebase-check-restore.t
--- a/tests/test-rebase-check-restore.t
+++ b/tests/test-rebase-check-restore.t
@@ -176,6 +176,48 @@
   warning: conflicts while merging A! (edit, then use 'hg resolve --mark')
   [1]
 
+An unresolved conflict will pin the obsolete revision
+
+  $ hg log -G -Tcompact
+  %  5[tip]   071d07019675   1970-01-01 00:00 +0000   test
+  |    F
+  |
+  o  4   ae36e8e3dfd7   1970-01-01 00:00 +0000   test
+  |    E
+  |
+  o  3:0   46b37eabc604   1970-01-01 00:00 +0000   test
+  |    D
+  |
+  | @  2   965c486023db   1970-01-01 00:00 +0000   test
+  | |    C
+  | |
+  | o  1   27547f69f254   1970-01-01 00:00 +0000   test
+  |/     B
+  |
+  o  0   4a2df7238c3b   1970-01-01 00:00 +0000   test
+       A
+  
+
+But resolving the conflicts will unpin it
+
+  $ hg resolve -m A
+  (no more unresolved files)
+  $ hg log -G -Tcompact
+  o  4[tip]   ae36e8e3dfd7   1970-01-01 00:00 +0000   test
+  |    E
+  |
+  o  3:0   46b37eabc604   1970-01-01 00:00 +0000   test
+  |    D
+  |
+  | @  2   965c486023db   1970-01-01 00:00 +0000   test
+  | |    C
+  | |
+  | o  1   27547f69f254   1970-01-01 00:00 +0000   test
+  |/     B
+  |
+  o  0   4a2df7238c3b   1970-01-01 00:00 +0000   test
+       A
+  
   $ hg up -C -q .
 
   $ cd ..