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

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 20, 2015, 4:39 p.m.
Message ID <b7aae40caeea1ee81c97.1445359188@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/11206/
State Accepted
Commit 38dcb85f9370bf2b647b4e728cb9488a960d7d22
Headers show

Comments

Pierre-Yves David - Oct. 20, 2015, 4:39 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Augie Fackler - Oct. 21, 2015, 2:43 p.m.
On Tue, Oct 20, 2015 at 06:39:48PM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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):

couldn't this be else?

> +                        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):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

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):