Show More
@@ -185,9 +185,19 b' msgdestmerge = {' | |||||
185 | (_('working directory not at a head revision'), |
|
185 | (_('working directory not at a head revision'), | |
186 | _("use 'hg update' or merge with an explicit revision")) |
|
186 | _("use 'hg update' or merge with an explicit revision")) | |
187 | }, |
|
187 | }, | |
|
188 | 'emptysourceset': | |||
|
189 | {'merge': | |||
|
190 | (_('source set is empty'), | |||
|
191 | None) | |||
|
192 | }, | |||
|
193 | 'multiplebranchessourceset': | |||
|
194 | {'merge': | |||
|
195 | (_('source set is rooted in multiple branches'), | |||
|
196 | None) | |||
|
197 | }, | |||
188 | } |
|
198 | } | |
189 |
|
199 | |||
190 | def _destmergebook(repo, action='merge'): |
|
200 | def _destmergebook(repo, action='merge', sourceset=None): | |
191 | """find merge destination in the active bookmark case""" |
|
201 | """find merge destination in the active bookmark case""" | |
192 | node = None |
|
202 | node = None | |
193 | bmheads = repo.bookmarkheads(repo._activebookmark) |
|
203 | bmheads = repo.bookmarkheads(repo._activebookmark) | |
@@ -206,15 +216,27 b" def _destmergebook(repo, action='merge')" | |||||
206 | assert node is not None |
|
216 | assert node is not None | |
207 | return node |
|
217 | return node | |
208 |
|
218 | |||
209 | def _destmergebranch(repo, action='merge'): |
|
219 | def _destmergebranch(repo, action='merge', sourceset=None): | |
210 | """find merge destination based on branch heads""" |
|
220 | """find merge destination based on branch heads""" | |
211 | node = None |
|
221 | node = None | |
212 | parent = repo.dirstate.p1() |
|
222 | ||
213 | branch = repo.dirstate.branch() |
|
223 | if sourceset is None: | |
|
224 | sourceset = [repo[repo.dirstate.p1()].rev()] | |||
|
225 | branch = repo.dirstate.branch() | |||
|
226 | elif not sourceset: | |||
|
227 | msg, hint = msgdestmerge['emptysourceset'][action] | |||
|
228 | raise error.Abort(msg, hint=hint) | |||
|
229 | else: | |||
|
230 | branch = None | |||
|
231 | for ctx in repo.set('roots(%ld::%ld)', sourceset, sourceset): | |||
|
232 | if branch is not None and ctx.branch() != branch: | |||
|
233 | msg, hint = msgdestmerge['multiplebranchessourceset'][action] | |||
|
234 | raise error.Abort(msg, hint=hint) | |||
|
235 | branch = ctx.branch() | |||
|
236 | ||||
214 | bheads = repo.branchheads(branch) |
|
237 | bheads = repo.branchheads(branch) | |
215 |
|
238 | if not repo.revs('%ld and %ln', sourceset, bheads): | ||
216 | if parent not in bheads: |
|
239 | # Case A: working copy if not on a head. (merge only) | |
217 | # Case A: working copy if not on a head. |
|
|||
218 | # |
|
240 | # | |
219 | # This is probably a user mistake We bailout pointing at 'hg update' |
|
241 | # This is probably a user mistake We bailout pointing at 'hg update' | |
220 | if len(repo.heads()) <= 1: |
|
242 | if len(repo.heads()) <= 1: | |
@@ -222,10 +244,10 b" def _destmergebranch(repo, action='merge" | |||||
222 | else: |
|
244 | else: | |
223 | msg, hint = msgdestmerge['notatheads'][action] |
|
245 | msg, hint = msgdestmerge['notatheads'][action] | |
224 | raise error.Abort(msg, hint=hint) |
|
246 | raise error.Abort(msg, hint=hint) | |
225 |
# remove |
|
247 | # remove heads descendants of source from the set | |
226 | bheads = [bh for bh in bheads if bh != parent] |
|
248 | bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset)) | |
227 | # filters out bookmarked heads |
|
249 | # filters out bookmarked heads | |
228 | nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
|
250 | nbhs = list(repo.revs('%ld - bookmark()', bheads)) | |
229 | if len(nbhs) > 1: |
|
251 | if len(nbhs) > 1: | |
230 | # Case B: There is more than 1 other anonymous heads |
|
252 | # Case B: There is more than 1 other anonymous heads | |
231 | # |
|
253 | # | |
@@ -253,7 +275,7 b" def _destmergebranch(repo, action='merge" | |||||
253 | assert node is not None |
|
275 | assert node is not None | |
254 | return node |
|
276 | return node | |
255 |
|
277 | |||
256 | def destmerge(repo, action='merge'): |
|
278 | def destmerge(repo, action='merge', sourceset=None): | |
257 | """return the default destination for a merge |
|
279 | """return the default destination for a merge | |
258 |
|
280 | |||
259 | (or raise exception about why it can't pick one) |
|
281 | (or raise exception about why it can't pick one) | |
@@ -261,9 +283,9 b" def destmerge(repo, action='merge'):" | |||||
261 | :action: the action being performed, controls emitted error message |
|
283 | :action: the action being performed, controls emitted error message | |
262 | """ |
|
284 | """ | |
263 | if repo._activebookmark: |
|
285 | if repo._activebookmark: | |
264 | node = _destmergebook(repo, action=action) |
|
286 | node = _destmergebook(repo, action=action, sourceset=sourceset) | |
265 | else: |
|
287 | else: | |
266 | node = _destmergebranch(repo, action=action) |
|
288 | node = _destmergebranch(repo, action=action, sourceset=sourceset) | |
267 | return repo[node].rev() |
|
289 | return repo[node].rev() | |
268 |
|
290 | |||
269 | histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())' |
|
291 | histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())' |
@@ -541,8 +541,10 b' def _destupdate(repo, subset, x):' | |||||
541 | @predicate('_destmerge') |
|
541 | @predicate('_destmerge') | |
542 | def _destmerge(repo, subset, x): |
|
542 | def _destmerge(repo, subset, x): | |
543 | # experimental revset for merge destination |
|
543 | # experimental revset for merge destination | |
544 | getargs(x, 0, 0, _("_mergedefaultdest takes no arguments")) |
|
544 | sourceset = None | |
545 | return subset & baseset([destutil.destmerge(repo)]) |
|
545 | if x is not None: | |
|
546 | sourceset = getset(repo, fullreposet(repo), x) | |||
|
547 | return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)]) | |||
546 |
|
548 | |||
547 | @predicate('adds(pattern)', safe=True) |
|
549 | @predicate('adds(pattern)', safe=True) | |
548 | def adds(repo, subset, x): |
|
550 | def adds(repo, subset, x): |
@@ -116,3 +116,36 b' Test experimental destination revset' | |||||
116 | (run 'hg heads' to see all heads) |
|
116 | (run 'hg heads' to see all heads) | |
117 | [255] |
|
117 | [255] | |
118 |
|
118 | |||
|
119 | (on a branch with a two heads) | |||
|
120 | ||||
|
121 | $ hg up 5 | |||
|
122 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
123 | $ echo f >> a | |||
|
124 | $ hg commit -mf | |||
|
125 | created new head | |||
|
126 | $ hg log -r '_destmerge()' | |||
|
127 | changeset: 6:e88e33f3bf62 | |||
|
128 | parent: 5:a431fabd6039 | |||
|
129 | parent: 3:ea9ff125ff88 | |||
|
130 | user: test | |||
|
131 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
132 | summary: m2 | |||
|
133 | ||||
|
134 | ||||
|
135 | (from the other head) | |||
|
136 | ||||
|
137 | $ hg log -r '_destmerge(e88e33f3bf62)' | |||
|
138 | changeset: 8:b613918999e2 | |||
|
139 | tag: tip | |||
|
140 | parent: 5:a431fabd6039 | |||
|
141 | user: test | |||
|
142 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
143 | summary: f | |||
|
144 | ||||
|
145 | ||||
|
146 | (from unrelated branch) | |||
|
147 | ||||
|
148 | $ hg log -r '_destmerge(foobranch)' | |||
|
149 | abort: branch 'foobranch' has one head - please merge with an explicit rev | |||
|
150 | (run 'hg heads' to see all heads) | |||
|
151 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now