[PATCH 4 of 4] update: move default destination into a revset

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Sep 21 17:16:38 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1442622190 25200
#      Fri Sep 18 17:23:10 2015 -0700
# Node ID d2de35b3a325e0d4ceeea7992ac0135b84fb95ee
# Parent  d515bf3d8e84ca73062b078e2cbc35f5bba7e360
update: move default destination into a revset

This is another step toward having "default" destination more clear and unified.
Not all the logic is there because some bookmark related computation happened
elsewhere. It will be moved later.

The function is private because as for the other ones, cleanup is needed before
we can proceed.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -19,11 +19,10 @@ from .node import (
     nullid,
     nullrev,
 )
 from . import (
     copies,
-    error as errormod,
     filemerge,
     obsolete,
     subrepo,
     util,
     worker,
@@ -983,46 +982,14 @@ def update(repo, node, branchmerge, forc
         pas = [None]
         if ancestor is not None:
             pas = [repo[ancestor]]
 
         if node is None:
-            # Here is where we should consider bookmarks, divergent bookmarks,
-            # foreground changesets (successors), and tip of current branch;
-            # but currently we are only checking the branch tips.
-            try:
-                node = repo.branchtip(wc.branch())
-            except errormod.RepoLookupError:
-                if wc.branch() == 'default': # no default branch!
-                    node = repo.lookup('tip') # update to tip
-                else:
-                    raise util.Abort(_("branch %s not found") % wc.branch())
-
-            if p1.obsolete() and not p1.children():
-                # allow updating to successors
-                successors = obsolete.successorssets(repo, p1.node())
-
-                # behavior of certain cases is as follows,
-                #
-                # divergent changesets: update to highest rev, similar to what
-                #     is currently done when there are more than one head
-                #     (i.e. 'tip')
-                #
-                # replaced changesets: same as divergent except we know there
-                # is no conflict
-                #
-                # pruned changeset: no update is done; though, we could
-                #     consider updating to the first non-obsolete parent,
-                #     similar to what is current done for 'hg prune'
-
-                if successors:
-                    # flatten the list here handles both divergent (len > 1)
-                    # and the usual case (len = 1)
-                    successors = [n for sub in successors for n in sub]
-
-                    # get the max revision for the given successors set,
-                    # i.e. the 'tip' of a set
-                    node = repo.revs('max(%ln)', successors).first()
+            nodes = list(repo.set('_updatedefaultdest()'))
+            if nodes:
+                node = nodes[0].node()
+                if p1.obsolete() and not p1.children():
                     pas = [p1]
 
         overwrite = force and not branchmerge
 
         p2 = repo[node]
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -523,10 +523,60 @@ def _mergedefaultdest(repo, subset, x):
             node = nbhs[-1]
         else:
             node = nbhs[0]
     return baseset([repo[node].rev()])
 
+def _updatedefaultdest(repo, subset, x):
+    """``_updatedefaultdest()``
+
+    default destination for update.
+    # XXX: Currently private because I expect the signature to change.
+    # XXX: - taking rev as arguments,
+    # XXX: - bailing out in case of ambiguity vs returning all data.
+    """
+    getargs(x, 0, 0, _("_updatedefaultdest takes no arguments"))
+    # Here is where we should consider bookmarks, divergent bookmarks,
+    # foreground changesets (successors), and tip of current branch;
+    # but currently we are only checking the branch tips.
+    node = None
+    wc = repo[None]
+    p1 = wc.p1()
+    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 util.Abort(_("branch %s not found") % wc.branch())
+
+    if p1.obsolete() and not p1.children():
+        # allow updating to successors
+        successors = obsmod.successorssets(repo, p1.node())
+
+        # behavior of certain cases is as follows,
+        #
+        # divergent changesets: update to highest rev, similar to what
+        #     is currently done when there are more than one head
+        #     (i.e. 'tip')
+        #
+        # replaced changesets: same as divergent except we know there
+        # is no conflict
+        #
+        # pruned changeset: no update is done; though, we could
+        #     consider updating to the first non-obsolete parent,
+        #     similar to what is current done for 'hg prune'
+
+        if successors:
+            # flatten the list here handles both divergent (len > 1)
+            # and the usual case (len = 1)
+            successors = [n for sub in successors for n in sub]
+
+            # get the max revision for the given successors set,
+            # i.e. the 'tip' of a set
+            node = repo.revs('max(%ln)', successors).first()
+    return baseset([repo[node].rev()])
+
 def adds(repo, subset, x):
     """``adds(pattern)``
     Changesets that add a file matching pattern.
 
     The pattern without explicit kind like ``glob:`` is expected to be
@@ -2161,10 +2211,11 @@ def _hexlist(repo, subset, x):
     s = subset
     return baseset([r for r in ls if r in s])
 
 symbols = {
     "_mergedefaultdest": _mergedefaultdest,
+    "_updatedefaultdest": _updatedefaultdest,
     "adds": adds,
     "all": getall,
     "ancestor": ancestor,
     "ancestors": ancestors,
     "_firstancestors": _firstancestors,


More information about the Mercurial-devel mailing list