changeset 26727:5b7fd48f9868

destmerge: extract logic based on bookmark into its own function One of the main goal of having consolidated destination function is to allow extension to play with this logic. We extract sub logic to make is wrapping more practical.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 15 Oct 2015 03:13:14 +0100
parents 8e6649616699
children e8f1b7285917
files mercurial/destutil.py
diffstat 1 files changed, 22 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/destutil.py	Thu Oct 15 03:00:09 2015 +0100
+++ b/mercurial/destutil.py	Thu Oct 15 03:13:14 2015 +0100
@@ -131,23 +131,30 @@
 
     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:
-        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)