Show More
@@ -311,6 +311,118 class rebaseruntime(object): | |||||
311 | if dest.closesbranch() and not self.keepbranchesf: |
|
311 | if dest.closesbranch() and not self.keepbranchesf: | |
312 | self.ui.status(_('reopening closed branch head %s\n') % dest) |
|
312 | self.ui.status(_('reopening closed branch head %s\n') % dest) | |
313 |
|
313 | |||
|
314 | def _performrebase(self): | |||
|
315 | repo, ui, opts = self.repo, self.ui, self.opts | |||
|
316 | if self.keepbranchesf: | |||
|
317 | # insert _savebranch at the start of extrafns so if | |||
|
318 | # there's a user-provided extrafn it can clobber branch if | |||
|
319 | # desired | |||
|
320 | self.extrafns.insert(0, _savebranch) | |||
|
321 | if self.collapsef: | |||
|
322 | branches = set() | |||
|
323 | for rev in self.state: | |||
|
324 | branches.add(repo[rev].branch()) | |||
|
325 | if len(branches) > 1: | |||
|
326 | raise error.Abort(_('cannot collapse multiple named ' | |||
|
327 | 'branches')) | |||
|
328 | ||||
|
329 | # Rebase | |||
|
330 | if not self.targetancestors: | |||
|
331 | self.targetancestors = repo.changelog.ancestors([self.target], | |||
|
332 | inclusive=True) | |||
|
333 | ||||
|
334 | # Keep track of the current bookmarks in order to reset them later | |||
|
335 | self.currentbookmarks = repo._bookmarks.copy() | |||
|
336 | self.activebookmark = self.activebookmark or repo._activebookmark | |||
|
337 | if self.activebookmark: | |||
|
338 | bookmarks.deactivate(repo) | |||
|
339 | ||||
|
340 | self.extrafn = _makeextrafn(self.extrafns) | |||
|
341 | ||||
|
342 | self.sortedstate = sorted(self.state) | |||
|
343 | total = len(self.sortedstate) | |||
|
344 | pos = 0 | |||
|
345 | for rev in self.sortedstate: | |||
|
346 | ctx = repo[rev] | |||
|
347 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, | |||
|
348 | ctx.description().split('\n', 1)[0]) | |||
|
349 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) | |||
|
350 | if names: | |||
|
351 | desc += ' (%s)' % ' '.join(names) | |||
|
352 | pos += 1 | |||
|
353 | if self.state[rev] == revtodo: | |||
|
354 | ui.status(_('rebasing %s\n') % desc) | |||
|
355 | ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)), | |||
|
356 | _('changesets'), total) | |||
|
357 | p1, p2, base = defineparents(repo, rev, self.target, | |||
|
358 | self.state, | |||
|
359 | self.targetancestors, | |||
|
360 | self.obsoletenotrebased) | |||
|
361 | storestatus(repo, self.originalwd, self.target, | |||
|
362 | self.state, self.collapsef, self.keepf, | |||
|
363 | self.keepbranchesf, self.external, | |||
|
364 | self.activebookmark) | |||
|
365 | storecollapsemsg(repo, self.collapsemsg) | |||
|
366 | if len(repo[None].parents()) == 2: | |||
|
367 | repo.ui.debug('resuming interrupted rebase\n') | |||
|
368 | else: | |||
|
369 | try: | |||
|
370 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |||
|
371 | 'rebase') | |||
|
372 | stats = rebasenode(repo, rev, p1, base, self.state, | |||
|
373 | self.collapsef, self.target) | |||
|
374 | if stats and stats[3] > 0: | |||
|
375 | raise error.InterventionRequired( | |||
|
376 | _('unresolved conflicts (see hg ' | |||
|
377 | 'resolve, then hg rebase --continue)')) | |||
|
378 | finally: | |||
|
379 | ui.setconfig('ui', 'forcemerge', '', 'rebase') | |||
|
380 | if not self.collapsef: | |||
|
381 | merging = p2 != nullrev | |||
|
382 | editform = cmdutil.mergeeditform(merging, 'rebase') | |||
|
383 | editor = cmdutil.getcommiteditor(editform=editform, **opts) | |||
|
384 | newnode = concludenode(repo, rev, p1, p2, | |||
|
385 | extrafn=self.extrafn, | |||
|
386 | editor=editor, | |||
|
387 | keepbranches=self.keepbranchesf, | |||
|
388 | date=self.date) | |||
|
389 | else: | |||
|
390 | # Skip commit if we are collapsing | |||
|
391 | repo.dirstate.beginparentchange() | |||
|
392 | repo.setparents(repo[p1].node()) | |||
|
393 | repo.dirstate.endparentchange() | |||
|
394 | newnode = None | |||
|
395 | # Update the state | |||
|
396 | if newnode is not None: | |||
|
397 | self.state[rev] = repo[newnode].rev() | |||
|
398 | ui.debug('rebased as %s\n' % short(newnode)) | |||
|
399 | else: | |||
|
400 | if not self.collapsef: | |||
|
401 | ui.warn(_('note: rebase of %d:%s created no changes ' | |||
|
402 | 'to commit\n') % (rev, ctx)) | |||
|
403 | self.skipped.add(rev) | |||
|
404 | self.state[rev] = p1 | |||
|
405 | ui.debug('next revision set to %s\n' % p1) | |||
|
406 | elif self.state[rev] == nullmerge: | |||
|
407 | ui.debug('ignoring null merge rebase of %s\n' % rev) | |||
|
408 | elif self.state[rev] == revignored: | |||
|
409 | ui.status(_('not rebasing ignored %s\n') % desc) | |||
|
410 | elif self.state[rev] == revprecursor: | |||
|
411 | targetctx = repo[self.obsoletenotrebased[rev]] | |||
|
412 | desctarget = '%d:%s "%s"' % (targetctx.rev(), targetctx, | |||
|
413 | targetctx.description().split('\n', 1)[0]) | |||
|
414 | msg = _('note: not rebasing %s, already in destination as %s\n') | |||
|
415 | ui.status(msg % (desc, desctarget)) | |||
|
416 | elif self.state[rev] == revpruned: | |||
|
417 | msg = _('note: not rebasing %s, it has no successor\n') | |||
|
418 | ui.status(msg % desc) | |||
|
419 | else: | |||
|
420 | ui.status(_('already rebased %s as %s\n') % | |||
|
421 | (desc, repo[self.state[rev]])) | |||
|
422 | ||||
|
423 | ui.progress(_('rebasing'), None) | |||
|
424 | ui.note(_('rebase merging completed\n')) | |||
|
425 | ||||
314 | @command('rebase', |
|
426 | @command('rebase', | |
315 | [('s', 'source', '', |
|
427 | [('s', 'source', '', | |
316 | _('rebase the specified changeset and descendants'), _('REV')), |
|
428 | _('rebase the specified changeset and descendants'), _('REV')), | |
@@ -475,115 +587,7 def rebase(ui, repo, **opts): | |||||
475 | if retcode is not None: |
|
587 | if retcode is not None: | |
476 | return retcode |
|
588 | return retcode | |
477 |
|
589 | |||
478 |
|
|
590 | rbsrt._performrebase() | |
479 | # insert _savebranch at the start of extrafns so if |
|
|||
480 | # there's a user-provided extrafn it can clobber branch if |
|
|||
481 | # desired |
|
|||
482 | rbsrt.extrafns.insert(0, _savebranch) |
|
|||
483 | if rbsrt.collapsef: |
|
|||
484 | branches = set() |
|
|||
485 | for rev in rbsrt.state: |
|
|||
486 | branches.add(repo[rev].branch()) |
|
|||
487 | if len(branches) > 1: |
|
|||
488 | raise error.Abort(_('cannot collapse multiple named ' |
|
|||
489 | 'branches')) |
|
|||
490 |
|
||||
491 | # Rebase |
|
|||
492 | if not rbsrt.targetancestors: |
|
|||
493 | rbsrt.targetancestors = repo.changelog.ancestors([rbsrt.target], |
|
|||
494 | inclusive=True) |
|
|||
495 |
|
||||
496 | # Keep track of the current bookmarks in order to reset them later |
|
|||
497 | rbsrt.currentbookmarks = repo._bookmarks.copy() |
|
|||
498 | rbsrt.activebookmark = rbsrt.activebookmark or repo._activebookmark |
|
|||
499 | if rbsrt.activebookmark: |
|
|||
500 | bookmarks.deactivate(repo) |
|
|||
501 |
|
||||
502 | rbsrt.extrafn = _makeextrafn(rbsrt.extrafns) |
|
|||
503 |
|
||||
504 | rbsrt.sortedstate = sorted(rbsrt.state) |
|
|||
505 | total = len(rbsrt.sortedstate) |
|
|||
506 | pos = 0 |
|
|||
507 | for rev in rbsrt.sortedstate: |
|
|||
508 | ctx = repo[rev] |
|
|||
509 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
|||
510 | ctx.description().split('\n', 1)[0]) |
|
|||
511 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
|||
512 | if names: |
|
|||
513 | desc += ' (%s)' % ' '.join(names) |
|
|||
514 | pos += 1 |
|
|||
515 | if rbsrt.state[rev] == revtodo: |
|
|||
516 | ui.status(_('rebasing %s\n') % desc) |
|
|||
517 | ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)), |
|
|||
518 | _('changesets'), total) |
|
|||
519 | p1, p2, base = defineparents(repo, rev, rbsrt.target, |
|
|||
520 | rbsrt.state, |
|
|||
521 | rbsrt.targetancestors, |
|
|||
522 | rbsrt.obsoletenotrebased) |
|
|||
523 | storestatus(repo, rbsrt.originalwd, rbsrt.target, |
|
|||
524 | rbsrt.state, rbsrt.collapsef, rbsrt.keepf, |
|
|||
525 | rbsrt.keepbranchesf, rbsrt.external, |
|
|||
526 | rbsrt.activebookmark) |
|
|||
527 | storecollapsemsg(repo, rbsrt.collapsemsg) |
|
|||
528 | if len(repo[None].parents()) == 2: |
|
|||
529 | repo.ui.debug('resuming interrupted rebase\n') |
|
|||
530 | else: |
|
|||
531 | try: |
|
|||
532 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
|||
533 | 'rebase') |
|
|||
534 | stats = rebasenode(repo, rev, p1, base, rbsrt.state, |
|
|||
535 | rbsrt.collapsef, rbsrt.target) |
|
|||
536 | if stats and stats[3] > 0: |
|
|||
537 | raise error.InterventionRequired( |
|
|||
538 | _('unresolved conflicts (see hg ' |
|
|||
539 | 'resolve, then hg rebase --continue)')) |
|
|||
540 | finally: |
|
|||
541 | ui.setconfig('ui', 'forcemerge', '', 'rebase') |
|
|||
542 | if not rbsrt.collapsef: |
|
|||
543 | merging = p2 != nullrev |
|
|||
544 | editform = cmdutil.mergeeditform(merging, 'rebase') |
|
|||
545 | editor = cmdutil.getcommiteditor(editform=editform, **opts) |
|
|||
546 | newnode = concludenode(repo, rev, p1, p2, |
|
|||
547 | extrafn=rbsrt.extrafn, |
|
|||
548 | editor=editor, |
|
|||
549 | keepbranches=rbsrt.keepbranchesf, |
|
|||
550 | date=rbsrt.date) |
|
|||
551 | else: |
|
|||
552 | # Skip commit if we are collapsing |
|
|||
553 | repo.dirstate.beginparentchange() |
|
|||
554 | repo.setparents(repo[p1].node()) |
|
|||
555 | repo.dirstate.endparentchange() |
|
|||
556 | newnode = None |
|
|||
557 | # Update the state |
|
|||
558 | if newnode is not None: |
|
|||
559 | rbsrt.state[rev] = repo[newnode].rev() |
|
|||
560 | ui.debug('rebased as %s\n' % short(newnode)) |
|
|||
561 | else: |
|
|||
562 | if not rbsrt.collapsef: |
|
|||
563 | ui.warn(_('note: rebase of %d:%s created no changes ' |
|
|||
564 | 'to commit\n') % (rev, ctx)) |
|
|||
565 | rbsrt.skipped.add(rev) |
|
|||
566 | rbsrt.state[rev] = p1 |
|
|||
567 | ui.debug('next revision set to %s\n' % p1) |
|
|||
568 | elif rbsrt.state[rev] == nullmerge: |
|
|||
569 | ui.debug('ignoring null merge rebase of %s\n' % rev) |
|
|||
570 | elif rbsrt.state[rev] == revignored: |
|
|||
571 | ui.status(_('not rebasing ignored %s\n') % desc) |
|
|||
572 | elif rbsrt.state[rev] == revprecursor: |
|
|||
573 | targetctx = repo[rbsrt.obsoletenotrebased[rev]] |
|
|||
574 | desctarget = '%d:%s "%s"' % (targetctx.rev(), targetctx, |
|
|||
575 | targetctx.description().split('\n', 1)[0]) |
|
|||
576 | msg = _('note: not rebasing %s, already in destination as %s\n') |
|
|||
577 | ui.status(msg % (desc, desctarget)) |
|
|||
578 | elif rbsrt.state[rev] == revpruned: |
|
|||
579 | msg = _('note: not rebasing %s, it has no successor\n') |
|
|||
580 | ui.status(msg % desc) |
|
|||
581 | else: |
|
|||
582 | ui.status(_('already rebased %s as %s\n') % |
|
|||
583 | (desc, repo[rbsrt.state[rev]])) |
|
|||
584 |
|
||||
585 | ui.progress(_('rebasing'), None) |
|
|||
586 | ui.note(_('rebase merging completed\n')) |
|
|||
587 |
|
591 | |||
588 | if rbsrt.collapsef and not rbsrt.keepopen: |
|
592 | if rbsrt.collapsef and not rbsrt.keepopen: | |
589 | p1, p2, _base = defineparents(repo, min(rbsrt.state), |
|
593 | p1, p2, _base = defineparents(repo, min(rbsrt.state), |
General Comments 0
You need to be logged in to leave comments.
Login now