diff --git a/mercurial/discovery.py b/mercurial/discovery.py
index b345f851d05621575052a8352fc50724616f59e8_bWVyY3VyaWFsL2Rpc2NvdmVyeS5weQ==..5a14f48d6b9a5822c8d6d1be66b904cc8788a107_bWVyY3VyaWFsL2Rpc2NvdmVyeS5weQ== 100644
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -124,8 +124,7 @@
                 missing.append(node)
         if excluded:
             # update missing heads
-            rset = repo.set('heads(%ln)', missing)
-            missingheads = [ctx.node() for ctx in rset]
+            missingheads = phases.newheads(repo, onlyheads, excluded)
         else:
             missingheads = onlyheads
         og.missingheads = missingheads