# HG changeset patch # User Pierre-Yves David # Date 2015-10-20 01:07:23 # Node ID 38dcb85f9370bf2b647b4e728cb9488a960d7d22 # Parent 75d550b7d8f5e2dd20caa82737e24788183c0836 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. diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -160,6 +160,7 @@ import errno import os import sys +from mercurial import bundle2 from mercurial import cmdutil from mercurial import discovery from mercurial import error @@ -822,7 +823,18 @@ def _histedit(ui, repo, state, *freeargs 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