|
1 # destutil.py - Mercurial utility function for command destination |
|
2 # |
|
3 # Copyright Matt Mackall <mpm@selenic.com> and other |
|
4 # |
|
5 # This software may be used and distributed according to the terms of the |
|
6 # GNU General Public License version 2 or any later version. |
|
7 |
|
8 from .i18n import _ |
|
9 from . import ( |
|
10 error, |
|
11 util, |
|
12 obsolete, |
|
13 ) |
|
14 |
|
15 def destupdate(repo): |
|
16 """destination for bare update operation |
|
17 """ |
|
18 # Here is where we should consider bookmarks, divergent bookmarks, and tip |
|
19 # of current branch; but currently we are only checking the branch tips. |
|
20 node = None |
|
21 wc = repo[None] |
|
22 p1 = wc.p1() |
|
23 try: |
|
24 node = repo.branchtip(wc.branch()) |
|
25 except error.RepoLookupError: |
|
26 if wc.branch() == 'default': # no default branch! |
|
27 node = repo.lookup('tip') # update to tip |
|
28 else: |
|
29 raise util.Abort(_("branch %s not found") % wc.branch()) |
|
30 |
|
31 if p1.obsolete() and not p1.children(): |
|
32 # allow updating to successors |
|
33 successors = obsolete.successorssets(repo, p1.node()) |
|
34 |
|
35 # behavior of certain cases is as follows, |
|
36 # |
|
37 # divergent changesets: update to highest rev, similar to what |
|
38 # is currently done when there are more than one head |
|
39 # (i.e. 'tip') |
|
40 # |
|
41 # replaced changesets: same as divergent except we know there |
|
42 # is no conflict |
|
43 # |
|
44 # pruned changeset: no update is done; though, we could |
|
45 # consider updating to the first non-obsolete parent, |
|
46 # similar to what is current done for 'hg prune' |
|
47 |
|
48 if successors: |
|
49 # flatten the list here handles both divergent (len > 1) |
|
50 # and the usual case (len = 1) |
|
51 successors = [n for sub in successors for n in sub] |
|
52 |
|
53 # get the max revision for the given successors set, |
|
54 # i.e. the 'tip' of a set |
|
55 node = repo.revs('max(%ln)', successors).first() |
|
56 return repo[node].rev() |