merge: add a higher-level update() for the common `hg update` use case
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 21 Sep 2020 09:57:29 -0700
changeset 45579 c1b603cdc95a
parent 45578 147fb889278b
child 45580 5c8230ca37f2
merge: add a higher-level update() for the common `hg update` use case This is different from the `update()` function that I just made private. The new function is specifically for the normal `hg update` use case. It doesn't do a merge and it doesn't do a clean (forced) update. Differential Revision: https://phab.mercurial-scm.org/D9066
hgext/rebase.py
hgext/transplant.py
mercurial/merge.py
--- a/hgext/rebase.py	Wed Sep 23 15:16:35 2020 +0200
+++ b/hgext/rebase.py	Mon Sep 21 09:57:29 2020 -0700
@@ -642,13 +642,7 @@
                         cmdutil.bailifchanged(repo)
                         self.inmemory = False
                         self._assignworkingcopy()
-                        mergemod._update(
-                            repo,
-                            p1,
-                            branchmerge=False,
-                            force=False,
-                            wc=self.wctx,
-                        )
+                        mergemod.update(repo[p1], wc=self.wctx)
                         rebasenode(
                             repo,
                             rev,
--- a/hgext/transplant.py	Wed Sep 23 15:16:35 2020 +0200
+++ b/hgext/transplant.py	Mon Sep 21 09:57:29 2020 -0700
@@ -198,9 +198,7 @@
                     if pulls:
                         if source != repo:
                             exchange.pull(repo, source.peer(), heads=pulls)
-                        merge._update(
-                            repo, pulls[-1], branchmerge=False, force=False
-                        )
+                        merge.update(repo[pulls[-1]])
                         p1 = repo.dirstate.p1()
                         pulls = []
 
@@ -275,7 +273,7 @@
             tr.close()
             if pulls:
                 exchange.pull(repo, source.peer(), heads=pulls)
-                merge._update(repo, pulls[-1], branchmerge=False, force=False)
+                merge.update(repo[pulls[-1]])
         finally:
             self.saveseries(revmap, merges)
             self.transplants.write()
--- a/mercurial/merge.py	Wed Sep 23 15:16:35 2020 +0200
+++ b/mercurial/merge.py	Mon Sep 21 09:57:29 2020 -0700
@@ -2056,6 +2056,28 @@
     )
 
 
+def update(ctx, updatecheck=None, wc=None):
+    """Do a regular update to the given commit, aborting if there are conflicts.
+
+    The 'updatecheck' argument can be used to control what to do in case of
+    conflicts.
+
+    Note: This is a new, higher-level update() than the one that used to exist
+    in this module. That function is now called _update(). You can hopefully
+    replace your callers to use this new update(), or clean_update(), merge(),
+    revert_to(), or graft().
+    """
+    return _update(
+        ctx.repo(),
+        ctx.rev(),
+        branchmerge=False,
+        force=False,
+        labels=[b'working copy', b'destination'],
+        updatecheck=updatecheck,
+        wc=wc,
+    )
+
+
 def clean_update(ctx, wc=None):
     """Do a clean update to the given commit.