commands: centralize code to update with extra care for non-file components
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sat, 12 Mar 2016 04:35:42 +0900
changeset 28501 66513f6ca038
parent 28500 2e1bceeea520
child 28502 e0d19d955608
commands: centralize code to update with extra care for non-file components This patch centralizes similar code paths to update the working directory with extra care for non-file components (e.g. bookmark) into newly added function updatetotally(). 'if True' at the beginning of updatetotally() is redundant at this patch, but useful to reduce amount of changes in subsequent patch.
mercurial/commands.py
mercurial/hg.py
--- a/mercurial/commands.py	Sat Mar 12 04:35:42 2016 +0900
+++ b/mercurial/commands.py	Sat Mar 12 04:35:42 2016 +0900
@@ -5618,35 +5618,12 @@
     if modheads == 0:
         return
     if optupdate:
-        warndest = False
         try:
-            movemarkfrom = None
-            if not checkout:
-                warndest = True
-                updata = destutil.destupdate(repo)
-                checkout, movemarkfrom, brev = updata
-            ret = hg.update(repo, checkout)
-            if warndest:
-                destutil.statusotherdests(ui, repo)
+            return hg.updatetotally(ui, repo, checkout, brev)
         except error.UpdateAbort as inst:
             msg = _("not updating: %s") % str(inst)
             hint = inst.hint
             raise error.UpdateAbort(msg, hint=hint)
-        if not ret and movemarkfrom:
-            if movemarkfrom == repo['.'].node():
-                pass # no-op update
-            elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
-                ui.status(_("updating bookmark %s\n") % repo._activebookmark)
-        elif brev in repo._bookmarks:
-            if brev != repo._activebookmark:
-                ui.status(_("(activating bookmark %s)\n") % brev)
-            bookmarks.activate(repo, brev)
-        elif brev:
-            if repo._activebookmark:
-                ui.status(_("(leaving bookmark %s)\n") %
-                          repo._activebookmark)
-            bookmarks.deactivate(repo)
-        return ret
     if modheads > 1:
         currentbranchheads = len(repo.branchheads())
         if currentbranchheads == modheads:
@@ -7071,7 +7048,6 @@
 
     Returns 0 on success, 1 if there are unresolved files.
     """
-    movemarkfrom = None
     if rev and node:
         raise error.Abort(_("please specify just one revision"))
 
@@ -7084,8 +7060,6 @@
     if check and clean:
         raise error.Abort(_("cannot specify both -c/--check and -C/--clean"))
 
-    warndest = False
-
     with repo.wlock():
         cmdutil.clearunfinished(repo)
 
@@ -7098,40 +7072,10 @@
 
         if check:
             cmdutil.bailifchanged(repo, merge=False)
-        if rev is None:
-            updata = destutil.destupdate(repo, clean=clean, check=check)
-            rev, movemarkfrom, brev = updata
-            warndest = True
 
         repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
 
-        if clean:
-            ret = hg.clean(repo, rev)
-        else:
-            ret = hg.update(repo, rev)
-
-        if not ret and movemarkfrom:
-            if movemarkfrom == repo['.'].node():
-                pass # no-op update
-            elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
-                ui.status(_("updating bookmark %s\n") % repo._activebookmark)
-            else:
-                # this can happen with a non-linear update
-                ui.status(_("(leaving bookmark %s)\n") %
-                          repo._activebookmark)
-                bookmarks.deactivate(repo)
-        elif brev in repo._bookmarks:
-            if brev != repo._activebookmark:
-                ui.status(_("(activating bookmark %s)\n") % brev)
-            bookmarks.activate(repo, brev)
-        elif brev:
-            if repo._activebookmark:
-                ui.status(_("(leaving bookmark %s)\n") %
-                          repo._activebookmark)
-            bookmarks.deactivate(repo)
-        if warndest:
-            destutil.statusotherdests(ui, repo)
-    return ret
+        return hg.updatetotally(ui, repo, rev, brev, clean=clean, check=check)
 
 @command('verify', [])
 def verify(ui, repo):
--- a/mercurial/hg.py	Sat Mar 12 04:35:42 2016 +0900
+++ b/mercurial/hg.py	Sat Mar 12 04:35:42 2016 +0900
@@ -19,6 +19,7 @@
     bookmarks,
     bundlerepo,
     cmdutil,
+    destutil,
     discovery,
     error,
     exchange,
@@ -694,6 +695,63 @@
         _showstats(repo, stats, quietempty)
     return stats[3] > 0
 
+# naming conflict in updatetotally()
+_clean = clean
+
+def updatetotally(ui, repo, checkout, brev, clean=False, check=False):
+    """Update the working directory with extra care for non-file components
+
+    This takes care of non-file components below:
+
+    :bookmark: might be advanced or (in)activated
+
+    This takes arguments below:
+
+    :checkout: to which revision the working directory is updated
+    :brev: a name, which might be a bookmark to be activated after updating
+    :clean: whether changes in the working directory can be discarded
+    :check: whether changes in the working directory should be checked
+
+    This returns whether conflict is detected at updating or not.
+    """
+    if True:
+        movemarkfrom = None
+        warndest = False
+        if checkout is None:
+            updata = destutil.destupdate(repo, clean=clean, check=check)
+            checkout, movemarkfrom, brev = updata
+            warndest = True
+
+        if clean:
+            ret = _clean(repo, checkout)
+        else:
+            ret = _update(repo, checkout)
+
+        if not ret and movemarkfrom:
+            if movemarkfrom == repo['.'].node():
+                pass # no-op update
+            elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
+                ui.status(_("updating bookmark %s\n") % repo._activebookmark)
+            else:
+                # this can happen with a non-linear update
+                ui.status(_("(leaving bookmark %s)\n") %
+                          repo._activebookmark)
+                bookmarks.deactivate(repo)
+        elif brev in repo._bookmarks:
+            if brev != repo._activebookmark:
+                ui.status(_("(activating bookmark %s)\n") % brev)
+            bookmarks.activate(repo, brev)
+        elif brev:
+            if repo._activebookmark:
+                ui.status(_("(leaving bookmark %s)\n") %
+                          repo._activebookmark)
+            bookmarks.deactivate(repo)
+
+        if warndest:
+            destutil.statusotherdests(ui, repo)
+
+    return ret
+
 def merge(repo, node, force=None, remind=True, mergeforce=False):
     """Branch merge with node, resolving changes. Return true if any
     unresolved conflicts."""