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

login
register
mail settings
Submitter Olle Lundberg
Date March 26, 2014, 11:48 p.m.
Message ID <02d88a51cdb9e5d2dbca.1395877736@se-c02kq0dadr55.lan>
Download mbox | patch
Permalink /patch/4074/
State Not Applicable
Headers show

Comments

Olle Lundberg - March 26, 2014, 11:48 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 02d88a51cdb9e5d2dbcad01a721fc8cff51c7425
# Parent  37c58378ad6bd3b82905f2aec3a6658a1242d3ee
evolve: active bookmark should move when using prev/next (#37)

This patch adds a new default argument to _bookmarksupdater that
controls whether we move inactive bookmarks for a current node or
not. This change does not break existing usage, but will allow us
to move active bookmarks when we traverse the history with previous
and next.

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 - March 27, 2014, 6:27 p.m.
On 03/26/2014 04:48 PM, 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 02d88a51cdb9e5d2dbcad01a721fc8cff51c7425
> # Parent  37c58378ad6bd3b82905f2aec3a6658a1242d3ee
> evolve: active bookmark should move when using prev/next (#37)
>
> This patch adds a new default argument to _bookmarksupdater that
> controls whether we move inactive bookmarks for a current node or
> not. This change does not break existing usage, but will allow us
> to move active bookmarks when we traverse the history with previous
> and next.
>
> The #37 references the bitbucket issue for mutable-history, that
> can be found here:
> https://bitbucket.org/marmoute/mutable-history/issue/37/
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -786,21 +786,23 @@
>       except util.Abort:
>           # Invalidate the previous setparents
>           repo.dirstate.invalidate()
>           raise
>
> -def _bookmarksupdater(repo, oldid):
> +def _bookmarksupdater(repo, oldid, moveinactive=True):
>       """Return a callable update(newid) updating the current bookmark
>       and bookmarks bound to oldid to newid.
>       """
>       bm = bookmarks.readcurrent(repo)
>       def updatebookmarks(newid):
>           dirty = False
>           if bm:
>               repo._bookmarks[bm] = newid
>               dirty = True
> -        oldbookmarks = repo.nodebookmarks(oldid)
> +        oldbookmarks = None
> +        if moveinactive:
> +            oldbookmarks = repo.nodebookmarks(oldid)
>           if oldbookmarks:
>               for b in oldbookmarks:
>                   repo._bookmarks[b] = newid
>               dirty = True
>           if dirty:

I'm not sure this belong to _bookmarksupdater, the function is more 
intended to update bookmark afater a rewriting, ho just letting the 
active bookmark follow the current position.

> @@ -1281,11 +1283,14 @@
>
>       parents = wparents[0].parents()
>       displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
>       if len(parents) == 1:
>           p = parents[0]
> +        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
> +                                     moveinactive=False)
>           hg.update(repo, p.rev())
> +        bmupdate(p.node())
>           displayer.show(p)
>           return 0
>       else:
>           for p in parents:
>               displayer.show(p)
> @@ -1307,11 +1312,14 @@
>       if not children:
>           ui.warn(_('no non-obsolete children\n'))
>           return 1
>       if len(children) == 1:
>           c = children[0]
> +        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
> +                                     moveinactive=False)
>           hg.update(repo, c.rev())
> +        bmupdate(c.node())
>           displayer.show(c)
>           return 0
>       else:
>           for c in children:
>               displayer.show(c)
> diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-bookmarks.t


Thanks for the extensive testing. But they need a bit more documentation 
to be maintable.

Also consider a custom log template for more compact output.
Olle Lundberg - March 27, 2014, 9:45 p.m.
On Thu, Mar 27, 2014 at 7:27 PM, Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

>
>
> On 03/26/2014 04:48 PM, 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 02d88a51cdb9e5d2dbcad01a721fc8cff51c7425
>> # Parent  37c58378ad6bd3b82905f2aec3a6658a1242d3ee
>> evolve: active bookmark should move when using prev/next (#37)
>>
>> This patch adds a new default argument to _bookmarksupdater that
>> controls whether we move inactive bookmarks for a current node or
>> not. This change does not break existing usage, but will allow us
>> to move active bookmarks when we traverse the history with previous
>> and next.
>>
>> The #37 references the bitbucket issue for mutable-history, that
>> can be found here:
>> https://bitbucket.org/marmoute/mutable-history/issue/37/
>>
>> diff --git a/hgext/evolve.py b/hgext/evolve.py
>> --- a/hgext/evolve.py
>> +++ b/hgext/evolve.py
>> @@ -786,21 +786,23 @@
>>       except util.Abort:
>>           # Invalidate the previous setparents
>>           repo.dirstate.invalidate()
>>           raise
>>
>> -def _bookmarksupdater(repo, oldid):
>> +def _bookmarksupdater(repo, oldid, moveinactive=True):
>>       """Return a callable update(newid) updating the current bookmark
>>       and bookmarks bound to oldid to newid.
>>       """
>>       bm = bookmarks.readcurrent(repo)
>>       def updatebookmarks(newid):
>>           dirty = False
>>           if bm:
>>               repo._bookmarks[bm] = newid
>>               dirty = True
>> -        oldbookmarks = repo.nodebookmarks(oldid)
>> +        oldbookmarks = None
>> +        if moveinactive:
>> +            oldbookmarks = repo.nodebookmarks(oldid)
>>           if oldbookmarks:
>>               for b in oldbookmarks:
>>                   repo._bookmarks[b] = newid
>>               dirty = True
>>           if dirty:
>>
>
> I'm not sure this belong to _bookmarksupdater, the function is more
> intended to update bookmark afater a rewriting, ho just letting the active
> bookmark follow the current position.


I think it does. Perhaps with an updated docstring. The logic is more or
less the same, the interface does not get any more complicated (the
complexity of the code stays about the same too). Would you prefer a
separate function with a refactored _bookmarksupdater?


>  @@ -1281,11 +1283,14 @@
>>
>>       parents = wparents[0].parents()
>>       displayer = cmdutil.show_changeset(ui, repo, {'template':
>> shorttemplate})
>>       if len(parents) == 1:
>>           p = parents[0]
>> +        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
>> +                                     moveinactive=False)
>>           hg.update(repo, p.rev())
>> +        bmupdate(p.node())
>>           displayer.show(p)
>>           return 0
>>       else:
>>           for p in parents:
>>               displayer.show(p)
>> @@ -1307,11 +1312,14 @@
>>       if not children:
>>           ui.warn(_('no non-obsolete children\n'))
>>           return 1
>>       if len(children) == 1:
>>           c = children[0]
>> +        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
>> +                                     moveinactive=False)
>>           hg.update(repo, c.rev())
>> +        bmupdate(c.node())
>>           displayer.show(c)
>>           return 0
>>       else:
>>           for c in children:
>>               displayer.show(c)
>> diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
>> new file mode 100644
>> --- /dev/null
>> +++ b/tests/test-bookmarks.t
>>
>
>
> Thanks for the extensive testing. But they need a bit more documentation
> to be maintable.
>

