[PATCH V2 for 09 of 14 FIX-bundle2] histedit: properly apply bundle2 backups

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Oct 20 16:39:48 UTC 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1445303243 -7200
#      Tue Oct 20 03:07:23 2015 +0200
# Node ID b7aae40caeea1ee81c9725c432bbb34047291038
# Parent  122054fdc36932f18ae6af7d66d908718e88a0d1
# EXP-Topic generaldelta
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r b7aae40caeea
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 requires.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -158,10 +158,11 @@ except ImportError:
     import pickle
 import errno
 import os
 import sys
 
+from mercurial import bundle2
 from mercurial import cmdutil
 from mercurial import discovery
 from mercurial import error
 from mercurial import copies
 from mercurial import context
@@ -820,11 +821,22 @@ def _histedit(ui, repo, state, *freeargs
             # Recover our old commits if necessary
             if not state.topmost in repo and state.backupfile:
                 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
             if repo.unfiltered().revs('parents() and (%n  or %ln::)',
                                     state.parentctxnode, leafs | tmpnodes):


More information about the Mercurial-devel mailing list