annotate mercurial/destutil.py @ 26690:704818fb170d

exchange: advertise if a clone bundle was attempted The client now sends a "cbattempted" boolean flag to the "getbundle" wire protocol command to tell the server whether a clone bundle was attempted. The presence of this flag will enable the server to conditionally emit a bundle2 "output" part advertising the availability of clone bundles to compatible clients that don't have it enabled.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 14 Oct 2015 10:36:20 -0700
parents 634666c48b7d
children 9903261dcc81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
1 # destutil.py - Mercurial utility function for command destination
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
2 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
3 # Copyright Matt Mackall <mpm@selenic.com> and other
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
4 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
7
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
8 from .i18n import _
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
9 from . import (
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
10 bookmarks,
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
11 error,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
12 obsolete,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
13 )
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
14
26629
ae5f7be2b4ab destupdate: include the 'check' logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26628
diff changeset
15 def destupdate(repo, clean=False, check=False):
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
16 """destination for bare update operation
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
17
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
18 return (rev, movemark, activemark)
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
19
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
20 - rev: the revision to update to,
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
21 - movemark: node to move the active bookmark from
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
22 (cf bookmark.calculate update),
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
23 - activemark: a bookmark to activate at the end of the update.
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
24 """
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
25 node = None
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
26 wc = repo[None]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
27 p1 = wc.p1()
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
28 activemark = None
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
29
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
30 # we also move the active bookmark, if any
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
31 node, movemark = bookmarks.calculateupdate(repo.ui, repo, None)
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
32 if node is not None:
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
33 activemark = node
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
34
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
35 if node is None:
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
36 try:
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
37 node = repo.branchtip(wc.branch())
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
38 except error.RepoLookupError:
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
39 if wc.branch() == 'default': # no default branch!
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
40 node = repo.lookup('tip') # update to tip
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
41 else:
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
42 raise error.Abort(_("branch %s not found") % wc.branch())
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
43
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
44 if p1.obsolete() and not p1.children():
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
45 # allow updating to successors
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
46 successors = obsolete.successorssets(repo, p1.node())
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
47
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
48 # behavior of certain cases is as follows,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
49 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
50 # divergent changesets: update to highest rev, similar to what
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
51 # is currently done when there are more than one head
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
52 # (i.e. 'tip')
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
53 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
54 # replaced changesets: same as divergent except we know there
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
55 # is no conflict
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
56 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
57 # pruned changeset: no update is done; though, we could
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
58 # consider updating to the first non-obsolete parent,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
59 # similar to what is current done for 'hg prune'
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
60
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
61 if successors:
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
62 # flatten the list here handles both divergent (len > 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
63 # and the usual case (len = 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
64 successors = [n for sub in successors for n in sub]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
65
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
66 # get the max revision for the given successors set,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
67 # i.e. the 'tip' of a set
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
68 node = repo.revs('max(%ln)', successors).first()
26628
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
69 rev = repo[node].rev()
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
70
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
71 if not clean:
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
72 # Check that the update is linear.
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
73 #
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
74 # Mercurial do not allow update-merge for non linear pattern
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
75 # (that would be technically possible but was considered too confusing
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
76 # for user a long time ago)
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
77 #
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
78 # See mercurial.merge.update for details
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
79 if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True):
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
80 dirty = wc.dirty(missing=True)
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
81 foreground = obsolete.foreground(repo, [p1.node()])
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
82 if not repo[rev].node() in foreground:
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
83 if dirty:
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
84 msg = _("uncommitted changes")
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
85 hint = _("commit and merge, or update --clean to"
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
86 " discard changes")
26683
634666c48b7d update: introduce a 'UpdateAbort' exception
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26641
diff changeset
87 raise error.UpdateAbort(msg, hint=hint)
26629
ae5f7be2b4ab destupdate: include the 'check' logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26628
diff changeset
88 elif not check: # destination is not a descendant.
26628
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
89 msg = _("not a linear update")
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
90 hint = _("merge or update --check to force update")
26683
634666c48b7d update: introduce a 'UpdateAbort' exception
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26641
diff changeset
91 raise error.UpdateAbort(msg, hint=hint)
26628
45b86dbabbda destupdate: move the check related to the "clean" logic in the function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
92
26641
5c57d01fe64e destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26629
diff changeset
93 return rev, movemark, activemark