Patchwork [2,of,4] update: move default destination computation to a function

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 7, 2015, 7:02 p.m.
Message ID <cb49c9ec614d20e21bc5.1444244542@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10863/
State Superseded
Commit 2aeeef1dc9a5c6d9a30fcd5b1c7d94cbcb3299e0
Headers show

Comments

Pierre-Yves David - Oct. 7, 2015, 7:02 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1444034807 25200
#      Mon Oct 05 01:46:47 2015 -0700
# Node ID cb49c9ec614d20e21bc5affae1439a8abe727f5e
# Parent  23de95a90992c0bd0ea76b17e6c9ba2fba5f3c13
update: move default destination computation to a function

We ultimately want this to be accessible through a revset, but there is too
much complexity here for that to work. Especially we'll have to return more
than just the destination to control the behavior (eg: bookmarks to activate,
etc).

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -530,50 +530,13 @@  def _updatedefaultdest(repo, subset, x):
     # 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()])
+    from .scmutil import destupdate # avoiding cycle
+    rev = destupdate(repo)
+    return subset & baseset([rev])
 
 def adds(repo, subset, x):
     """``adds(pattern)``
     Changesets that add a file matching pattern.
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -5,11 +5,11 @@ 
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
 from mercurial.node import wdirrev
-import util, error, osutil, revset, similar, encoding, phases
+import util, error, osutil, revset, similar, encoding, phases, obsolete
 import pathutil
 import match as matchmod
 import os, errno, re, glob, tempfile, shutil, stat
 
 if os.name == 'nt':
@@ -1165,5 +1165,48 @@  def wlocksub(repo, cmd, *args, **kwargs)
     This can only be called while the wlock is held. This takes all the
     arguments that ui.system does, and returns the exit code of the
     subprocess."""
     return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
                     **kwargs)
+
+def destupdate(repo):
+    """destination for bare update operation
+    """
+    # Here is where we should consider bookmarks, divergent bookmarks, 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 = 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()
+    return repo[node].rev()