Show More
@@ -38,6 +38,7 b' from . import (' | |||||
38 | pathutil, |
|
38 | pathutil, | |
39 | phases, |
|
39 | phases, | |
40 | pycompat, |
|
40 | pycompat, | |
|
41 | repair, | |||
41 | revlog, |
|
42 | revlog, | |
42 | rewriteutil, |
|
43 | rewriteutil, | |
43 | scmutil, |
|
44 | scmutil, | |
@@ -3345,3 +3346,67 b' def wrongtooltocontinue(repo, task):' | |||||
3345 | if after[1]: |
|
3346 | if after[1]: | |
3346 | hint = after[0] |
|
3347 | hint = after[0] | |
3347 | raise error.Abort(_('no %s in progress') % task, hint=hint) |
|
3348 | raise error.Abort(_('no %s in progress') % task, hint=hint) | |
|
3349 | ||||
|
3350 | def abortgraft(ui, repo, graftstate): | |||
|
3351 | """abort the interrupted graft and rollbacks to the state before interrupted | |||
|
3352 | graft""" | |||
|
3353 | if not graftstate.exists(): | |||
|
3354 | raise error.Abort(_("no interrupted graft to abort")) | |||
|
3355 | statedata = readgraftstate(repo, graftstate) | |||
|
3356 | newnodes = statedata.get('newnodes') | |||
|
3357 | if newnodes is None: | |||
|
3358 | # and old graft state which does not have all the data required to abort | |||
|
3359 | # the graft | |||
|
3360 | raise error.Abort(_("cannot abort using an old graftstate")) | |||
|
3361 | ||||
|
3362 | # changeset from which graft operation was started | |||
|
3363 | if len(newnodes) > 0: | |||
|
3364 | startctx = repo[newnodes[0]].p1() | |||
|
3365 | else: | |||
|
3366 | startctx = repo['.'] | |||
|
3367 | # whether to strip or not | |||
|
3368 | cleanup = False | |||
|
3369 | from . import hg | |||
|
3370 | if newnodes: | |||
|
3371 | newnodes = [repo[r].rev() for r in newnodes] | |||
|
3372 | cleanup = True | |||
|
3373 | # checking that none of the newnodes turned public or is public | |||
|
3374 | immutable = [c for c in newnodes if not repo[c].mutable()] | |||
|
3375 | if immutable: | |||
|
3376 | repo.ui.warn(_("cannot clean up public changesets %s\n") | |||
|
3377 | % ', '.join(bytes(repo[r]) for r in immutable), | |||
|
3378 | hint=_("see 'hg help phases' for details")) | |||
|
3379 | cleanup = False | |||
|
3380 | ||||
|
3381 | # checking that no new nodes are created on top of grafted revs | |||
|
3382 | desc = set(repo.changelog.descendants(newnodes)) | |||
|
3383 | if desc - set(newnodes): | |||
|
3384 | repo.ui.warn(_("new changesets detected on destination " | |||
|
3385 | "branch, can't strip\n")) | |||
|
3386 | cleanup = False | |||
|
3387 | ||||
|
3388 | if cleanup: | |||
|
3389 | with repo.wlock(), repo.lock(): | |||
|
3390 | hg.updaterepo(repo, startctx.node(), overwrite=True) | |||
|
3391 | # stripping the new nodes created | |||
|
3392 | strippoints = [c.node() for c in repo.set("roots(%ld)", | |||
|
3393 | newnodes)] | |||
|
3394 | repair.strip(repo.ui, repo, strippoints, backup=False) | |||
|
3395 | ||||
|
3396 | if not cleanup: | |||
|
3397 | # we don't update to the startnode if we can't strip | |||
|
3398 | startctx = repo['.'] | |||
|
3399 | hg.updaterepo(repo, startctx.node(), overwrite=True) | |||
|
3400 | ||||
|
3401 | ui.status(_("graft aborted\n")) | |||
|
3402 | ui.status(_("working directory is now at %s\n") % startctx.hex()[:12]) | |||
|
3403 | graftstate.delete() | |||
|
3404 | return 0 | |||
|
3405 | ||||
|
3406 | def readgraftstate(repo, graftstate): | |||
|
3407 | """read the graft state file and return a dict of the data stored in it""" | |||
|
3408 | try: | |||
|
3409 | return graftstate.read() | |||
|
3410 | except error.CorruptedState: | |||
|
3411 | nodes = repo.vfs.read('graftstate').splitlines() | |||
|
3412 | return {'nodes': nodes} |
@@ -53,7 +53,6 b' from . import (' | |||||
53 | pycompat, |
|
53 | pycompat, | |
54 | rcutil, |
|
54 | rcutil, | |
55 | registrar, |
|
55 | registrar, | |
56 | repair, |
|
|||
57 | revsetlang, |
|
56 | revsetlang, | |
58 | rewriteutil, |
|
57 | rewriteutil, | |
59 | scmutil, |
|
58 | scmutil, | |
@@ -2465,14 +2464,14 b' def _dograft(ui, repo, *revs, **opts):' | |||||
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 |
|
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 = |
|
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'): | |
@@ -2642,69 +2641,6 b' def _dograft(ui, repo, *revs, **opts):' | |||||
2642 |
|
2641 | |||
2643 | return 0 |
|
2642 | return 0 | |
2644 |
|
2643 | |||
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 |
|
||||
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(): |
General Comments 0
You need to be logged in to leave comments.
Login now