mercurial/revset.py
changeset 26304 bca60842e22d
parent 26303 c99b4d6efdd8
child 26305 ade5c488d622
--- a/mercurial/revset.py	Thu Sep 17 14:03:15 2015 -0700
+++ b/mercurial/revset.py	Fri Sep 18 17:23:10 2015 -0700
@@ -524,6 +524,55 @@
             node = nbhs[0]
     return subset & 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 subset & baseset([repo[node].rev()])
+
 def adds(repo, subset, x):
     """``adds(pattern)``
     Changesets that add a file matching pattern.
@@ -2162,6 +2211,7 @@
 
 symbols = {
     "_mergedefaultdest": _mergedefaultdest,
+    "_updatedefaultdest": _updatedefaultdest,
     "adds": adds,
     "all": getall,
     "ancestor": ancestor,