author | Pierre-Yves David <pierre-yves.david@fb.com> |
Thu, 15 Oct 2015 02:15:43 +0100 | |
changeset 26723 | 52d08a93de1f |
parent 26722 | 6cd643a1d32c |
child 26724 | 7fc759c0c430 |
permissions | -rw-r--r-- |
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 |
|
26720
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
15 |
def _destupdatevalidate(repo, rev, clean, check): |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
16 |
"""validate that the destination comply to various rules |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
17 |
|
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
18 |
This exists as its own function to help wrapping from extensions.""" |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
19 |
wc = repo[None] |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
20 |
p1 = wc.p1() |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
21 |
if not clean: |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
22 |
# Check that the update is linear. |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
23 |
# |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
24 |
# Mercurial do not allow update-merge for non linear pattern |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
25 |
# (that would be technically possible but was considered too confusing |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
26 |
# for user a long time ago) |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
27 |
# |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
28 |
# See mercurial.merge.update for details |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
29 |
if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
30 |
dirty = wc.dirty(missing=True) |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
31 |
foreground = obsolete.foreground(repo, [p1.node()]) |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
32 |
if not repo[rev].node() in foreground: |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
33 |
if dirty: |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
34 |
msg = _("uncommitted changes") |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
35 |
hint = _("commit and merge, or update --clean to" |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
36 |
" discard changes") |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
37 |
raise error.UpdateAbort(msg, hint=hint) |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
38 |
elif not check: # destination is not a descendant. |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
39 |
msg = _("not a linear update") |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
40 |
hint = _("merge or update --check to force update") |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
41 |
raise error.UpdateAbort(msg, hint=hint) |
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
42 |
|
26723
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
43 |
def _destupdateobs(repo, clean, check): |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
44 |
"""decide of an update destination from obsolescence markers""" |
26569
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
45 |
node = None |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
46 |
wc = repo[None] |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
47 |
p1 = wc.p1() |
26723
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
48 |
movemark = None |
26569
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 |
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
|
51 |
# allow updating to successors |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
52 |
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
|
53 |
|
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
54 |
# 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
|
55 |
# |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
56 |
# 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
|
57 |
# 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
|
58 |
# (i.e. 'tip') |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
59 |
# |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
60 |
# 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
|
61 |
# is no conflict |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
62 |
# |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
63 |
# 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
|
64 |
# 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
|
65 |
# 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
|
66 |
|
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
67 |
if successors: |
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
68 |
# 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
|
69 |
# 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
|
70 |
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
|
71 |
|
2aeeef1dc9a5
update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
72 |
# 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
|
73 |
# 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
|
74 |
node = repo.revs('max(%ln)', successors).first() |
26722
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
75 |
if bookmarks.isactivewdirparent(repo): |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
76 |
movemark = repo['.'].node() |
26723
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
77 |
return node, movemark, None |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
78 |
|
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
79 |
def destupdate(repo, clean=False, check=False): |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
80 |
"""destination for bare update operation |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
81 |
|
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
82 |
return (rev, movemark, activemark) |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
83 |
|
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
84 |
- rev: the revision to update to, |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
85 |
- movemark: node to move the active bookmark from |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
86 |
(cf bookmark.calculate update), |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
87 |
- activemark: a bookmark to activate at the end of the update. |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
88 |
""" |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
89 |
node = None |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
90 |
wc = repo[None] |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
91 |
movemark = activemark = None |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
92 |
|
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
93 |
node, movemark, activemark = _destupdateobs(repo, clean, check) |
26722
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
94 |
|
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
95 |
if node is None: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
96 |
# we also move the active bookmark, if any |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
97 |
node, movemark = bookmarks.calculateupdate(repo.ui, repo, None) |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
98 |
if node is not None: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
99 |
activemark = node |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
100 |
|
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
101 |
if node is None: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
102 |
try: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
103 |
node = repo.branchtip(wc.branch()) |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
104 |
except error.RepoLookupError: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
105 |
if wc.branch() == 'default': # no default branch! |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
106 |
node = repo.lookup('tip') # update to tip |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
107 |
else: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
108 |
raise error.Abort(_("branch %s not found") % wc.branch()) |
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
|
109 |
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
|
110 |
|
26720
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
111 |
_destupdatevalidate(repo, rev, clean, check) |
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
|
112 |
|
26641
5c57d01fe64e
destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26629
diff
changeset
|
113 |
return rev, movemark, activemark |
26714
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
114 |
|
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
115 |
def destmerge(repo): |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
116 |
if repo._activebookmark: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
117 |
bmheads = repo.bookmarkheads(repo._activebookmark) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
118 |
curhead = repo[repo._activebookmark].node() |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
119 |
if len(bmheads) == 2: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
120 |
if curhead == bmheads[0]: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
121 |
node = bmheads[1] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
122 |
else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
123 |
node = bmheads[0] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
124 |
elif len(bmheads) > 2: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
125 |
raise error.Abort(_("multiple matching bookmarks to merge - " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
126 |
"please merge with an explicit rev or bookmark"), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
127 |
hint=_("run 'hg heads' to see all heads")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
128 |
elif len(bmheads) <= 1: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
129 |
raise error.Abort(_("no matching bookmark to merge - " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
130 |
"please merge with an explicit rev or bookmark"), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
131 |
hint=_("run 'hg heads' to see all heads")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
132 |
else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
133 |
branch = repo[None].branch() |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
134 |
bheads = repo.branchheads(branch) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
135 |
nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
136 |
|
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
137 |
if len(nbhs) > 2: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
138 |
raise error.Abort(_("branch '%s' has %d heads - " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
139 |
"please merge with an explicit rev") |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
140 |
% (branch, len(bheads)), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
141 |
hint=_("run 'hg heads .' to see heads")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
142 |
|
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
143 |
parent = repo.dirstate.p1() |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
144 |
if len(nbhs) <= 1: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
145 |
if len(bheads) > 1: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
146 |
raise error.Abort(_("heads are bookmarked - " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
147 |
"please merge with an explicit rev"), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
148 |
hint=_("run 'hg heads' to see all heads")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
149 |
if len(repo.heads()) > 1: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
150 |
raise error.Abort(_("branch '%s' has one head - " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
151 |
"please merge with an explicit rev") |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
152 |
% branch, |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
153 |
hint=_("run 'hg heads' to see all heads")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
154 |
msg, hint = _('nothing to merge'), None |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
155 |
if parent != repo.lookup(branch): |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
156 |
hint = _("use 'hg update' instead") |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
157 |
raise error.Abort(msg, hint=hint) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
158 |
|
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
159 |
if parent not in bheads: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
160 |
raise error.Abort(_('working directory not at a head revision'), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
161 |
hint=_("use 'hg update' or merge with an " |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
162 |
"explicit revision")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
163 |
if parent == nbhs[0]: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
164 |
node = nbhs[-1] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
165 |
else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
166 |
node = nbhs[0] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
167 |
return repo[node].rev() |