[PATCH 17 of 18] phases: gracefully handle strip

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Oct 10 07:28:13 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318247683 -7200
# Node ID 4b70d79e03205d956264683e9542ca7f0875625a
# Parent  848b4398797886463fdd314a00b37c009878313c
phases: gracefully handle strip

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -4,11 +4,11 @@
 # Copyright 2007 Matt Mackall
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from mercurial import changegroup, bookmarks
+from mercurial import changegroup, bookmarks, phases
 from mercurial.node import short
 from mercurial.i18n import _
 import os
 
 def _bundle(repo, cg, node, suffix, compress=True):
@@ -68,10 +68,32 @@ def strip(ui, repo, node, backup="all"):
     # (head = revision in the set that has no descendant in the set;
     #  base = revision in the set that has no ancestor in the set)
     tostrip = set(cl.descendants(striprev))
     tostrip.add(striprev)
 
+    #XXX RAW IMPORT FROM EXPERIMENTAL EXTENSION. CHECK ME.
+    nodetostrip = set(map(cl.node, tostrip))
+    # compute the potentially new created phases bondaries which are any
+    # parent of the stripped node that are not stripped (may not be heads)
+    newbondaries = set(par for nod in nodetostrip for par in cl.parents(nod)
+                       if par not in nodetostrip)
+    # save the current phases of newbondaries in a chache as repo.nodephase
+    # must work along the loop. We will use the next loop to add them.
+    phasesheads= [set() for i in range(len(phases.trackedphases))]
+    for nd in newbondaries:
+        phase = repo.nodephase(nd)
+        if phase in phases.trackedphases:
+            phasesheads[phase].add(nd)
+
+    for phase, heads in enumerate(repo._phasesheads):
+        heads = (set(heads) - nodetostrip) | phasesheads[phase]
+        # reduce heads (make them really heads)
+        ctxs = repo.set('heads(%ld)', map(cl.rev, heads))
+        repo._phasesheads[phase] = set(ctx.node() for ctx in ctxs)
+        # XXX DELAY THIS
+    # END OF RAW IMPORT
+
     files = _collectfiles(repo, striprev)
     saverevs = _collectbrokencsets(repo, files, striprev)
 
     # compute heads
     saveheads = set(saverevs)
@@ -143,10 +165,12 @@ def strip(ui, repo, node, backup="all"):
 
         for m in updatebm:
             bm[m] = repo['.'].node()
         bookmarks.write(repo)
 
+        # XXX do this conditionnaly
+        phases.writeheads(repo)
     except:
         if backupfile:
             ui.warn(_("strip failed, full bundle stored in '%s'\n")
                     % backupfile)
         elif saveheads:


More information about the Mercurial-devel mailing list