comparison hgext/rebase.py @ 46836:80cac9936324

reabase: call rewriteutil.precheck() a bit later We now filter out descendants of divergence-causing commits in `_handleskippingobsolete()`. The filtered-out commits are removed from the rebase set (`destmap` and `state`). We should therefore call `rewriteutil.precheck()` after `_handleskippingobsolete()`. This patch does that. It hasn't mattered so far because `rewriteutil.precheck()` doesn't yet check for divergence, but it will soon. This affects one test where we now fail because the user is trying to rebase an ancestor instead of failing because they tried to rebase a public commit. We have several similar tests just after, where we still fail because of the phase, so that seems fine. The difference in behavior also seems fine to me. Differential Revision: https://phab.mercurial-scm.org/D10258
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 23 Mar 2021 14:15:40 -0700
parents c2438f2f635c
children 27ba8acd5684 2cdb05da997d
comparison
equal deleted inserted replaced
46835:c2438f2f635c 46836:80cac9936324
411 411
412 def _preparenewrebase(self, destmap): 412 def _preparenewrebase(self, destmap):
413 if not destmap: 413 if not destmap:
414 return _nothingtorebase() 414 return _nothingtorebase()
415 415
416 result = buildstate(self.repo, destmap, self.collapsef)
417
418 if not result:
419 # Empty state built, nothing to rebase
420 self.ui.status(_(b'nothing to rebase\n'))
421 return _nothingtorebase()
422
423 (self.originalwd, self.destmap, self.state) = result
424 if self.collapsef:
425 dests = set(self.destmap.values())
426 if len(dests) != 1:
427 raise error.InputError(
428 _(b'--collapse does not work with multiple destinations')
429 )
430 destrev = next(iter(dests))
431 destancestors = self.repo.changelog.ancestors(
432 [destrev], inclusive=True
433 )
434 self.external = externalparent(self.repo, self.state, destancestors)
435
436 for destrev in sorted(set(destmap.values())):
437 dest = self.repo[destrev]
438 if dest.closesbranch() and not self.keepbranchesf:
439 self.ui.status(_(b'reopening closed branch head %s\n') % dest)
440
441 # Calculate self.obsolete_* sets
442 self._handleskippingobsolete()
443
416 rebaseset = destmap.keys() 444 rebaseset = destmap.keys()
417 if not self.keepf: 445 if not self.keepf:
418 try: 446 try:
419 rewriteutil.precheck(self.repo, rebaseset, action=b'rebase') 447 rewriteutil.precheck(self.repo, rebaseset, action=b'rebase')
420 except error.Abort as e: 448 except error.Abort as e:
421 if e.hint is None: 449 if e.hint is None:
422 e.hint = _(b'use --keep to keep original changesets') 450 e.hint = _(b'use --keep to keep original changesets')
423 raise e 451 raise e
424
425 result = buildstate(self.repo, destmap, self.collapsef)
426
427 if not result:
428 # Empty state built, nothing to rebase
429 self.ui.status(_(b'nothing to rebase\n'))
430 return _nothingtorebase()
431
432 (self.originalwd, self.destmap, self.state) = result
433 if self.collapsef:
434 dests = set(self.destmap.values())
435 if len(dests) != 1:
436 raise error.InputError(
437 _(b'--collapse does not work with multiple destinations')
438 )
439 destrev = next(iter(dests))
440 destancestors = self.repo.changelog.ancestors(
441 [destrev], inclusive=True
442 )
443 self.external = externalparent(self.repo, self.state, destancestors)
444
445 for destrev in sorted(set(destmap.values())):
446 dest = self.repo[destrev]
447 if dest.closesbranch() and not self.keepbranchesf:
448 self.ui.status(_(b'reopening closed branch head %s\n') % dest)
449
450 # Calculate self.obsolete_* sets
451 self._handleskippingobsolete()
452 452
453 self.prepared = True 453 self.prepared = True
454 454
455 def _assignworkingcopy(self): 455 def _assignworkingcopy(self):
456 if self.inmemory: 456 if self.inmemory: