diff mercurial/repair.py @ 22057:445472225ccd

strip: remove -b/--backup codepaths cset ba3bc6474bbf has removed this option. This commit just tidies the code that was associated to it. It also fixes the internal calls to the strip() function. Before this change, any function that thought it would want as a final safety to keep a partial backup bundle (bundling changes not linearly related to the current change being stripped), had to explicitly pass a backup="strip" option. With this change, these backups are always kept in case of an exception and always removed if there is no exception. Only full backups can be specified with backup=True or no full backups with backup=False.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 24 Jul 2014 15:06:08 -0400
parents 4d9d490d7bbe
children d7b114493315
line wrap: on
line diff
--- a/mercurial/repair.py	Thu Aug 07 12:51:45 2014 -0400
+++ b/mercurial/repair.py	Thu Jul 24 15:06:08 2014 -0400
@@ -47,7 +47,13 @@
 
     return s
 
-def strip(ui, repo, nodelist, backup="all", topic='backup'):
+def strip(ui, repo, nodelist, backup=True, topic='backup'):
+
+    # Simple way to maintain backwards compatibility for this
+    # argument.
+    if backup in ['none', 'strip']:
+        backup = False
+
     repo = repo.unfiltered()
     repo.destroying()
 
@@ -58,8 +64,6 @@
     striplist = [cl.rev(node) for node in nodelist]
     striprev = min(striplist)
 
-    keeppartialbundle = backup == 'strip'
-
     # Some revisions with rev > striprev may not be descendants of striprev.
     # We have to find these revisions and put them in a bundle, so that
     # we can restore them after the truncations.
@@ -109,7 +113,7 @@
     # create a changegroup for all the branches we need to keep
     backupfile = None
     vfs = repo.vfs
-    if backup == "all":
+    if backup:
         backupfile = _bundle(repo, stripbases, cl.heads(), node, topic)
         repo.ui.status(_("saved backup bundle to %s\n") %
                        vfs.join(backupfile))
@@ -118,7 +122,7 @@
     if saveheads or savebases:
         # do not compress partial bundle if we remove it from disk later
         chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp',
-                            compress=keeppartialbundle)
+                            compress=False)
 
     mfst = repo.manifest
 
@@ -156,8 +160,6 @@
             if not repo.ui.verbose:
                 repo.ui.popbuffer()
             f.close()
-            if not keeppartialbundle:
-                vfs.unlink(chgrpfile)
 
         # remove undo files
         for undovfs, undofile in repo.undofiles():
@@ -179,5 +181,9 @@
             ui.warn(_("strip failed, partial bundle stored in '%s'\n")
                     % vfs.join(chgrpfile))
         raise
+    else:
+        if saveheads or savebases:
+            # Remove partial backup only if there were no exceptions
+            vfs.unlink(chgrpfile)
 
     repo.destroyed()