Show More
@@ -1,155 +1,158 | |||
|
1 | 1 | # destutil.py - Mercurial utility function for command destination |
|
2 | 2 | # |
|
3 | 3 | # Copyright Matt Mackall <mpm@selenic.com> and other |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from .i18n import _ |
|
9 | 9 | from . import ( |
|
10 | 10 | bookmarks, |
|
11 | 11 | error, |
|
12 | 12 | obsolete, |
|
13 | 13 | ) |
|
14 | 14 | |
|
15 | 15 | def _destupdatevalidate(repo, rev, clean, check): |
|
16 | 16 | """validate that the destination comply to various rules |
|
17 | 17 | |
|
18 | 18 | This exists as its own function to help wrapping from extensions.""" |
|
19 | 19 | wc = repo[None] |
|
20 | 20 | p1 = wc.p1() |
|
21 | 21 | if not clean: |
|
22 | 22 | # Check that the update is linear. |
|
23 | 23 | # |
|
24 | 24 | # Mercurial do not allow update-merge for non linear pattern |
|
25 | 25 | # (that would be technically possible but was considered too confusing |
|
26 | 26 | # for user a long time ago) |
|
27 | 27 | # |
|
28 | 28 | # See mercurial.merge.update for details |
|
29 | 29 | if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): |
|
30 | 30 | dirty = wc.dirty(missing=True) |
|
31 | 31 | foreground = obsolete.foreground(repo, [p1.node()]) |
|
32 | 32 | if not repo[rev].node() in foreground: |
|
33 | 33 | if dirty: |
|
34 | 34 | msg = _("uncommitted changes") |
|
35 | 35 | hint = _("commit and merge, or update --clean to" |
|
36 | 36 | " discard changes") |
|
37 | 37 | raise error.UpdateAbort(msg, hint=hint) |
|
38 | 38 | elif not check: # destination is not a descendant. |
|
39 | 39 | msg = _("not a linear update") |
|
40 | 40 | hint = _("merge or update --check to force update") |
|
41 | 41 | raise error.UpdateAbort(msg, hint=hint) |
|
42 | 42 | |
|
43 | 43 | def destupdate(repo, clean=False, check=False): |
|
44 | 44 | """destination for bare update operation |
|
45 | 45 | |
|
46 | 46 | return (rev, movemark, activemark) |
|
47 | 47 | |
|
48 | 48 | - rev: the revision to update to, |
|
49 | 49 | - movemark: node to move the active bookmark from |
|
50 | 50 | (cf bookmark.calculate update), |
|
51 | 51 | - activemark: a bookmark to activate at the end of the update. |
|
52 | 52 | """ |
|
53 | 53 | node = None |
|
54 | 54 | wc = repo[None] |
|
55 | 55 | p1 = wc.p1() |
|
56 |
movemark |
|
|
57 | ||
|
58 | if node is None: | |
|
59 | # we also move the active bookmark, if any | |
|
60 | node, movemark = bookmarks.calculateupdate(repo.ui, repo, None) | |
|
61 | if node is not None: | |
|
62 | activemark = node | |
|
56 | movemark = activemark = None | |
|
63 | 57 | |
|
64 | if node is None: | |
|
65 | try: | |
|
66 | node = repo.branchtip(wc.branch()) | |
|
67 | except error.RepoLookupError: | |
|
68 | if wc.branch() == 'default': # no default branch! | |
|
69 | node = repo.lookup('tip') # update to tip | |
|
70 | else: | |
|
71 | raise error.Abort(_("branch %s not found") % wc.branch()) | |
|
72 | 58 | if p1.obsolete() and not p1.children(): |
|
73 | 59 | # allow updating to successors |
|
74 | 60 | successors = obsolete.successorssets(repo, p1.node()) |
|
75 | 61 | |
|
76 | 62 | # behavior of certain cases is as follows, |
|
77 | 63 | # |
|
78 | 64 | # divergent changesets: update to highest rev, similar to what |
|
79 | 65 | # is currently done when there are more than one head |
|
80 | 66 | # (i.e. 'tip') |
|
81 | 67 | # |
|
82 | 68 | # replaced changesets: same as divergent except we know there |
|
83 | 69 | # is no conflict |
|
84 | 70 | # |
|
85 | 71 | # pruned changeset: no update is done; though, we could |
|
86 | 72 | # consider updating to the first non-obsolete parent, |
|
87 | 73 | # similar to what is current done for 'hg prune' |
|
88 | 74 | |
|
89 | 75 | if successors: |
|
90 | 76 | # flatten the list here handles both divergent (len > 1) |
|
91 | 77 | # and the usual case (len = 1) |
|
92 | 78 | successors = [n for sub in successors for n in sub] |
|
93 | 79 | |
|
94 | 80 | # get the max revision for the given successors set, |
|
95 | 81 | # i.e. the 'tip' of a set |
|
96 | 82 | node = repo.revs('max(%ln)', successors).first() |
|
83 | if bookmarks.isactivewdirparent(repo): | |
|
84 | movemark = repo['.'].node() | |
|
85 | ||
|
86 | if node is None: | |
|
87 | # we also move the active bookmark, if any | |
|
88 | node, movemark = bookmarks.calculateupdate(repo.ui, repo, None) | |
|
89 | if node is not None: | |
|
90 | activemark = node | |
|
91 | ||
|
92 | if node is None: | |
|
93 | try: | |
|
94 | node = repo.branchtip(wc.branch()) | |
|
95 | except error.RepoLookupError: | |
|
96 | if wc.branch() == 'default': # no default branch! | |
|
97 | node = repo.lookup('tip') # update to tip | |
|
98 | else: | |
|
99 | raise error.Abort(_("branch %s not found") % wc.branch()) | |
|
97 | 100 | rev = repo[node].rev() |
|
98 | 101 | |
|
99 | 102 | _destupdatevalidate(repo, rev, clean, check) |
|
100 | 103 | |
|
101 | 104 | return rev, movemark, activemark |
|
102 | 105 | |
|
103 | 106 | def destmerge(repo): |
|
104 | 107 | if repo._activebookmark: |
|
105 | 108 | bmheads = repo.bookmarkheads(repo._activebookmark) |
|
106 | 109 | curhead = repo[repo._activebookmark].node() |
|
107 | 110 | if len(bmheads) == 2: |
|
108 | 111 | if curhead == bmheads[0]: |
|
109 | 112 | node = bmheads[1] |
|
110 | 113 | else: |
|
111 | 114 | node = bmheads[0] |
|
112 | 115 | elif len(bmheads) > 2: |
|
113 | 116 | raise error.Abort(_("multiple matching bookmarks to merge - " |
|
114 | 117 | "please merge with an explicit rev or bookmark"), |
|
115 | 118 | hint=_("run 'hg heads' to see all heads")) |
|
116 | 119 | elif len(bmheads) <= 1: |
|
117 | 120 | raise error.Abort(_("no matching bookmark to merge - " |
|
118 | 121 | "please merge with an explicit rev or bookmark"), |
|
119 | 122 | hint=_("run 'hg heads' to see all heads")) |
|
120 | 123 | else: |
|
121 | 124 | branch = repo[None].branch() |
|
122 | 125 | bheads = repo.branchheads(branch) |
|
123 | 126 | nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
|
124 | 127 | |
|
125 | 128 | if len(nbhs) > 2: |
|
126 | 129 | raise error.Abort(_("branch '%s' has %d heads - " |
|
127 | 130 | "please merge with an explicit rev") |
|
128 | 131 | % (branch, len(bheads)), |
|
129 | 132 | hint=_("run 'hg heads .' to see heads")) |
|
130 | 133 | |
|
131 | 134 | parent = repo.dirstate.p1() |
|
132 | 135 | if len(nbhs) <= 1: |
|
133 | 136 | if len(bheads) > 1: |
|
134 | 137 | raise error.Abort(_("heads are bookmarked - " |
|
135 | 138 | "please merge with an explicit rev"), |
|
136 | 139 | hint=_("run 'hg heads' to see all heads")) |
|
137 | 140 | if len(repo.heads()) > 1: |
|
138 | 141 | raise error.Abort(_("branch '%s' has one head - " |
|
139 | 142 | "please merge with an explicit rev") |
|
140 | 143 | % branch, |
|
141 | 144 | hint=_("run 'hg heads' to see all heads")) |
|
142 | 145 | msg, hint = _('nothing to merge'), None |
|
143 | 146 | if parent != repo.lookup(branch): |
|
144 | 147 | hint = _("use 'hg update' instead") |
|
145 | 148 | raise error.Abort(msg, hint=hint) |
|
146 | 149 | |
|
147 | 150 | if parent not in bheads: |
|
148 | 151 | raise error.Abort(_('working directory not at a head revision'), |
|
149 | 152 | hint=_("use 'hg update' or merge with an " |
|
150 | 153 | "explicit revision")) |
|
151 | 154 | if parent == nbhs[0]: |
|
152 | 155 | node = nbhs[-1] |
|
153 | 156 | else: |
|
154 | 157 | node = nbhs[0] |
|
155 | 158 | return repo[node].rev() |
General Comments 0
You need to be logged in to leave comments.
Login now