Mercurial > hg
comparison mercurial/shelve.py @ 42599:3fb0493812c0
abort: added support for unshelve
This patch adds the support for shelve in `hg abort` plan.
For this the logic to load a `shelvedstate` and the error
handling for it had been shifted to a seperate function
`_loadunshelvedstate()`. This returns a tuple with `state` file
and `opts.`
`hgabortunshelve()` has been created for independent calls.
In case abortion of `unshelve` is called via `hg abort` the
`shelvedstate` needs to be loaded seperately. This has been
ensured by `_loadunshelvedstate()`
`hgabortunshelve()` is then registered as `abortfunc` for state
detection API.
Results are shown as tests.
Differential Revision: https://phab.mercurial-scm.org/D6579
author | Taapas Agrawal <taapas2897@gmail.com> |
---|---|
date | Wed, 26 Jun 2019 22:15:07 +0530 |
parents | 8ddfdcce4bd6 |
children | 117437f3f541 |
comparison
equal
deleted
inserted
replaced
42598:8ddfdcce4bd6 | 42599:3fb0493812c0 |
---|---|
622 """check parent while resuming an unshelve""" | 622 """check parent while resuming an unshelve""" |
623 if state.parents != repo.dirstate.parents(): | 623 if state.parents != repo.dirstate.parents(): |
624 raise error.Abort(_('working directory parents do not match unshelve ' | 624 raise error.Abort(_('working directory parents do not match unshelve ' |
625 'state')) | 625 'state')) |
626 | 626 |
627 def unshelveabort(ui, repo, state, opts): | 627 def _loadshelvedstate(ui, repo, opts): |
628 try: | |
629 state = shelvedstate.load(repo) | |
630 if opts.get('keep') is None: | |
631 opts['keep'] = state.keep | |
632 except IOError as err: | |
633 if err.errno != errno.ENOENT: | |
634 raise | |
635 cmdutil.wrongtooltocontinue(repo, _('unshelve')) | |
636 except error.CorruptedState as err: | |
637 ui.debug(pycompat.bytestr(err) + '\n') | |
638 if opts.get('continue'): | |
639 msg = _('corrupted shelved state file') | |
640 hint = _('please run hg unshelve --abort to abort unshelve ' | |
641 'operation') | |
642 raise error.Abort(msg, hint=hint) | |
643 elif opts.get('abort'): | |
644 shelvedstate.clear(repo) | |
645 raise error.Abort(_('could not read shelved state file, your ' | |
646 'working copy may be in an unexpected state\n' | |
647 'please update to some commit\n')) | |
648 return state | |
649 | |
650 def unshelveabort(ui, repo, state): | |
628 """subcommand that abort an in-progress unshelve""" | 651 """subcommand that abort an in-progress unshelve""" |
629 with repo.lock(): | 652 with repo.lock(): |
630 try: | 653 try: |
631 checkparents(repo, state) | 654 checkparents(repo, state) |
632 | 655 |
640 topic='shelve') | 663 topic='shelve') |
641 finally: | 664 finally: |
642 shelvedstate.clear(repo) | 665 shelvedstate.clear(repo) |
643 ui.warn(_("unshelve of '%s' aborted\n") % state.name) | 666 ui.warn(_("unshelve of '%s' aborted\n") % state.name) |
644 | 667 |
668 def hgabortunshelve(ui, repo): | |
669 """logic to abort unshelve using 'hg abort""" | |
670 with repo.wlock(): | |
671 state = _loadshelvedstate(ui, repo, {'abort' : True}) | |
672 return unshelveabort(ui, repo, state) | |
673 | |
645 def mergefiles(ui, repo, wctx, shelvectx): | 674 def mergefiles(ui, repo, wctx, shelvectx): |
646 """updates to wctx and merges the changes from shelvectx into the | 675 """updates to wctx and merges the changes from shelvectx into the |
647 dirstate.""" | 676 dirstate.""" |
648 with ui.configoverride({('ui', 'quiet'): True}): | 677 with ui.configoverride({('ui', 'quiet'): True}): |
649 hg.update(repo, wctx.node()) | 678 hg.update(repo, wctx.node()) |
663 for filetype in shelvefileextensions: | 692 for filetype in shelvefileextensions: |
664 shfile = shelvedfile(repo, name, filetype) | 693 shfile = shelvedfile(repo, name, filetype) |
665 if shfile.exists(): | 694 if shfile.exists(): |
666 shfile.movetobackup() | 695 shfile.movetobackup() |
667 cleanupoldbackups(repo) | 696 cleanupoldbackups(repo) |
668 | |
669 def unshelvecontinue(ui, repo, state, opts): | 697 def unshelvecontinue(ui, repo, state, opts): |
670 """subcommand to continue an in-progress unshelve""" | 698 """subcommand to continue an in-progress unshelve""" |
671 # We're finishing off a merge. First parent is our original | 699 # We're finishing off a merge. First parent is our original |
672 # parent, second is the temporary "fake" commit we're unshelving. | 700 # parent, second is the temporary "fake" commit we're unshelving. |
673 with repo.lock(): | 701 with repo.lock(): |
862 raise error.Abort(_('cannot combine abort/continue with ' | 890 raise error.Abort(_('cannot combine abort/continue with ' |
863 'naming a shelved change')) | 891 'naming a shelved change')) |
864 if abortf and opts.get('tool', False): | 892 if abortf and opts.get('tool', False): |
865 ui.warn(_('tool option will be ignored\n')) | 893 ui.warn(_('tool option will be ignored\n')) |
866 | 894 |
867 try: | 895 state = _loadshelvedstate(ui, repo, opts) |
868 state = shelvedstate.load(repo) | |
869 if opts.get('keep') is None: | |
870 opts['keep'] = state.keep | |
871 except IOError as err: | |
872 if err.errno != errno.ENOENT: | |
873 raise | |
874 cmdutil.wrongtooltocontinue(repo, _('unshelve')) | |
875 except error.CorruptedState as err: | |
876 ui.debug(pycompat.bytestr(err) + '\n') | |
877 if continuef: | |
878 msg = _('corrupted shelved state file') | |
879 hint = _('please run hg unshelve --abort to abort unshelve ' | |
880 'operation') | |
881 raise error.Abort(msg, hint=hint) | |
882 elif abortf: | |
883 shelvedstate.clear(repo) | |
884 raise error.Abort(_('could not read shelved state file, your ' | |
885 'working copy may be in an unexpected state\n' | |
886 'please update to some commit\n')) | |
887 | |
888 if abortf: | 896 if abortf: |
889 return unshelveabort(ui, repo, state, opts) | 897 return unshelveabort(ui, repo, state) |
890 elif continuef: | 898 elif continuef: |
891 return unshelvecontinue(ui, repo, state, opts) | 899 return unshelvecontinue(ui, repo, state, opts) |
892 elif len(shelved) > 1: | 900 elif len(shelved) > 1: |
893 raise error.Abort(_('can only unshelve one change at a time')) | 901 raise error.Abort(_('can only unshelve one change at a time')) |
894 elif not shelved: | 902 elif not shelved: |