Patchwork bookmarks: fix head selection for merge with two bookmarked heads

login
register
mail settings
Submitter Mads Kiilerich
Date Dec. 16, 2012, 6:53 p.m.
Message ID <1c99377ad04befd82dee.1355683987@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/121/
State Superseded
Commit 26627c30735a610f59979a36885b327b25d8dbff
Headers show

Comments

Mads Kiilerich - Dec. 16, 2012, 6:53 p.m.
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1355683886 -3600
# Branch stable
# Node ID 1c99377ad04befd82dee47221d185a60dc8bc585
# Parent  7e2b9f6a2cd043966fca50a29a9867fb12387a22
bookmarks: fix head selection for merge with two bookmarked heads

A type error caused the search for the other head to fail. The code is fragile,
and instead it ended up using the 'first' bookmark head, but the ordering is
undefined and it could thus use the wrong bookmarkhead and fail with:

  $ hg up -q -C e at diverged
  $ hg merge
  abort: merging with a working directory ancestor has no effect
Mads Kiilerich - Dec. 16, 2012, 6:54 p.m.
Mads Kiilerich wrote, On 12/16/2012 07:53 PM:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1355683886 -3600
> # Branch stable
> # Node ID 1c99377ad04befd82dee47221d185a60dc8bc585
> # Parent  7e2b9f6a2cd043966fca50a29a9867fb12387a22
> bookmarks: fix head selection for merge with two bookmarked heads

Should have been flagged for stable.

/Mads
Kevin Bullock - Dec. 17, 2012, 4:22 a.m.
On 16 Dec 2012, at 12:53 PM, Mads Kiilerich wrote:

> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1355683886 -3600
> # Branch stable
> # Node ID 1c99377ad04befd82dee47221d185a60dc8bc585
> # Parent  7e2b9f6a2cd043966fca50a29a9867fb12387a22
> bookmarks: fix head selection for merge with two bookmarked heads
> 
> A type error caused the search for the other head to fail.

Okay, not a TypeError, but a type mismatch. bmheads is an array of raw node IDs, curhead (before this patch) is a changectx. Good catch. +1 if you fix up the description.

pacem in terris / ??? / ?????? / ????????? / ??
Kevin R. Bullock
Mads Kiilerich - Dec. 24, 2012, 12:42 p.m.
Mads Kiilerich wrote, On 12/16/2012 07:53 PM:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1355683886 -3600
> # Branch stable
> # Node ID 1c99377ad04befd82dee47221d185a60dc8bc585
> # Parent  7e2b9f6a2cd043966fca50a29a9867fb12387a22
> bookmarks: fix head selection for merge with two bookmarked heads

Pushed to crew stable. Thanks for reviewing.

/Mads

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4288,7 +4288,7 @@ 
 
     if not node and repo._bookmarkcurrent:
         bmheads = repo.bookmarkheads(repo._bookmarkcurrent)
-        curhead = repo[repo._bookmarkcurrent]
+        curhead = repo[repo._bookmarkcurrent].node()
         if len(bmheads) == 2:
             if curhead == bmheads[0]:
                 node = bmheads[1]
diff --git a/tests/test-bookmarks-merge.t b/tests/test-bookmarks-merge.t
--- a/tests/test-bookmarks-merge.t
+++ b/tests/test-bookmarks-merge.t
@@ -75,9 +75,27 @@ 
   $ echo f > f
   $ hg commit -Am "f"
   adding f
+  $ hg bookmarks -r 4 "e at diverged"
+  $ hg up -q -C "e at diverged"
+  $ hg merge
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg parents
+  changeset:   4:a0546fcfe0fb
+  bookmark:    e at diverged
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     d
+  
+  changeset:   5:26bee9c5bcf3
+  bookmark:    e
+  parent:      3:b8f96cf4688b
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     e
+  
   $ hg up -C e
-  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
-  $ hg bookmarks -r 4 "e at diverged"
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg bookmarks
      b                         1:d2ae7f538514
      c                         3:b8f96cf4688b