Mercurial > hg-stable
changeset 26569:2aeeef1dc9a5
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).
To prevent cycle, a new module is created, it will receive other
destination/behavior function in the future.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 05 Oct 2015 01:46:47 -0700 |
parents | c0501c26b05c |
children | c8b332b1eb1f |
files | mercurial/destutil.py mercurial/revset.py |
diffstat | 2 files changed, 59 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/destutil.py Mon Oct 05 01:46:47 2015 -0700 @@ -0,0 +1,56 @@ +# destutil.py - Mercurial utility function for command destination +# +# Copyright Matt Mackall <mpm@selenic.com> and other +# +# 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 . import ( + error, + util, + obsolete, +) + +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()
--- a/mercurial/revset.py Thu Oct 08 10:57:03 2015 -0700 +++ b/mercurial/revset.py Mon Oct 05 01:46:47 2015 -0700 @@ -12,6 +12,7 @@ from .i18n import _ from . import ( + destutil, encoding, error, hbisect, @@ -532,46 +533,8 @@ # # 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()]) + rev = destutil.destupdate(repo) + return subset & baseset([rev]) def adds(repo, subset, x): """``adds(pattern)``