diff --git a/mercurial/destutil.py b/mercurial/destutil.py
index 8e6649616699459223c41631a5897c36a1d35201_bWVyY3VyaWFsL2Rlc3R1dGlsLnB5..5b7fd48f9868ce57ae58c3d2d2366c75d82b3f2d_bWVyY3VyaWFsL2Rlc3R1dGlsLnB5 100644
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -131,5 +131,26 @@
 
     return rev, movemark, activemark
 
+def _destmergebook(repo):
+    """find merge destination in the active bookmark case"""
+    node = None
+    bmheads = repo.bookmarkheads(repo._activebookmark)
+    curhead = repo[repo._activebookmark].node()
+    if len(bmheads) == 2:
+        if curhead == bmheads[0]:
+            node = bmheads[1]
+        else:
+            node = bmheads[0]
+    elif len(bmheads) > 2:
+        raise error.Abort(_("multiple matching bookmarks to merge - "
+            "please merge with an explicit rev or bookmark"),
+            hint=_("run 'hg heads' to see all heads"))
+    elif len(bmheads) <= 1:
+        raise error.Abort(_("no matching bookmark to merge - "
+            "please merge with an explicit rev or bookmark"),
+            hint=_("run 'hg heads' to see all heads"))
+    assert node is not None
+    return node
+
 def destmerge(repo):
     if repo._activebookmark:
@@ -134,20 +155,6 @@
 def destmerge(repo):
     if repo._activebookmark:
-        bmheads = repo.bookmarkheads(repo._activebookmark)
-        curhead = repo[repo._activebookmark].node()
-        if len(bmheads) == 2:
-            if curhead == bmheads[0]:
-                node = bmheads[1]
-            else:
-                node = bmheads[0]
-        elif len(bmheads) > 2:
-            raise error.Abort(_("multiple matching bookmarks to merge - "
-                "please merge with an explicit rev or bookmark"),
-                hint=_("run 'hg heads' to see all heads"))
-        elif len(bmheads) <= 1:
-            raise error.Abort(_("no matching bookmark to merge - "
-                "please merge with an explicit rev or bookmark"),
-                hint=_("run 'hg heads' to see all heads"))
+        node = _destmergebook(repo)
     else:
         branch = repo[None].branch()
         bheads = repo.branchheads(branch)