D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
Closed by commit rHG3fb0493812c0: abort: added support for unshelve (authored 
by taapas1128).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15866=15882

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return state
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui, repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -665,7 +694,6 @@
 if shfile.exists():
 shfile.movetobackup()
 cleanupoldbackups(repo)
-
 def unshelvecontinue(ui, repo, state, opts):
 

D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15866.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15863=15866

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return state
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui, repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -665,7 +694,6 @@
 if shfile.exists():
 shfile.movetobackup()
 cleanupoldbackups(repo)
-
 def unshelvecontinue(ui, repo, state, opts):
 """subcommand to continue an in-progress unshelve"""
 # We're finishing off a merge. First parent is our original
@@ 

D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15863.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15861=15863

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return state
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui, repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -665,7 +694,6 @@
 if shfile.exists():
 shfile.movetobackup()
 cleanupoldbackups(repo)
-
 def unshelvecontinue(ui, repo, state, opts):
 """subcommand to continue an in-progress unshelve"""
 # We're finishing off a merge. First parent is our original
@@ 

D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15861.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15860=15861

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return state
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui, repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -665,7 +694,6 @@
 if shfile.exists():
 shfile.movetobackup()
 cleanupoldbackups(repo)
-
 def unshelvecontinue(ui, repo, state, opts):
 """subcommand to continue an in-progress unshelve"""
 # We're finishing off a merge. First parent is our original
@@ 

D6579: abort: added support for unshelve

2019-07-10 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> shelve.py:648
> +'please update to some commit\n'))
> +return (state, opts)
> +

we can prevent returning opts here. One user does not need it and other one is 
passing by reference.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 added a comment.


  updated that.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15860.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15859=15860

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return (state, opts)
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui, repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state, opts = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -864,29 +893,9 @@
 if abortf and opts.get('tool', False):
 ui.warn(_('tool option will be ignored\n'))
 
-try:
-state = shelvedstate.load(repo)
-if opts.get('keep') is None:
-   

D6579: abort: added support for unshelve

2019-07-10 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  The commit message is outdated.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15859.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15857=15859

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return (state, opts)
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui,repo):
+"""logic to  abort unshelve using 'hg abort"""
+with repo.wlock():
+state, opts = _loadshelvedstate(ui, repo, {'abort' : True})
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -864,29 +893,9 @@
 if abortf and opts.get('tool', False):
 ui.warn(_('tool option will be ignored\n'))
 
-try:
-state = shelvedstate.load(repo)
-if opts.get('keep') is None:
-opts['keep'] = state.keep
-except 

D6579: abort: added support for unshelve

2019-07-10 Thread taapas1128 (Taapas Agrawal)
taapas1128 marked 5 inline comments as done.
taapas1128 updated this revision to Diff 15857.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15833=15857

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,7 +710,7 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   abort: could not read shelved state file, your working copy may be in an 
unexpected state
   please update to some commit
   
@@ -703,8 +718,10 @@
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -824,7 +841,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -843,7 +860,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,7 +624,30 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if opts.get('continue'):
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif opts.get('abort'):
+shelvedstate.clear(repo)
+raise error.Abort(_('could not read shelved state file, your '
+'working copy may be in an unexpected state\n'
+'please update to some commit\n'))
+return (state, opts)
+
+def unshelveabort(ui, repo, state):
 """subcommand that abort an in-progress unshelve"""
 with repo.lock():
 try:
@@ -642,6 +665,12 @@
 shelvedstate.clear(repo)
 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
+def hgabortunshelve(ui,repo):
+"""logic to  abort unshelve using 'hg abort"""
+state, opts = _loadshelvedstate(ui, repo, {'abort' : True})
+with repo.wlock():
+return unshelveabort(ui, repo, state)
+
 def mergefiles(ui, repo, wctx, shelvectx):
 """updates to wctx and merges the changes from shelvectx into the
 dirstate."""
@@ -864,29 +893,9 @@
 if abortf and opts.get('tool', False):
 ui.warn(_('tool option will be ignored\n'))
 
-try:
-state = shelvedstate.load(repo)
-if opts.get('keep') is None:
-

