Mercurial > hg-stable
annotate mercurial/destutil.py @ 26724:7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
One of the main goal of having consolidated destination function is to allow
extension to play with this logic. We extract sub logic to make is wrapping more
practical.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 15 Oct 2015 02:27:30 +0100 |
parents | 52d08a93de1f |
children | bde739aced83 |
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 |
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 |
26724
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
79 def _destupdatebook(repo, clean, check): |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
80 """decide on an update destination from active bookmark""" |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
81 # we also move the active bookmark, if any |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
82 activemark = None |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
83 node, movemark = bookmarks.calculateupdate(repo.ui, repo, None) |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
84 if node is not None: |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
85 activemark = node |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
86 return node, movemark, activemark |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
87 |
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
|
88 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
|
89 """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
|
90 |
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 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
|
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 - 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
|
94 - 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
|
95 (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
|
96 - 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
|
97 """ |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 |
52d08a93de1f
destupdate: extract logic based on obsolescence marker in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26722
diff
changeset
|
102 node, movemark, activemark = _destupdateobs(repo, clean, check) |
26724
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
103 if node is None: |
7fc759c0c430
destupdate: extract logic based on bookmarks in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26723
diff
changeset
|
104 node, movemark, activemark = _destupdatebook(repo, clean, check) |
26722
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
105 |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
106 if node is None: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
107 if node is None: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
108 try: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
109 node = repo.branchtip(wc.branch()) |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
110 except error.RepoLookupError: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
111 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
|
112 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
|
113 else: |
6cd643a1d32c
destupdate: move obsolete handling first
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26721
diff
changeset
|
114 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
|
115 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
|
116 |
26720
6c22a17faa18
destupdate: extract validation logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26714
diff
changeset
|
117 _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
|
118 |
26641
5c57d01fe64e
destupdate: also include bookmark related logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26629
diff
changeset
|
119 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
|
120 |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
121 def destmerge(repo): |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
122 if repo._activebookmark: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 node = bmheads[1] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
128 else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
129 node = bmheads[0] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
130 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
|
131 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
|
132 "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
|
133 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
|
134 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
|
135 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
|
136 "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
|
137 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
|
138 else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
143 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
|
144 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
|
145 "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
|
146 % (branch, len(bheads)), |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
147 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
|
148 |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 "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
|
154 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
|
155 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
|
156 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
|
157 "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
|
158 % branch, |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 "explicit revision")) |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
169 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
|
170 node = nbhs[-1] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
171 else: |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
172 node = nbhs[0] |
9903261dcc81
destutil: move default merge destination into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26683
diff
changeset
|
173 return repo[node].rev() |