mercurial/phases.py
changeset 44004 9c1fd975e9ac
parent 43730 d18cf63e1dbd
child 44064 8eb3c52337a6
--- a/mercurial/phases.py	Wed Dec 25 14:53:45 2019 +0100
+++ b/mercurial/phases.py	Thu Dec 19 00:32:42 2019 -0800
@@ -112,6 +112,7 @@
     nullid,
     nullrev,
     short,
+    wdirrev,
 )
 from .pycompat import (
     getattr,
@@ -242,6 +243,7 @@
         """return a smartset for the given phases"""
         self.loadphaserevs(repo)  # ensure phase's sets are loaded
         phases = set(phases)
+
         if public not in phases:
             # fast path: _phasesets contains the interesting sets,
             # might only need a union and post-filtering.
@@ -252,21 +254,39 @@
                 revs = set.union(*[self._phasesets[p] for p in phases])
             if repo.changelog.filteredrevs:
                 revs = revs - repo.changelog.filteredrevs
+
             if subset is None:
                 return smartset.baseset(revs)
             else:
+                if wdirrev in subset and repo[None].phase() in phases:
+                    # The working dir would never be in the cache, but it was
+                    # in the subset being filtered for its phase, so add it to
+                    # the output.
+                    revs.add(wdirrev)
+
                 return subset & smartset.baseset(revs)
         else:
+            # phases keeps all the *other* phases.
             phases = set(allphases).difference(phases)
             if not phases:
                 return smartset.fullreposet(repo)
+
+            # revs has the revisions in all *other* phases.
             if len(phases) == 1:
                 [p] = phases
                 revs = self._phasesets[p]
             else:
                 revs = set.union(*[self._phasesets[p] for p in phases])
+
             if subset is None:
                 subset = smartset.fullreposet(repo)
+
+            if wdirrev in subset and repo[None].phase() in phases:
+                # The working dir is in the subset being filtered, and its
+                # phase is in the phases *not* being returned, so add it to the
+                # set of revisions to filter out.
+                revs.add(wdirrev)
+
             if not revs:
                 return subset
             return subset.filter(lambda r: r not in revs)