D6579: abort: added support for unshelve

2019-07-10 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> shelve.py:628
>  
> -def unshelveabort(ui, repo, state, opts):
> +def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
> +try:

continuef and abortf can be read from opts, no need to pass them separately.

Also, `opts` should be pass as a dictionary here, no need to pass that as 
kwargs.

> shelve.py:648
> +'commit\n')
> +ui.warn(msg)
> +shelvedstate.clear(repo)

I think we can convert this `ui.warn()` to `error.Abort()` and hence get rid of 
`sys.exit()`. Send a standalone patch before this one which make this an error 
instead of warn.

> shelve.py:656
> +if not state:
> +statetuple = _loadshelvedstate(ui, repo, abortf=True)
> +state, opts = statetuple

nit: `state, opts = _loadshelvedstate(ui, repo, {'abort'=True})`

> shelve.py:658
> +state, opts = statetuple
> +with repo.wlock(), repo.lock():
>  try:

let's take `wlock()` only again when if we are processing `hg abort`. We can 
define this function as `unshelveabort(ui, repo, state, abortcommand=False)` 
and pass state as None, and abortcommand as True. When abortcommand is True, 
reassign state to new one and take wlock. Also make sure to release the wlock 
later in case of abortcommand.

> shelve.py:896
>  
> -try:
> -state = shelvedstate.load(repo)
> -if opts.get('keep') is None:
> -opts['keep'] = state.keep
> -except IOError as err:
> -if err.errno != errno.ENOENT:
> -raise
> -cmdutil.wrongtooltocontinue(repo, _('unshelve'))
> -except error.CorruptedState as err:
> -ui.debug(pycompat.bytestr(err) + '\n')
> -if continuef:
> -msg = _('corrupted shelved state file')
> -hint = _('please run hg unshelve --abort to abort unshelve '
> - 'operation')
> -raise error.Abort(msg, hint=hint)
> -elif abortf:
> -msg = _('could not read shelved state file, your working 
> copy '
> -'may be in an unexpected state\nplease update to 
> some '
> -'commit\n')
> -ui.warn(msg)
> -shelvedstate.clear(repo)
> -return
> +statetuple = _loadshelvedstate(ui, repo, continuef=continuef,
> +   abortf=abortf, **opts)

same as a comment above related to directly assigning it to `state, opts`

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-09 Thread taapas1128 (Taapas Agrawal)
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15833.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15806=15833

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,14 +710,16 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   could not read shelved state file, your working copy may be in an unexpected 
state
   please update to some commit
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge in progress but does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -822,7 +839,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -841,7 +858,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,37 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif abortf:
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+sys.exit()
+return (state, opts)
+
+def unshelveabort(ui, repo, state=None):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if not state:
+statetuple = _loadshelvedstate(ui, repo, abortf=True)
+state, opts = statetuple
+with repo.wlock(), repo.lock():
 try:
 checkparents(repo, state)
 
@@ -864,31 +893,12 @@
 if abortf and opts.get('tool', False):
 ui.warn(_('tool option will be ignored\n'))
 
