D7705: phases: make the working directory consistently a draft

rdamazio (Rodrigo Damazio Bovendorp) phabricator at mercurial-scm.org
Thu Dec 19 03:34:46 EST 2019


rdamazio created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Before this change, `hg log -r 'wdir() and public()'` would return it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7705

AFFECTED FILES
  mercurial/phases.py
  tests/test-phases.t

CHANGE DETAILS

diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -48,6 +48,15 @@
   1 1 B
   0 1 A
 
+Working directory is a draft.
+
+  $ hg log -r 'wdir()' -T '{phase}\n'
+  draft
+  $ hg log -r 'wdir() and public()' -T '{phase}\n'
+  $ hg log -r 'wdir() and draft()' -T '{phase}\n'
+  draft
+  $ hg log -r 'wdir() and secret()' -T '{phase}\n'
+
 Draft commit are properly created over public one:
 
   $ hg phase --public .
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -112,6 +112,7 @@
     nullid,
     nullrev,
     short,
+    wdirrev,
 )
 from .pycompat import (
     getattr,
@@ -252,25 +253,43 @@
                 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 draft in phases:
+                    # The working dir would never be in the cache, but it should
+                    # be considered a draft - if it's in the subset being
+                    # filtered for drafts, 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 not revs:
                 return subset
+            if wdirrev in subset and draft in phases:
+                # The working dir is in the subset being filtered, and draft is
+                # in the phases *not* being returned, so add it to the set of
+                # revisions to filter out.
+                revs.add(wdirrev)
+
             return subset.filter(lambda r: r not in revs)
 
+
     def copy(self):
         # Shallow copy meant to ensure isolation in
         # advance/retractboundary(), nothing more.



To: rdamazio, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list