diff mercurial/phases.py @ 33043:e8c8d81eb864

bundle: add config option to include phases This adds an experimental.bundle-phases config option to include phase information in bundles. As with the recently added support for bundling obsmarkers, the support for bundling phases is hidden behind the config option until we decide to make a bundlespec v3 that includes phases (and obsmarkers and ...). We could perhaps use the listkeys format for this, but that's considered obsolete according to Pierre-Yves. Instead, we introduce a new "phase-heads" bundle part. The new part contains the phase heads among the set of bundled revisions. It does not include those in secret phase; any head in the bundle that is not mentioned in the phase-heads part is assumed to be secret. As a special case, an empty phase-heads part thus means that any changesets should be added in secret phase. (If we ever add a fourth phase, we'll include secret in the part and we'll add a version number.) For now, phases are only included by "hg bundle", and not by e.g. strip and rebase.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 22 Jun 2017 10:10:02 -0700
parents e65ff29dbeb0
children 50243c975fc2
line wrap: on
line diff
--- a/mercurial/phases.py	Fri Jun 16 16:56:16 2017 -0700
+++ b/mercurial/phases.py	Thu Jun 22 10:10:02 2017 -0700
@@ -430,6 +430,32 @@
         else:
             return False
 
+def subsetphaseheads(repo, subset):
+    """Finds the phase heads for a subset of a history
+
+    Returns a list indexed by phase number where each item is a list of phase
+    head nodes.
+    """
+    cl = repo.changelog
+
+    headsbyphase = [[] for i in allphases]
+    # No need to keep track of secret phase; any heads in the subset that
+    # are not mentioned are implicitly secret.
+    for phase in allphases[:-1]:
+        revset = "heads(%%ln & %s())" % phasenames[phase]
+        headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
+    return headsbyphase
+
+def updatephases(repo, tr, headsbyphase, addednodes):
+    """Updates the repo with the given phase heads"""
+    # First make all the added revisions secret because changegroup.apply()
+    # currently sets the phase to draft.
+    retractboundary(repo, tr, secret, addednodes)
+
+    # Now advance phase boundaries of all but secret phase
+    for phase in allphases[:-1]:
+        advanceboundary(repo, tr, phase, headsbyphase[phase])
+
 def analyzeremotephases(repo, subset, roots):
     """Compute phases heads and root in a subset of node from root dict