histedit: properly apply bundle2 backups
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 20 Oct 2015 03:07:23 +0200
changeset 26798 38dcb85f9370
parent 26797 75d550b7d8f5
child 26799 ae03d4190321
histedit: properly apply bundle2 backups If the histedit fails, we restore a backup. We make sure this backup bundle can be in bundle2 format as general delta will require.
hgext/histedit.py
--- a/hgext/histedit.py	Tue Oct 20 16:01:33 2015 +0200
+++ b/hgext/histedit.py	Tue Oct 20 03:07:23 2015 +0200
@@ -160,6 +160,7 @@
 import os
 import sys
 
+from mercurial import bundle2
 from mercurial import cmdutil
 from mercurial import discovery
 from mercurial import error
@@ -822,7 +823,18 @@
                 backupfile = repo.join(state.backupfile)
                 f = hg.openpath(ui, backupfile)
                 gen = exchange.readbundle(ui, f, backupfile)
-                gen.apply(repo, 'histedit', 'bundle:' + backupfile)
+                tr = repo.transaction('histedit.abort')
+                try:
+                    if not isinstance(gen, bundle2.unbundle20):
+                        gen.apply(repo, 'histedit', 'bundle:' + backupfile)
+                    if isinstance(gen, bundle2.unbundle20):
+                        bundle2.applybundle(repo, gen, tr,
+                                            source='histedit',
+                                            url='bundle:' + backupfile)
+                    tr.close()
+                finally:
+                    tr.release()
+
                 os.remove(backupfile)
 
             # check whether we should update away