Patchwork [evolve-ext:stable,V4] evolve: active bookmark should move when using prev/next (#37)

login
register
mail settings
Submitter Olle Lundberg
Date April 3, 2014, 3:24 p.m.
Message ID <9531687c9a0169d563b2.1396538673@SE-C02KQ0DADR55>
Download mbox | patch
Permalink /patch/4206/
State Not Applicable
Headers show

Comments

Olle Lundberg - April 3, 2014, 3:24 p.m.
# HG changeset patch
# User Olle Lundberg <geek@nerd.sh>
# Date 1395874725 -3600
#      Wed Mar 26 23:58:45 2014 +0100
# Branch stable
# Node ID 9531687c9a0169d563b210b96e709d08055993e6
# Parent  37c58378ad6bd3b82905f2aec3a6658a1242d3ee
evolve: active bookmark should move when using prev/next (#37)

The #37 references the bitbucket issue for mutable-history, that
can be found here:
https://bitbucket.org/marmoute/mutable-history/issue/37/
Pierre-Yves David - April 7, 2014, 11:32 p.m.
On 04/03/2014 08:24 AM, Olle Lundberg wrote:
> # HG changeset patch
> # User Olle Lundberg <geek@nerd.sh>
> # Date 1395874725 -3600
> #      Wed Mar 26 23:58:45 2014 +0100
> # Branch stable
> # Node ID 9531687c9a0169d563b210b96e709d08055993e6
> # Parent  37c58378ad6bd3b82905f2aec3a6658a1242d3ee
> evolve: active bookmark should move when using prev/next (#37)
>
> The #37 references the bitbucket issue for mutable-history, that
> can be found here:
> https://bitbucket.org/marmoute/mutable-history/issue/37/

And pushed, Thanks!

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -1281,11 +1281,16 @@ 
 
     parents = wparents[0].parents()
     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
     if len(parents) == 1:
         p = parents[0]
-        hg.update(repo, p.rev())
+        bm = bookmarks.readcurrent(repo)
+        shouldmove = bm is not None and bookmarks.iscurrent(repo, bm)
+        ret = hg.update(repo, p.rev())
+        if not ret and shouldmove:
+            repo._bookmarks[bm] = p.node()
+            repo._bookmarks.write()
         displayer.show(p)
         return 0
     else:
         for p in parents:
             displayer.show(p)
@@ -1307,11 +1312,16 @@ 
     if not children:
         ui.warn(_('no non-obsolete children\n'))
         return 1
     if len(children) == 1:
         c = children[0]
-        hg.update(repo, c.rev())
+        bm = bookmarks.readcurrent(repo)
+        shouldmove = bm is not None and bookmarks.iscurrent(repo, bm)
+        ret = hg.update(repo, c.rev())
+        if not ret and shouldmove:
+            repo._bookmarks[bm] = c.node()
+            repo._bookmarks.write()
         displayer.show(c)
         return 0
     else:
         for c in children:
             displayer.show(c)
diff --git a/tests/test-prev-next.t b/tests/test-prev-next.t
new file mode 100644
--- /dev/null
+++ b/tests/test-prev-next.t
@@ -0,0 +1,62 @@ 
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > hgext.rebase=
+  > hgext.graphlog=
+  > EOF
+  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
+
+hg prev should move active bookmark
+  $ hg init
+  $ touch a
+  $ hg add a
+  $ hg commit -m 'added a'
+  $ touch b
+  $ hg add b
+  $ hg commit -m 'added b'
+  $ hg bookmark mark
+  $ hg bookmarks
+   * mark                      1:6e742c9127b3
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [0] added a
+  $ hg bookmarks
+   * mark                      0:a154386e50d1
+
+hg next should move active bookmark
+  $ hg next
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [1] added b
+  $ hg bookmarks
+   * mark                      1:6e742c9127b3
+
+hg next/prev should not interfere with inactive bookmarks
+  $ touch c
+  $ hg add c
+  $ hg commit -m 'added c'
+  $ hg bookmark -r2 no-move
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [1] added b
+  $ hg bookmarks
+   * mark                      1:6e742c9127b3
+     no-move                   2:4e26ef31f919
+  $ hg next
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [2] added c
+  $ hg bookmarks
+   * mark                      2:4e26ef31f919
+     no-move                   2:4e26ef31f919
+  $ hg up 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg next
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [2] added c
+  $ hg bookmarks
+     mark                      2:4e26ef31f919
+     no-move                   2:4e26ef31f919
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [1] added b
+  $ hg bookmarks
+     mark                      2:4e26ef31f919
+     no-move                   2:4e26ef31f919