Patchwork rebase: restore bookmark state on abort

login
register
mail settings
Submitter Tony Tung
Date April 14, 2015, 7:08 p.m.
Message ID <45acd5f4c8e089d0c930.1429038522@andromeda.local>
Download mbox | patch
Permalink /patch/8675/
State Accepted
Commit db9d8673f49871cf3be1e015f243ff7bcf3db709
Delegated to: Kevin Bullock
Headers show

Comments

Tony Tung - April 14, 2015, 7:08 p.m.
# HG changeset patch
# User Tony Tung <tonytung@fb.com>
# Date 1428951242 14400
#      Mon Apr 13 14:54:02 2015 -0400
# Node ID 45acd5f4c8e089d0c9300e10792c0133bc9451c6
# Parent  52ff737c63d2b2cb41185549aa9c35bc47317032
rebase: restore bookmark state on abort.

The bookmark state was already being preserved, but it wasn't being
properly restored.
Sean Farley - April 15, 2015, 3:14 p.m.
Tony Tung <tonytung@fb.com> writes:

> # HG changeset patch
> # User Tony Tung <tonytung@fb.com>
> # Date 1428951242 14400
> #      Mon Apr 13 14:54:02 2015 -0400
> # Node ID 45acd5f4c8e089d0c9300e10792c0133bc9451c6
> # Parent  52ff737c63d2b2cb41185549aa9c35bc47317032
> rebase: restore bookmark state on abort.
>
> The bookmark state was already being preserved, but it wasn't being
> properly restored.

+1, small nits below

> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -231,7 +231,8 @@
>                      hint = _('use "hg rebase --abort" to clear broken state')
>                      raise util.Abort(msg, hint=hint)
>              if abortf:
> -                return abort(repo, originalwd, target, state)
> +                return abort(repo, originalwd, target, state,
> +                             activebookmark=activebookmark)
>          else:
>              if srcf and basef:
>                  raise util.Abort(_('cannot specify both a '
> @@ -852,8 +853,11 @@
>  
>      return False
>  
> -def abort(repo, originalwd, target, state):
> -    'Restore the repository to its original state'
> +def abort(repo, originalwd, target, state, activebookmark=None):
> +    '''Restore the repository to its original state.  Additional args:
> +
> +    activebookmark: the name of the bookmark that should be active after the
> +        restore'''
>      dstates = [s for s in state.values() if s >= 0]
>      immutable = [d for d in dstates if not repo[d].mutable()]
>      cleanup = True
> @@ -883,6 +887,9 @@
>              # no backup of rebased cset versions needed
>              repair.strip(repo.ui, repo, strippoints)
>  
> +    if activebookmark:
> +        bookmarks.setcurrent(repo, activebookmark)
> +
>      clearstatus(repo)
>      repo.ui.warn(_('rebase aborted\n'))
>      return 0
> @@ -1102,4 +1109,3 @@
>           _("use 'hg rebase --continue' or 'hg rebase --abort'")])
>      # ensure rebased rev are not hidden
>      extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible)
> -

Looks like an unrelated whitespace change. Should be fixed in-flight.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -231,7 +231,8 @@ 
                     hint = _('use "hg rebase --abort" to clear broken state')
                     raise util.Abort(msg, hint=hint)
             if abortf:
-                return abort(repo, originalwd, target, state)
+                return abort(repo, originalwd, target, state,
+                             activebookmark=activebookmark)
         else:
             if srcf and basef:
                 raise util.Abort(_('cannot specify both a '
@@ -852,8 +853,11 @@ 
 
     return False
 
-def abort(repo, originalwd, target, state):
-    'Restore the repository to its original state'
+def abort(repo, originalwd, target, state, activebookmark=None):
+    '''Restore the repository to its original state.  Additional args:
+
+    activebookmark: the name of the bookmark that should be active after the
+        restore'''
     dstates = [s for s in state.values() if s >= 0]
     immutable = [d for d in dstates if not repo[d].mutable()]
     cleanup = True
@@ -883,6 +887,9 @@ 
             # no backup of rebased cset versions needed
             repair.strip(repo.ui, repo, strippoints)
 
+    if activebookmark:
+        bookmarks.setcurrent(repo, activebookmark)
+
     clearstatus(repo)
     repo.ui.warn(_('rebase aborted\n'))
     return 0
@@ -1102,4 +1109,3 @@ 
          _("use 'hg rebase --continue' or 'hg rebase --abort'")])
     # ensure rebased rev are not hidden
     extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible)
-
diff --git a/tests/test-bookmarks-rebase.t b/tests/test-bookmarks-rebase.t
--- a/tests/test-bookmarks-rebase.t
+++ b/tests/test-bookmarks-rebase.t
@@ -66,3 +66,27 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     0
   
+aborted rebase should restore active bookmark.
+
+  $ hg up 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  (leaving bookmark two)
+  $ echo 'e' > d
+  $ hg ci -A -m "4"
+  adding d
+  created new head
+  $ hg bookmark three
+  $ hg rebase -s three -d two
+  rebasing 4:dd7c838e8362 "4" (tip three)
+  merging d
+  warning: conflicts during merge.
+  merging d incomplete! (edit conflicts, then use 'hg resolve --mark')
+  unresolved conflicts (see hg resolve, then hg rebase --continue)
+  [1]
+  $ hg rebase --abort
+  rebase aborted
+  $ hg bookmark
+     one                       1:925d80f479bb
+   * three                     4:dd7c838e8362
+     two                       3:42e5ed2cdcf4
+