Patchwork D6679: unshelve: store information about interactive mode in shelvedstate

login
register
mail settings
Submitter phabricator
Date July 23, 2019, 7:32 p.m.
Message ID <differential-rev-PHID-DREV-nvclocduvsi2wqljscsb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41025/
State Superseded
Headers show

Comments

phabricator - July 23, 2019, 7:32 p.m.
navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is a follow-up patch to 5162753c4c14 <https://phab.mercurial-scm.org/rHG5162753c4c14c143e6be011b89d6567b5ef50d66>. This makes `unshelve`
  stores the information about interactive mode on conflicts.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/shelve.py
  tests/test-shelve.t

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-devel
phabricator - July 24, 2019, 8:57 a.m.
pulkit added inline comments.

INLINE COMMENTS

> shelve.py:181
> +    _shelvedinteractively = 'shelvedinteractively'
> +    _notshelvedinteractively = 'notshelvedinteractively'
>  

We are already in shelve code, so no need to prepend shelved to the name.

Also, we can only had `interactive` stored in the shelved state. If it's not present in the state file, we can assume we were not running interactive unshelve.

> shelve.py:842
>      # we'll be merging with, rebase it to be on top.
> -    interactive = opts.get('interactive')
> +    interactive = opts.get('interactive', False)
>      if tmpwctx.node() == shelvectx.p1().node() and not interactive:

unrequired change.

> shelve.py:938
>  
> -    if abortf or continuef and not interactive:
> +    if len(shelved) > 1:
> +        raise error.Abort(_('can only unshelve one change at a time'))

This change is unrelated to storing info about interactive in shelvedstate. Can you decouple this into a separate patch?

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - July 24, 2019, 12:06 p.m.
navaneeth.suresh added inline comments.
navaneeth.suresh marked 3 inline comments as done.

INLINE COMMENTS

> pulkit wrote in shelve.py:938
> This change is unrelated to storing info about interactive in shelvedstate. Can you decouple this into a separate patch?

Doing that right away!

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - July 24, 2019, 2:51 p.m.
pulkit added inline comments.

INLINE COMMENTS

> pulkit wrote in shelve.py:181
> We are already in shelve code, so no need to prepend shelved to the name.
> 
> Also, we can only had `interactive` stored in the shelved state. If it's not present in the state file, we can assume we were not running interactive unshelve.

The above comment is not done.

I meant, we don't need _noninteractive.

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - July 24, 2019, 5:20 p.m.
navaneeth.suresh added inline comments.
navaneeth.suresh marked an inline comment as done.

INLINE COMMENTS

> pulkit wrote in shelve.py:181
> The above comment is not done.
> 
> I meant, we don't need _noninteractive.

Done.

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - July 30, 2019, 4:10 p.m.
navaneeth.suresh added a comment.


  > mercurial/shelve.py:938: local variable 'interactive' is assigned to but never used
  > Maybe `--continue --interactive` has to be banned if the mode can't be
  > overridden by the command option.
  
  Noted. Created D6703 <https://phab.mercurial-scm.org/D6703>. Thanks!

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers, pulkit
Cc: yuja, pulkit, mercurial-devel

Patch

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1351,13 +1351,12 @@ 
   A
   B
   C
-  $ hg unshelve --continue -i <<EOF
+  $ hg unshelve --continue <<EOF
   > y
   > y
   > y
   > y
   > EOF
-  unshelving change 'default-01'
   diff --git a/bar1 b/bar1
   1 hunks, 1 lines changed
   examine changes to 'bar1'?
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -177,6 +177,8 @@ 
     _nokeep = 'nokeep'
     # colon is essential to differentiate from a real bookmark name
     _noactivebook = ':no-active-bookmark'
+    _shelvedinteractively = 'shelvedinteractively'
+    _notshelvedinteractively = 'notshelvedinteractively'
 
     @classmethod
     def _verifyandtransform(cls, d):
@@ -247,6 +249,8 @@ 
             obj.activebookmark = ''
             if d.get('activebook', '') != cls._noactivebook:
                 obj.activebookmark = d.get('activebook', '')
