changeset 26726:8e6649616699

destupdate: have a generic and extensible way to run each step We want extension to be able to easily override or add new way to select the default update destination. We use the same list + dict approach as in other parts of the code.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 15 Oct 2015 03:00:09 +0100
parents bde739aced83
children 5b7fd48f9868
files mercurial/destutil.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/destutil.py	Thu Oct 15 02:33:09 2015 +0100
+++ b/mercurial/destutil.py	Thu Oct 15 03:00:09 2015 +0100
@@ -100,6 +100,15 @@
             raise error.Abort(_("branch %s not found") % wc.branch())
     return node, movemark, None
 
+# order in which each step should be evalutated
+# steps are run until one finds a destination
+destupdatesteps = ['evolution', 'bookmark', 'branch']
+# mapping to ease extension overriding steps.
+destupdatestepmap = {'evolution': _destupdateobs,
+                     'bookmark': _destupdatebook,
+                     'branch': _destupdatebranch,
+                     }
+
 def destupdate(repo, clean=False, check=False):
     """destination for bare update operation
 
@@ -110,14 +119,12 @@
                 (cf bookmark.calculate update),
     - activemark: a bookmark to activate at the end of the update.
     """
-    node = None
-    movemark = activemark = None
+    node = 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:
-        node, movemark, activemark = _destupdatebranch(repo, clean, check)
+    for step in destupdatesteps:
+        node, movemark, activemark = destupdatestepmap[step](repo, clean, check)
+        if node is not None:
+            break
     rev = repo[node].rev()
 
     _destupdatevalidate(repo, rev, clean, check)