Patchwork [1,of,2,STABLE] bookmarks: resolve divergent bookmarks when fowarding bookmark to descendant

login
register
mail settings
Submitter Sean Farley
Date April 29, 2013, 10:38 p.m.
Message ID <d6ff913a84d296fc6d1e.1367275121@laptop.local>
Download mbox | patch
Permalink /patch/1502/
State Superseded
Commit 26c51e87e807d085a24cc9f2321c75faaa0c7ff4
Headers show

Comments

Sean Farley - April 29, 2013, 10:38 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1367274592 18000
#      Mon Apr 29 17:29:52 2013 -0500
# Branch stable
# Node ID d6ff913a84d296fc6d1ed129351eb215d7e6920e
# Parent  f01a351db79106ba96ac6d527cf69944fd98e665
bookmarks: resolve divergent bookmarks when fowarding bookmark to descendant

This patch is a follow-up to 56dd55da2f7d that resolves divergent bookmarks
between the to-be-forwarded bookmark MARK and the new descendant. This
situation can happen when pulling new changesets, updating to the divergent
bookmark, abandoning the previous changesets with strip, and then moving MARK
to MARK@N.

Test coverage is added.
Sean Farley - April 30, 2013, 1:08 a.m.
On Mon, Apr 29, 2013 at 7:49 PM, Kevin Bullock
<kbullock+mercurial@ringworld.org> wrote:
> On 29 Apr 2013, at 5:38 PM, Sean Farley wrote:
>
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1367274592 18000
>> #      Mon Apr 29 17:29:52 2013 -0500
>> # Branch stable
>> # Node ID d6ff913a84d296fc6d1ed129351eb215d7e6920e
>> # Parent  f01a351db79106ba96ac6d527cf69944fd98e665
>> bookmarks: resolve divergent bookmarks when fowarding bookmark to descendant
>>
>> This patch is a follow-up to 56dd55da2f7d that resolves divergent bookmarks
>> between the to-be-forwarded bookmark MARK and the new descendant. This
>> situation can happen when pulling new changesets, updating to the divergent
>> bookmark, abandoning the previous changesets with strip, and then moving MARK
>> to MARK@N.
>>
>> Test coverage is added.
>>
>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -814,10 +814,14 @@
>>                 if marks[mark] == target and target == cur:
>>                     # re-activating a bookmark
>>                     return
>>                 anc = repo.changelog.ancestors([repo[target].rev()])
>>                 bmctx = repo[marks[mark]]
>> +                divs = [repo[b].node() for b in marks
>> +                        if b.split('@', 1)[0] == mark.split('@', 1)[0]]
>> +                deletefrom = [b for b in divs if repo[b].rev() in anc or b == target]
>
> check-code says hi.

Arrrrrgh. That's what happens when I don't have enough time to run the
test suite!

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -814,10 +814,14 @@ 
                 if marks[mark] == target and target == cur:
                     # re-activating a bookmark
                     return
                 anc = repo.changelog.ancestors([repo[target].rev()])
                 bmctx = repo[marks[mark]]
+                divs = [repo[b].node() for b in marks
+                        if b.split('@', 1)[0] == mark.split('@', 1)[0]]
+                deletefrom = [b for b in divs if repo[b].rev() in anc or b == target]
+                bookmarks.deletedivergent(repo, deletefrom, mark)
                 if bmctx.rev() in anc:
                     ui.status(_("moving bookmark '%s' forward from %s\n") %
                               (mark, short(bmctx.node())))
                     return
             raise util.Abort(_("bookmark '%s' already exists "
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -588,5 +588,26 @@ 
   o  changeset:   0:f7b1eb17ad24
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     0
   
+
+test clearing divergent bookmarks of linear ancestors
+
+  $ hg bookmark Z -r 0
+  $ hg bookmark Z@1 -r 1
+  $ hg bookmark Z@2 -r 2
+  $ hg bookmark Z@3 -r 3
+  $ hg book
+     Z                         0:f7b1eb17ad24
+     Z@1                       1:925d80f479bb
+     Z@2                       2:db815d6d32e6
+   * Z@3                       3:9ba5f110a0b3
+     four                      3:9ba5f110a0b3
+     should-end-on-two         2:db815d6d32e6
+  $ hg bookmark Z
+  moving bookmark 'Z' forward from f7b1eb17ad24
+  $ hg book
+   * Z                         3:9ba5f110a0b3
+     Z@1                       1:925d80f479bb
+     four                      3:9ba5f110a0b3
+     should-end-on-two         2:db815d6d32e6