Will update with more sections and comments.

>
> Also consider a custom log template for more compact output.


I think I will skip most of the hg log -G and use hg bookmarks instead.


>
>
>
> --
> Pierre-Yves David
>

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -786,21 +786,23 @@ 
     except util.Abort:
         # Invalidate the previous setparents
         repo.dirstate.invalidate()
         raise
 
-def _bookmarksupdater(repo, oldid):
+def _bookmarksupdater(repo, oldid, moveinactive=True):
     """Return a callable update(newid) updating the current bookmark
     and bookmarks bound to oldid to newid.
     """
     bm = bookmarks.readcurrent(repo)
     def updatebookmarks(newid):
         dirty = False
         if bm:
             repo._bookmarks[bm] = newid
             dirty = True
-        oldbookmarks = repo.nodebookmarks(oldid)
+        oldbookmarks = None
+        if moveinactive:
+            oldbookmarks = repo.nodebookmarks(oldid)
         if oldbookmarks:
             for b in oldbookmarks:
                 repo._bookmarks[b] = newid
             dirty = True
         if dirty:
@@ -1281,11 +1283,14 @@ 
 
     parents = wparents[0].parents()
     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
     if len(parents) == 1:
         p = parents[0]
+        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
+                                     moveinactive=False)
         hg.update(repo, p.rev())
+        bmupdate(p.node())
         displayer.show(p)
         return 0
     else:
         for p in parents:
             displayer.show(p)
@@ -1307,11 +1312,14 @@ 
     if not children:
         ui.warn(_('no non-obsolete children\n'))
         return 1
     if len(children) == 1:
         c = children[0]
+        bmupdate = _bookmarksupdater(repo, wparents[0].node(),
+                                     moveinactive=False)
         hg.update(repo, c.rev())
+        bmupdate(c.node())
         displayer.show(c)
         return 0
     else:
         for c in children:
             displayer.show(c)
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
new file mode 100644
--- /dev/null
+++ b/tests/test-bookmarks.t
@@ -0,0 +1,239 @@ 
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > hgext.rebase=
+  > hgext.graphlog=
+  > EOF
+  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
+
+  $ 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 prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [0] added a
+  $ hg log -G 
+  o  changeset:   1:6e742c9127b3
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added b
+  |
+  @  changeset:   0:a154386e50d1
+     bookmark:    mark
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ touch c
+  $ hg add c
+  $ hg commit -m 'added c'
+  created new head
+  $ hg log -G
+  @  changeset:   2:be36db4d1345
+  |  bookmark:    mark
+  |  tag:         tip
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [0] added a
+  $ hg log -G
+  o  changeset:   2:be36db4d1345
+  |  tag:         tip
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  @  changeset:   0:a154386e50d1
+     bookmark:    mark
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg up
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updating bookmark mark
+  $ hg log -G
+  @  changeset:   2:be36db4d1345
+  |  bookmark:    mark
+  |  tag:         tip
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ touch d
+  $ hg add d
+  $ hg commit -m 'added d'
+  $ hg log -G
+  @  changeset:   3:606c12292ffd
+  |  bookmark:    mark
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  o  changeset:   2:be36db4d1345
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [2] added c
+  $ hg log -G
+  o  changeset:   3:606c12292ffd
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  @  changeset:   2:be36db4d1345
+  |  bookmark:    mark
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg next
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [3] added d
+  $ hg log -G
+  @  changeset:   3:606c12292ffd
+  |  bookmark:    mark
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  o  changeset:   2:be36db4d1345
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg bookmark -r2 no-move 
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [2] added c
+  $ hg log -G
+  o  changeset:   3:606c12292ffd
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  @  changeset:   2:be36db4d1345
+  |  bookmark:    mark
+  |  bookmark:    no-move
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg next
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [3] added d
+  $ hg log -G
+  @  changeset:   3:606c12292ffd
+  |  bookmark:    mark
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  o  changeset:   2:be36db4d1345
+  |  bookmark:    no-move
+  |  parent:      0:a154386e50d1
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  | o  changeset:   1:6e742c9127b3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     added b
+  |
+  o  changeset:   0:a154386e50d1
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg bookmarks
+   * mark                      3:606c12292ffd
+     no-move                   2:be36db4d1345