changeset 26725:bde739aced83

destupdate: extract logic based on branch in 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 02:33:09 +0100
parents 7fc759c0c430
children 8e6649616699
files mercurial/destutil.py
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/destutil.py	Thu Oct 15 02:27:30 2015 +0100
+++ b/mercurial/destutil.py	Thu Oct 15 02:33:09 2015 +0100
@@ -85,6 +85,21 @@
         activemark = node
     return node, movemark, activemark
 
+def _destupdatebranch(repo, clean, check):
+    """decide on an update destination from current branch"""
+    wc = repo[None]
+    movemark = node = None
+    try:
+        node = repo.branchtip(wc.branch())
+        if bookmarks.isactivewdirparent(repo):
+            movemark = repo['.'].node()
+    except error.RepoLookupError:
+        if wc.branch() == 'default': # no default branch!
+            node = repo.lookup('tip') # update to tip
+        else:
+            raise error.Abort(_("branch %s not found") % wc.branch())
+    return node, movemark, None
+
 def destupdate(repo, clean=False, check=False):
     """destination for bare update operation
 
@@ -96,22 +111,13 @@
     - activemark: a bookmark to activate at the end of the update.
     """
     node = None
-    wc = repo[None]
     movemark = activemark = None
 
     node, movemark, activemark = _destupdateobs(repo, clean, check)
     if node is None:
         node, movemark, activemark = _destupdatebook(repo, clean, check)
-
     if node is None:
-        if node is None:
-            try:
-                node = repo.branchtip(wc.branch())
-            except error.RepoLookupError:
-                if wc.branch() == 'default': # no default branch!
-                    node = repo.lookup('tip') # update to tip
-                else:
-                    raise error.Abort(_("branch %s not found") % wc.branch())
+        node, movemark, activemark = _destupdatebranch(repo, clean, check)
     rev = repo[node].rev()
 
     _destupdatevalidate(repo, rev, clean, check)