+            obj.shelvedinteractively = (d.get('shelvedinteractively')
+                                         == cls._shelvedinteractively)
         except (error.RepoLookupError, KeyError) as err:
             raise error.CorruptedState(pycompat.bytestr(err))
 
@@ -254,7 +258,7 @@ 
 
     @classmethod
     def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
-             branchtorestore, keep=False, activebook=''):
+             branchtorestore, keep=False, activebook='', shelvedinteractively=False):
         info = {
             "name": name,
             "originalwctx": nodemod.hex(originalwctx.node()),
@@ -265,7 +269,9 @@ 
                                       for n in nodestoremove]),
             "branchtorestore": branchtorestore,
             "keep": cls._keep if keep else cls._nokeep,
-            "activebook": activebook or cls._noactivebook
+            "activebook": activebook or cls._noactivebook,
+            "shelvedinteractively": (cls._shelvedinteractively
+                    if shelvedinteractively else cls._notshelvedinteractively)
         }
         scmutil.simplekeyvaluefile(
             repo.vfs, cls._filename).write(info,
@@ -698,7 +704,7 @@ 
     """subcommand to continue an in-progress unshelve"""
     # We're finishing off a merge. First parent is our original
     # parent, second is the temporary "fake" commit we're unshelving.
-    interactive = opts.get('interactive')
+    interactive = state.shelvedinteractively
     with repo.lock():
         checkparents(repo, state)
         ms = merge.mergestate.read(repo)
@@ -833,7 +839,7 @@ 
     """Rebase restored commit from its original location to a destination"""
     # If the shelve is not immediately on top of the commit
     # we'll be merging with, rebase it to be on top.
-    interactive = opts.get('interactive')
+    interactive = opts.get('interactive', False)
     if tmpwctx.node() == shelvectx.p1().node() and not interactive:
         # We won't skip on interactive mode because, the user might want to
         # unshelve certain changes only.
@@ -854,7 +860,8 @@ 
             nodestoremove = [repo.changelog.node(rev)
                              for rev in pycompat.xrange(oldtiprev, len(repo))]
             shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
-                              branchtorestore, opts.get('keep'), activebookmark)
+                              branchtorestore, opts.get('keep'), activebookmark,
+                              shelvedinteractively=interactive)
             raise error.InterventionRequired(
                 _("unresolved conflicts (see 'hg resolve', then "
                   "'hg unshelve --continue')"))
@@ -928,10 +935,21 @@ 
     if opts.get("name"):
         shelved.append(opts["name"])
 
-    if abortf or continuef and not interactive:
+    if len(shelved) > 1:
+        raise error.Abort(_('can only unshelve one change at a time'))
+    elif not shelved:
+        shelved = listshelves(repo)
+        if not shelved:
+            raise error.Abort(_('no shelved changes to apply!'))
+        basename = util.split(shelved[0][1])[1]
+        if not (abortf or continuef):
+            ui.status(_("unshelving change '%s'\n") % basename)
+    elif shelved:
+        basename = shelved[0]
+    if abortf or continuef:
         if abortf and continuef:
             raise error.Abort(_('cannot use both abort and continue'))
-        if shelved:
+        if opts.get("name"):
             raise error.Abort(_('cannot combine abort/continue with '
                                'naming a shelved change'))
         if abortf and opts.get('tool', False):
@@ -941,20 +959,7 @@ 
         if abortf:
             return unshelveabort(ui, repo, state)
         elif continuef:
-            return unshelvecontinue(ui, repo, state, opts)
-    elif len(shelved) > 1:
-        raise error.Abort(_('can only unshelve one change at a time'))
-    elif not shelved:
-        shelved = listshelves(repo)
-        if not shelved:
-            raise error.Abort(_('no shelved changes to apply!'))
-        basename = util.split(shelved[0][1])[1]
-        ui.status(_("unshelving change '%s'\n") % basename)
-    elif shelved:
-        basename = shelved[0]
-    if continuef and interactive:
-        state = _loadshelvedstate(ui, repo, opts)
-        return unshelvecontinue(ui, repo, state, opts, basename)
+            return unshelvecontinue(ui, repo, state, opts, basename)
 
     if not shelvedfile(repo, basename, patchextension).exists():
         raise error.Abort(_("shelved change '%s' not found") % basename)