diff mercurial/repair.py @ 16252:cf17e76be4dd stable

strip: enhance repair.strip to receive a list of nodes (issue3299) Originally, mq.strip called repair.strip a single rev at a time. repair.strip stores in a backup bundle any revision greater than the revision being stripped, strips, then restores the backup with repo.addchangegroup. So, when stripping revisions on more than one topological branch, some could end up being restored from the backup bundle, only to be later removed by a subsequent repair.strip call. But repo.addchangegroup calls hooks for all those restore operations. And 9df9444e96ec changed it to delay all hook calls until the repository lock were released - by mq.strip, after stripping all revisions. Thus, the hooks could be called over revisions already removed from the repository at that point. By generating the revision lists at once inside repo.strip, we avoid calling addchangegroup for temporary restores. Incidentally, this also avoids creating many backup files for a single strip command.
author Wagner Bruna <wbruna@softwareexpress.com.br>
date Mon, 12 Mar 2012 17:02:45 -0300
parents 73c4b3d0c711
children 17f179805297
line wrap: on
line diff
--- a/mercurial/repair.py	Mon Mar 12 13:22:28 2012 +0100
+++ b/mercurial/repair.py	Mon Mar 12 17:02:45 2012 -0300
@@ -54,10 +54,13 @@
 
     return s
 
-def strip(ui, repo, node, backup="all"):
+def strip(ui, repo, nodelist, backup="all"):
     cl = repo.changelog
     # TODO delete the undo files, and handle undo of merge sets
-    striprev = cl.rev(node)
+    if isinstance(nodelist, str):
+        nodelist = [nodelist]
+    striplist = [cl.rev(node) for node in nodelist]
+    striprev = min(striplist)
 
     keeppartialbundle = backup == 'strip'
 
@@ -68,8 +71,10 @@
     # the list of heads and bases of the set of interesting revisions.
     # (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)
+    tostrip = set(striplist)
+    for rev in striplist:
+        for desc in cl.descendants(rev):
+            tostrip.add(desc)
 
     files = _collectfiles(repo, striprev)
     saverevs = _collectbrokencsets(repo, files, striprev)
@@ -88,6 +93,7 @@
         descendants = set(cl.descendants(*saverevs))
         saverevs.difference_update(descendants)
     savebases = [cl.node(r) for r in saverevs]
+    stripbases = [cl.node(r) for r in tostrip]
 
     bm = repo._bookmarks
     updatebm = []
@@ -99,7 +105,7 @@
     # create a changegroup for all the branches we need to keep
     backupfile = None
     if backup == "all":
-        backupfile = _bundle(repo, [node], cl.heads(), node, 'backup')
+        backupfile = _bundle(repo, stripbases, cl.heads(), node, 'backup')
         repo.ui.status(_("saved backup bundle to %s\n") % backupfile)
     if saveheads or savebases:
         # do not compress partial bundle if we remove it from disk later