2463 if any((opts.get('edit'), opts.get('log'), opts.get('user'), |
2462 if any((opts.get('edit'), opts.get('log'), opts.get('user'), |
2464 opts.get('date'), opts.get('currentdate'), |
2463 opts.get('date'), opts.get('currentdate'), |
2465 opts.get('currentuser'), opts.get('rev'))): |
2464 opts.get('currentuser'), opts.get('rev'))): |
2466 raise error.Abort(_("cannot specify any other flag with '--abort'")) |
2465 raise error.Abort(_("cannot specify any other flag with '--abort'")) |
2467 |
2466 |
2468 return _abortgraft(ui, repo, graftstate) |
2467 return cmdutil.abortgraft(ui, repo, graftstate) |
2469 elif opts.get('continue'): |
2468 elif opts.get('continue'): |
2470 cont = True |
2469 cont = True |
2471 if revs: |
2470 if revs: |
2472 raise error.Abort(_("can't specify --continue and revisions")) |
2471 raise error.Abort(_("can't specify --continue and revisions")) |
2473 # read in unfinished revisions |
2472 # read in unfinished revisions |
2474 if graftstate.exists(): |
2473 if graftstate.exists(): |
2475 statedata = _readgraftstate(repo, graftstate) |
2474 statedata = cmdutil.readgraftstate(repo, graftstate) |
2476 if statedata.get('date'): |
2475 if statedata.get('date'): |
2477 opts['date'] = statedata['date'] |
2476 opts['date'] = statedata['date'] |
2478 if statedata.get('user'): |
2477 if statedata.get('user'): |
2479 opts['user'] = statedata['user'] |
2478 opts['user'] = statedata['user'] |
2480 if statedata.get('log'): |
2479 if statedata.get('log'): |
2639 # remove state when we complete successfully |
2638 # remove state when we complete successfully |
2640 if not opts.get('dry_run'): |
2639 if not opts.get('dry_run'): |
2641 graftstate.delete() |
2640 graftstate.delete() |
2642 |
2641 |
2643 return 0 |
2642 return 0 |
2644 |
|
2645 def _abortgraft(ui, repo, graftstate): |
|
2646 """abort the interrupted graft and rollbacks to the state before interrupted |
|
2647 graft""" |
|
2648 if not graftstate.exists(): |
|
2649 raise error.Abort(_("no interrupted graft to abort")) |
|
2650 statedata = _readgraftstate(repo, graftstate) |
|
2651 newnodes = statedata.get('newnodes') |
|
2652 if newnodes is None: |
|
2653 # and old graft state which does not have all the data required to abort |
|
2654 # the graft |
|
2655 raise error.Abort(_("cannot abort using an old graftstate")) |
|
2656 |
|
2657 # changeset from which graft operation was started |
|
2658 if len(newnodes) > 0: |
|
2659 startctx = repo[newnodes[0]].p1() |
|
2660 else: |
|
2661 startctx = repo['.'] |
|
2662 # whether to strip or not |
|
2663 cleanup = False |
|
2664 if newnodes: |
|
2665 newnodes = [repo[r].rev() for r in newnodes] |
|
2666 cleanup = True |
|
2667 # checking that none of the newnodes turned public or is public |
|
2668 immutable = [c for c in newnodes if not repo[c].mutable()] |
|
2669 if immutable: |
|
2670 repo.ui.warn(_("cannot clean up public changesets %s\n") |
|
2671 % ', '.join(bytes(repo[r]) for r in immutable), |
|
2672 hint=_("see 'hg help phases' for details")) |
|
2673 cleanup = False |
|
2674 |
|
2675 # checking that no new nodes are created on top of grafted revs |
|
2676 desc = set(repo.changelog.descendants(newnodes)) |
|
2677 if desc - set(newnodes): |
|
2678 repo.ui.warn(_("new changesets detected on destination " |
|
2679 "branch, can't strip\n")) |
|
2680 cleanup = False |
|
2681 |
|
2682 if cleanup: |
|
2683 with repo.wlock(), repo.lock(): |
|
2684 hg.updaterepo(repo, startctx.node(), overwrite=True) |
|
2685 # stripping the new nodes created |
|
2686 strippoints = [c.node() for c in repo.set("roots(%ld)", |
|
2687 newnodes)] |
|
2688 repair.strip(repo.ui, repo, strippoints, backup=False) |
|
2689 |
|
2690 if not cleanup: |
|
2691 # we don't update to the startnode if we can't strip |
|
2692 startctx = repo['.'] |
|
2693 hg.updaterepo(repo, startctx.node(), overwrite=True) |
|
2694 |
|
2695 ui.status(_("graft aborted\n")) |
|
2696 ui.status(_("working directory is now at %s\n") % startctx.hex()[:12]) |
|
2697 graftstate.delete() |
|
2698 return 0 |
|
2699 |
|
2700 def _readgraftstate(repo, graftstate): |
|
2701 """read the graft state file and return a dict of the data stored in it""" |
|
2702 try: |
|
2703 return graftstate.read() |
|
2704 except error.CorruptedState: |
|
2705 nodes = repo.vfs.read('graftstate').splitlines() |
|
2706 return {'nodes': nodes} |
|
2707 |
2643 |
2708 def _stopgraft(ui, repo, graftstate): |
2644 def _stopgraft(ui, repo, graftstate): |
2709 """stop the interrupted graft""" |
2645 """stop the interrupted graft""" |
2710 if not graftstate.exists(): |
2646 if not graftstate.exists(): |
2711 raise error.Abort(_("no interrupted graft found")) |
2647 raise error.Abort(_("no interrupted graft found")) |