Mercurial > hg
comparison mercurial/destutil.py @ 29043:cf7de4aeb86b stable
destutil: add the ability to specify a search space for rebase destination
In the 'hg pull --rebase', we don't want to pick a rebase destination unrelated
to the pull, we lay down basic infrastructure to allow such restriction on
stable (before 3.8 release) in this case. See issue 5214 for details.
Actual usage and test will be in the next patch.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Sat, 30 Apr 2016 18:41:08 +0200 |
parents | d9539959167d |
children | 1c7167009936 |
comparison
equal
deleted
inserted
replaced
29042:693b856a4d45 | 29043:cf7de4aeb86b |
---|---|
254 (_('rebaseset is rooted in multiple named branches'), | 254 (_('rebaseset is rooted in multiple named branches'), |
255 _('specify an explicit destination with --dest')), | 255 _('specify an explicit destination with --dest')), |
256 }, | 256 }, |
257 } | 257 } |
258 | 258 |
259 def _destmergebook(repo, action='merge', sourceset=None): | 259 def _destmergebook(repo, action='merge', sourceset=None, destspace=None): |
260 """find merge destination in the active bookmark case""" | 260 """find merge destination in the active bookmark case""" |
261 node = None | 261 node = None |
262 bmheads = repo.bookmarkheads(repo._activebookmark) | 262 bmheads = repo.bookmarkheads(repo._activebookmark) |
263 curhead = repo[repo._activebookmark].node() | 263 curhead = repo[repo._activebookmark].node() |
264 if len(bmheads) == 2: | 264 if len(bmheads) == 2: |
273 msg, hint = msgdestmerge['nootherbookmarks'][action] | 273 msg, hint = msgdestmerge['nootherbookmarks'][action] |
274 raise error.NoMergeDestAbort(msg, hint=hint) | 274 raise error.NoMergeDestAbort(msg, hint=hint) |
275 assert node is not None | 275 assert node is not None |
276 return node | 276 return node |
277 | 277 |
278 def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True): | 278 def _destmergebranch(repo, action='merge', sourceset=None, onheadcheck=True, |
279 destspace=None): | |
279 """find merge destination based on branch heads""" | 280 """find merge destination based on branch heads""" |
280 node = None | 281 node = None |
281 | 282 |
282 if sourceset is None: | 283 if sourceset is None: |
283 sourceset = [repo[repo.dirstate.p1()].rev()] | 284 sourceset = [repo[repo.dirstate.p1()].rev()] |
306 raise error.Abort(msg, hint=hint) | 307 raise error.Abort(msg, hint=hint) |
307 # remove heads descendants of source from the set | 308 # remove heads descendants of source from the set |
308 bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset)) | 309 bheads = list(repo.revs('%ln - (%ld::)', bheads, sourceset)) |
309 # filters out bookmarked heads | 310 # filters out bookmarked heads |
310 nbhs = list(repo.revs('%ld - bookmark()', bheads)) | 311 nbhs = list(repo.revs('%ld - bookmark()', bheads)) |
312 | |
313 if destspace is not None: | |
314 # restrict search space | |
315 # used in the 'hg pull --rebase' case, see issue 5214. | |
316 nbhs = list(repo.revs('%ld and %ld', destspace, nbhs)) | |
317 | |
311 if len(nbhs) > 1: | 318 if len(nbhs) > 1: |
312 # Case B: There is more than 1 other anonymous heads | 319 # Case B: There is more than 1 other anonymous heads |
313 # | 320 # |
314 # This means that there will be more than 1 candidate. This is | 321 # This means that there will be more than 1 candidate. This is |
315 # ambiguous. We abort asking the user to pick as explicit destination | 322 # ambiguous. We abort asking the user to pick as explicit destination |
337 else: | 344 else: |
338 node = nbhs[0] | 345 node = nbhs[0] |
339 assert node is not None | 346 assert node is not None |
340 return node | 347 return node |
341 | 348 |
342 def destmerge(repo, action='merge', sourceset=None, onheadcheck=True): | 349 def destmerge(repo, action='merge', sourceset=None, onheadcheck=True, |
350 destspace=None): | |
343 """return the default destination for a merge | 351 """return the default destination for a merge |
344 | 352 |
345 (or raise exception about why it can't pick one) | 353 (or raise exception about why it can't pick one) |
346 | 354 |
347 :action: the action being performed, controls emitted error message | 355 :action: the action being performed, controls emitted error message |
348 """ | 356 """ |
357 # destspace is here to work around issues with `hg pull --rebase` see | |
358 # issue5214 for details | |
349 if repo._activebookmark: | 359 if repo._activebookmark: |
350 node = _destmergebook(repo, action=action, sourceset=sourceset) | 360 node = _destmergebook(repo, action=action, sourceset=sourceset, |
361 destspace=destspace) | |
351 else: | 362 else: |
352 node = _destmergebranch(repo, action=action, sourceset=sourceset, | 363 node = _destmergebranch(repo, action=action, sourceset=sourceset, |
353 onheadcheck=onheadcheck) | 364 onheadcheck=onheadcheck, destspace=destspace) |
354 return repo[node].rev() | 365 return repo[node].rev() |
355 | 366 |
356 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())' | 367 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())' |
357 | 368 |
358 def desthistedit(ui, repo): | 369 def desthistedit(ui, repo): |