destmerge: extract logic based on bookmark into its own function
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 15 Oct 2015 03:13:14 +0100
changeset 26727 5b7fd48f9868
parent 26726 8e6649616699
child 26728 e8f1b7285917
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.
mercurial/destutil.py
--- 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)