-try:
-state = shelvedstate.load(repo)
-if opts.get('keep') is None:
-opts['keep'] = state.keep
-except IOError as err:
-if err.errno != errno.ENOENT:
-raise
-cmdutil.wrongtooltocontinue(repo, 

D6579: abort: added support for unshelve

2019-07-08 Thread taapas1128 (Taapas Agrawal)
taapas1128 added a comment.


  @mharbison72 Thanks for the suggestions. I have amended the patch accordingly.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-08 Thread taapas1128 (Taapas Agrawal)
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15806.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15781=15806

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,5 @@
 #testcases stripbased phasebased
+#testcases abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +20,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +293,14 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,14 +710,16 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   could not read shelved state file, your working copy may be in an unexpected 
state
   please update to some commit
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge does not support 'hg abort' (no-abortflag !)
+  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
   [255]
   $ cd ..
 
@@ -822,7 +839,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -841,7 +858,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,37 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif abortf:
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+sys.exit()
+return (state, opts)
+
+def unshelveabort(ui, repo, state=None, **opts):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if not state:
+statetuple = _loadshelvedstate(ui, repo, abortf=True, **opts)
+state, opts = statetuple
+with repo.wlock(), repo.lock():
 try:
 checkparents(repo, state)
 
@@ -864,31 +893,12 @@
 if abortf and opts.get('tool', False):
 ui.warn(_('tool option will be ignored\n'))
 
-try:
-state = shelvedstate.load(repo)
-if opts.get('keep') is None:
-opts['keep'] = state.keep
-except IOError as err:
-if err.errno != errno.ENOENT:
-raise
-cmdutil.wrongtooltocontinue(repo, 

D6579: abort: added support for unshelve

2019-07-08 Thread mharbison72 (Matt Harbison)
mharbison72 added inline comments.

INLINE COMMENTS

> test-shelve2.t:1
> -#testcases stripbased phasebased
> +#testcases stripbased phasebased abortflag abortcommand
>  

Shouldn't these be 2 lines, to maximize the test coverage?  Presumably 
`--abort` and `hg abort` can work with either phase or strip based shelving.  
See test-narrow.t, or some of the lfs tests.

  #testcases stripbased phasebased
  #testcases abortflag abortcommand

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-08 Thread mharbison72 (Matt Harbison)
mharbison72 added inline comments.

INLINE COMMENTS

> test-shelve2.t:734
> +  abort: merge does not support 'hg abort' (stripbased !)
> +  (use 'hg commit' or 'hg merge --abort') (stripbased !)
>[255]

I think that you can eliminate the duplication with this:

  abort: no unshelve in progress (abortflag !)
  abort: merge does not support 'hg abort' (no-abortflag !)
  (use 'hg commit' or 'hg merge --abort') (no-abortflag !)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: mharbison72, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-06 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15781.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15768=15781

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,4 @@
-#testcases stripbased phasebased
+#testcases stripbased phasebased abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +19,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +292,23 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  unshelve in progress, will be aborted
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: aborting unshelve does not support no-backup flag
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  unshelve in progress, will be aborted
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,14 +718,20 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   could not read shelved state file, your working copy may be in an unexpected 
state
   please update to some commit
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge does not support 'hg abort' (abortcommand !)
+  (use 'hg commit' or 'hg merge --abort') (abortcommand !)
+  abort: merge does not support 'hg abort' (phasebased !)
+  (use 'hg commit' or 'hg merge --abort') (phasebased !)
+  abort: merge does not support 'hg abort' (stripbased !)
+  (use 'hg commit' or 'hg merge --abort') (stripbased !)
   [255]
   $ cd ..
 
@@ -822,7 +851,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -841,7 +870,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,40 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif abortf:
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+sys.exit()
+return (state, opts)
+
+def unshelveabort(ui, repo, state=None, **opts):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if opts.get('no_backup'):
+raise error.Abort(_("aborting unshelve does not support no-backup"
+" flag"))
+if not state:
+statetuple = 

D6579: abort: added support for unshelve

2019-07-04 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15768.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15756=15768

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-shelve2.t

CHANGE DETAILS

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -1,4 +1,4 @@
-#testcases stripbased phasebased
+#testcases stripbased phasebased abortflag abortcommand
 
   $ cat <> $HGRCPATH
   > [extensions]
@@ -19,6 +19,13 @@
 
 #endif
 
+#if abortflag
+  $ cat >> $HGRCPATH < [alias]
+  > abort = unshelve --abort
+  > EOF
+#endif
+
 shelve should leave dirstate clean (issue4055)
 
   $ hg init shelverebase
@@ -285,7 +292,25 @@
   >>> working-copy: aef214a5229c - shelve: changes to: commit stuff
   $ cat f.orig
   g
-  $ hg unshelve --abort
+
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  aborting unshelve
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: unshelve does not support no-backup flag
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  aborting unshelve
+  abort: unshelve does not support no-backup flag
+  [255]
+#endif
+
+  $ hg abort
   unshelve of 'default' aborted
   $ hg st
   ? f.orig
@@ -695,14 +720,20 @@
   [255]
 
 Unshelve --abort works with a corrupted shelvedstate
-  $ hg unshelve --abort
+  $ hg abort
   could not read shelved state file, your working copy may be in an unexpected 
state
   please update to some commit
 
 Unshelve --abort fails with appropriate message if there's no unshelve in
 progress
-  $ hg unshelve --abort
-  abort: no unshelve in progress
+  $ hg abort
+  abort: no unshelve in progress (abortflag !)
+  abort: merge does not support 'hg abort' (abortcommand !)
+  (use 'hg commit' or 'hg merge --abort') (abortcommand !)
+  abort: merge does not support 'hg abort' (phasebased !)
+  (use 'hg commit' or 'hg merge --abort') (phasebased !)
+  abort: merge does not support 'hg abort' (stripbased !)
+  (use 'hg commit' or 'hg merge --abort') (stripbased !)
   [255]
   $ cd ..
 
@@ -822,7 +853,7 @@
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
   [1]
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 Unshelve without .shelve metadata (can happen when upgrading a repository with 
old shelve)
@@ -841,7 +872,7 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
-  $ hg unshelve --abort
+  $ hg abort
   unshelve of 'default' aborted
 
 #endif
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,41 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif abortf:
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+sys.exit()
+return (state, opts)
+
+def unshelveabort(ui, repo, state=None, **opts):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if opts.get('no_backup'):
+raise error.Abort(_("unshelve does not support no-backup flag"))
+if opts.get('dry_run'):
+return 0
+if not state:
+   

D6579: abort: added support for unshelve

2019-07-04 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15756.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15753=15756

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-abort.t

CHANGE DETAILS

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -1,9 +1,8 @@
-TEST `hg abort` operation rebase
-
   $ cat >> $HGRCPATH < [extensions]
   > rebase=
-  > 
+  > shelve=
+  > mq =
   > [phases]
   > publish=False
   > 
@@ -11,7 +10,7 @@
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
 
-
+TEST `hg abort` operation rebase
   $ hg init a
   $ cd a
 
@@ -630,3 +629,95 @@
   cannot clean up public changesets 6ec71c037d94
   graft aborted
   working directory is now at 6ec71c037d94
+  $ cd ..
+
+###TEST `hg abort` operation unshelve
+
+Prepare unshelve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve abort works with a corrupted shelvedstate
+  $ hg abort
+  could not read shelved state file, your working copy may be in an unexpected 
state
+  please update to some commit
+
+Unshelve abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg abort
+  abort: merge does not support 'hg abort'
+  (use 'hg commit' or 'hg merge --abort')
+  [255]
+  $ cd ..
+
+Abort due to pending changes
+  $ hg init onlypendingchanges
+  $ cd onlypendingchanges
+  $ touch a
+  $ hg ci -Aqm a
+  $ echo f > f
+  $ hg add f
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo g > f
+  $ echo 1 > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging f
+  warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg st
+  M f
+  ? f.orig
+  $ cat f
+  <<< shelve:   f0be9a229575 - shelve: pending changes temporary commit
+  g
+  ===
+  f
+  >>> working-copy: 7d4133053e12 - shelve: changes to: a
+  $ cat f.orig
+  g
+  $ hg ci a -m 'intermediate other change'
+  abort: unshelve already in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+
+when in dry-run mode
+  $ hg abort --dry-run
+  aborting unshelve
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: unshelve does not support no-backup flag
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  aborting unshelve
+  abort: unshelve does not support no-backup flag
+  [255]
+
+normal abort
+  $ hg abort
+  unshelve of 'default' aborted
+  $ cd ..
+
+
+
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,41 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+msg = _('corrupted shelved state file')
+hint = _('please run hg unshelve --abort to abort unshelve '
+ 'operation')
+raise error.Abort(msg, hint=hint)
+elif abortf:
+ 

D6579: abort: added support for unshelve

2019-07-04 Thread taapas1128 (Taapas Agrawal)
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15753.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15734=15756

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-abort.t

CHANGE DETAILS

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -1,9 +1,8 @@
-TEST `hg abort` operation rebase
-
   $ cat >> $HGRCPATH < [extensions]
   > rebase=
-  > 
+  > shelve=
+  > mq =
   > [phases]
   > publish=False
   > 
@@ -11,7 +10,7 @@
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
 
-
+TEST `hg abort` operation rebase
   $ hg init a
   $ cd a
 
@@ -630,3 +629,95 @@
   cannot clean up public changesets 6ec71c037d94
   graft aborted
   working directory is now at 6ec71c037d94
+  $ cd ..
+
+###TEST `hg abort` operation unshelve
+
+Prepare unshelve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve abort works with a corrupted shelvedstate
+  $ hg abort
+  could not read shelved state file, your working copy may be in an unexpected 
state
+  please update to some commit
+
+Unshelve abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg abort
+  abort: merge does not support 'hg abort'
+  (use 'hg commit' or 'hg merge --abort')
+  [255]
+  $ cd ..
+
+Abort due to pending changes
+  $ hg init onlypendingchanges
+  $ cd onlypendingchanges
+  $ touch a
+  $ hg ci -Aqm a
+  $ echo f > f
+  $ hg add f
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo g > f
+  $ echo 1 > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging f
+  warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg st
+  M f
+  ? f.orig
+  $ cat f
+  <<< shelve:   f0be9a229575 - shelve: pending changes temporary commit
+  g
+  ===
+  f
+  >>> working-copy: 7d4133053e12 - shelve: changes to: a
+  $ cat f.orig
+  g
+  $ hg ci a -m 'intermediate other change'
+  abort: unshelve already in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+
+when in dry-run mode
+  $ hg abort --dry-run
+  aborting unshelve
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: unshelve does not support no-backup flag
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  aborting unshelve
+  abort: unshelve does not support no-backup flag
+  [255]
+
+normal abort
+  $ hg abort
+  unshelve of 'default' aborted
+  $ cd ..
+
+
+
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@
 import errno
 import itertools
 import stat
+import sys
 
 from .i18n import _
 from . import (
@@ -624,9 +625,41 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def _loadshelvedstate(ui, repo, continuef=False, abortf=False, **opts):
+if abortf and opts.get('no_backup'):
+raise error.Abort(_("unshelve does not support no-backup flag"))
+if abortf and opts.get('dry_run'):
+sys.exit()
+try:
+state = shelvedstate.load(repo)
+if opts.get('keep') is None:
+opts['keep'] = state.keep
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+if continuef:
+

D6579: abort: added support for unshelve

2019-07-04 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> shelve.py:630
> +if not state:
> +try:
> +state = shelvedstate.load(repo)

Let's take this code out into a new function and reuse that function at both 
the places instead of duplicating code.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-07-04 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15734.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15666=15756

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  mercurial/state.py
  tests/test-abort.t

CHANGE DETAILS

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -1,9 +1,8 @@
-TEST `hg abort` operation rebase
-
   $ cat >> $HGRCPATH < [extensions]
   > rebase=
-  > 
+  > shelve=
+  > mq =
   > [phases]
   > publish=False
   > 
@@ -11,7 +10,7 @@
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
 
-
+TEST `hg abort` operation rebase
   $ hg init a
   $ cd a
 
@@ -630,3 +629,95 @@
   cannot clean up public changesets 6ec71c037d94
   graft aborted
   working directory is now at 6ec71c037d94
+  $ cd ..
+
+###TEST `hg abort` operation unshelve
+
+Prepare unshelve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve abort works with a corrupted shelvedstate
+  $ hg abort
+  could not read shelved state file, your working copy may be in an unexpected 
state
+  please update to some commit
+
+Unshelve abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg abort
+  abort: merge does not support 'hg abort'
+  (use 'hg commit' or 'hg merge --abort')
+  [255]
+  $ cd ..
+
+Abort due to pending changes
+  $ hg init onlypendingchanges
+  $ cd onlypendingchanges
+  $ touch a
+  $ hg ci -Aqm a
+  $ echo f > f
+  $ hg add f
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo g > f
+  $ echo 1 > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging f
+  warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg st
+  M f
+  ? f.orig
+  $ cat f
+  <<< shelve:   f0be9a229575 - shelve: pending changes temporary commit
+  g
+  ===
+  f
+  >>> working-copy: 7d4133053e12 - shelve: changes to: a
+  $ cat f.orig
+  g
+  $ hg ci a -m 'intermediate other change'
+  abort: unshelve already in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+
+when in dry-run mode
+  $ hg abort --dry-run
+  abort: aborting unshelve
+  [255]
+
+when in no-backup mode
+  $ hg abort --no-backup
+  abort: unshelve does not support no-backup
+  [255]
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  abort: unshelve does not support no-backup
+  [255]
+
+normal abort
+  $ hg abort
+  unshelve of 'default' aborted
+  $ cd ..
+
+
+
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -194,10 +194,6 @@
 _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
-'unshelve', fname='shelvedstate', continueflag=True,
-cmdmsg=_('unshelve already in progress')
-)
-addunfinished(
 'update', fname='updatestate', clearable=True,
 cmdmsg=_('last update was interrupted'),
 cmdhint=_("use 'hg update' to get a consistent checkout"),
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -624,9 +624,25 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def unshelveabort(ui, repo, state=None):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if not state:
+try:
+state = shelvedstate.load(repo)
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+return
+
+with repo.wlock(), repo.lock():
 try:
 checkparents(repo, state)
 
@@ -888,7 

D6579: abort: added support for unshelve

2019-07-04 Thread taapas1128 (Taapas Agrawal)
taapas1128 added a comment.


  I have rebased it.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-06-30 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  This patch needs to be rebased on tip of hg-committed as shelve is in core 
now.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

To: taapas1128, #hg-reviewers
Cc: pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-06-26 Thread taapas1128 (Taapas Agrawal)
taapas1128 updated this revision to Diff 15666.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6579?vs=15665=15666

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  hgext/shelve.py
  tests/test-abort.t

CHANGE DETAILS

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -1,9 +1,8 @@
-TEST `hg abort` operation rebase
-
   $ cat >> $HGRCPATH < [extensions]
   > rebase=
-  > 
+  > shelve=
+  > mq =
   > [phases]
   > publish=False
   > 
@@ -11,7 +10,7 @@
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
 
-
+TEST `hg abort` operation rebase
   $ hg init a
   $ cd a
 
@@ -597,8 +596,78 @@
   cannot clean up public changesets 6ec71c037d94
   graft aborted
   working directory is now at 6ec71c037d94
-
-
-
-
-
+  $ cd ..
+
+###TEST `hg abort` operation unshelve
+
+Prepare unshelve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve abort works with a corrupted shelvedstate
+  $ hg abort
+  could not read shelved state file, your working copy may be in an unexpected 
state
+  please update to some commit
+
+Unshelve abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg abort
+  abort: merge does not support 'hg abort'
+  (use 'hg commit' or 'hg merge --abort')
+  [255]
+  $ cd ..
+
+Abort due to pending changes
+  $ hg init onlypendingchanges
+  $ cd onlypendingchanges
+  $ touch a
+  $ hg ci -Aqm a
+  $ echo f > f
+  $ hg add f
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo g > f
+  $ echo 1 > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging f
+  warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg st
+  M f
+  ? f.orig
+  $ cat f
+  <<< shelve:   f0be9a229575 - shelve: pending changes temporary commit
+  g
+  ===
+  f
+  >>> working-copy: 7d4133053e12 - shelve: changes to: a
+  $ cat f.orig
+  g
+  $ hg ci a -m 'intermediate other change'
+  abort: unshelve already in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+  $ hg abort
+  unshelve of 'default' aborted
+  $ cd ..
+
+
+
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -645,9 +645,25 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
+def unshelveabort(ui, repo, state=None):
 """subcommand that abort an in-progress unshelve"""
-with repo.lock():
+if not state:
+try:
+state = shelvedstate.load(repo)
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+return
+
+with repo.wlock(), repo.lock():
 try:
 checkparents(repo, state)
 
@@ -972,7 +988,7 @@
 return
 
 if abortf:
-return unshelveabort(ui, repo, state, opts)
+return unshelveabort(ui, repo, state)
 elif continuef:
 return unshelvecontinue(ui, repo, state, opts)
 elif len(shelved) > 1:
@@ -1140,6 +1156,6 @@
 def extsetup(ui):
 statemod.addunfinished(
 'unshelve', fname=shelvedstate._filename, continueflag=True,
-cmdmsg=_('unshelve already in progress')
+cmdmsg=_('unshelve already in progress'), abortfunc=unshelveabort
 )
 



To: taapas1128, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6579: abort: added support for unshelve

2019-06-26 Thread taapas1128 (Taapas Agrawal)
taapas1128 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch adds the support for shelve in `hg abort` plan.
  `unshelveabort()` has been modified for independent calls.
  
  Results are shown as tests.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6579

AFFECTED FILES
  hgext/shelve.py
  tests/test-abort.t

CHANGE DETAILS

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -1,9 +1,8 @@
-TEST `hg abort` operation rebase
-
   $ cat >> $HGRCPATH < [extensions]
   > rebase=
-  > 
+  > shelve=
+  > mq =
   > [phases]
   > publish=False
   > 
@@ -11,7 +10,7 @@
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
 
-
+TEST `hg abort` operation rebase
   $ hg init a
   $ cd a
 
@@ -597,8 +596,78 @@
   cannot clean up public changesets 6ec71c037d94
   graft aborted
   working directory is now at 6ec71c037d94
-
-
-
-
-
+  $ cd ..
+
+###TEST `hg abort` operation unshelve
+
+Prepare unshelve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve abort works with a corrupted shelvedstate
+  $ hg abort
+  could not read shelved state file, your working copy may be in an unexpected 
state
+  please update to some commit
+
+Unshelve abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg abort
+  abort: merge does not support 'hg abort'
+  (use 'hg commit' or 'hg merge --abort')
+  [255]
+  $ cd ..
+
+Abort due to pending changes
+  $ hg init onlypendingchanges
+  $ cd onlypendingchanges
+  $ touch a
+  $ hg ci -Aqm a
+  $ echo f > f
+  $ hg add f
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo g > f
+  $ echo 1 > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging f
+  warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg st
+  M f
+  ? f.orig
+  $ cat f
+  <<< shelve:   f0be9a229575 - shelve: pending changes temporary commit
+  g
+  ===
+  f
+  >>> working-copy: 7d4133053e12 - shelve: changes to: a
+  $ cat f.orig
+  g
+  $ hg ci a -m 'intermediate other change'
+  abort: unshelve already in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+  $ hg abort
+  unshelve of 'default' aborted
+  $ cd ..
+
+
+
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -645,9 +645,28 @@
 raise error.Abort(_('working directory parents do not match unshelve '
'state'))
 
-def unshelveabort(ui, repo, state, opts):
-"""subcommand that abort an in-progress unshelve"""
-with repo.lock():
+def unshelveabort(ui, repo, state=None):
+"""subcommand that abort an in-progress unshelve
+   flag abort determines abort is called as a flag
+   or 'hg abort'
+"""
+if not state:
+try:
+state = shelvedstate.load(repo)
+except IOError as err:
+if err.errno != errno.ENOENT:
+raise
+cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+except error.CorruptedState as err:
+ui.debug(pycompat.bytestr(err) + '\n')
+msg = _('could not read shelved state file, your working copy '
+'may be in an unexpected state\nplease update to some '
+'commit\n')
+ui.warn(msg)
+shelvedstate.clear(repo)
+return
+
+with repo.wlock(), repo.lock():
 try:
 checkparents(repo, state)
 
@@ -972,7 +991,7 @@
 return
 
 if abortf:
-return unshelveabort(ui, repo, state, opts)
+return unshelveabort(ui, repo, state)
 elif continuef:
 return unshelvecontinue(ui, repo, state, opts)
 elif len(shelved) > 1:
@@ -1140,6 +1159,6 @@
 def extsetup(ui):
 statemod.addunfinished(
 'unshelve', fname=shelvedstate._filename, continueflag=True,
-cmdmsg=_('unshelve already in progress')
+cmdmsg=_('unshelve already in progress'), abortfunc=unshelveabort
 )
 



To: taapas1128, #hg-reviewers
Cc: mercurial-devel