# HG changeset patch
# User Sushil khanchi <sushilkhanchi97@gmail.com>
# Date 1540538680 -19800
# Node ID db70de7c1698308bf134218b3e2eb79f5225c861
# Parent  0e59b03afe0a22061a73aaf4ea0154cfaf8cab03
evolve: use stack template in --continue case also

We use stack indexes (s#) in evolve msging when revs being evolved are
in active topic. Before this patch we are not covering the --continue case.
So this patch cover the same and use the stack indexes s# even when we
continue an interrupted evolve.

In this patch I used the same concept (to check if we should use s#)
as we are using in cases other than `--continue`. Thanks to PYD for
refactoring those lines.
Changes in tests also reflects the expected behaviour.

diff -r 0e59b03afe0a -r db70de7c1698 hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Wed Oct 24 19:38:02 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Oct 26 12:54:40 2018 +0530
@@ -1747,14 +1747,25 @@
             # evolved to confirm that if atop msg should be suppressed to remove
             # redundancy
             lastsolved = None
+            activetopic = getattr(repo, 'currenttopic', '')
             for rev in evolvestate['revs']:
                 # XXX: prevent this lookup by storing nodes instead of revnums
                 curctx = unfi[rev]
+
+                # check if we can use stack template
+                revtopic = getattr(curctx, 'topic', lambda: '')()
+                topicidx = getattr(curctx, 'topicidx', lambda: None)()
+                stacktmplt = False
+                if (activetopic and (activetopic == revtopic) and
+                    topicidx is not None):
+                    stacktmplt = True
+
                 if (curctx.node() not in evolvestate['replacements'] and
                     curctx.node() not in evolvestate['skippedrevs']):
                     newnode = _solveone(ui, repo, curctx, evolvestate, False,
                                         confirm, progresscb, category,
-                                        lastsolved=lastsolved)
+                                        lastsolved=lastsolved,
+                                        stacktmplt=stacktmplt)
                     if newnode[0]:
                         evolvestate['replacements'][curctx.node()] = newnode[1]
                         lastsolved = newnode[1]
diff -r 0e59b03afe0a -r db70de7c1698 tests/test-evolve-topic.t
--- a/tests/test-evolve-topic.t	Wed Oct 24 19:38:02 2018 +0530
+++ b/tests/test-evolve-topic.t	Fri Oct 26 12:54:40 2018 +0530
@@ -382,8 +382,8 @@
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   [s3] add eee
 
-Test showing that currently stackaliases does not support --continue case
--------------------------------------------------------------------------
+Check stackaliases(s#) works with  --continue case also, while evolving:
+------------------------------------------------------------------------
   $ hg up 18
   switching to topic bar
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -437,7 +437,7 @@
   continue: hg evolve --continue
   $ hg evolve --continue
   evolving 23:7acd9ea5d677 "add hhh"
-  move:[24] add iii
-  atop:[28] add hhh
-  move:[25] add jjj
+  move:[s4] add iii
+  atop:[s3] add hhh
+  move:[s5] add jjj
   working directory is now at 119e4c126fb2