topics: use a dict for successors of changesets produced by topic change
authorPulkit Goyal <7895pulkit@gmail.com>
Wed, 21 Jun 2017 07:21:50 +0530
changeset 2646 b5723184fc62
parent 2645 2e3f63f4a519
child 2647 b9cfb8bd0965
topics: use a dict for successors of changesets produced by topic change This patch adds a dictionary to store the successors of changesets which got obsoleted when we change it's topic. This is an improvement in the fix for issue5441.
hgext3rd/topic/__init__.py
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Wed Jun 21 11:55:45 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Wed Jun 21 07:21:50 2017 +0530
@@ -309,10 +309,9 @@
     l = repo.lock()
     txn = repo.transaction('rewrite-topics')
     try:
-        newp = None
-        oldp = None
         p1 = None
         p2 = None
+        successors = {}
         for c in repo.set('%r', revset):
             def filectxfn(repo, ctx, path):
                 try:
@@ -342,22 +341,18 @@
             # While changing topic of set of linear commits, make sure that
             # we base our commits on new parent rather than old parent which
             # was obsoleted while changing the topic
-            if newp and c.p1().node() == oldp:
-                p1 = newp
-                p2 = c.p2().node()
-            elif newp and c.p2().node() == oldp:
-                p1 = c.p1().node()
-                p2 = newp
-            else:
-                p1 = c.p1().node()
-                p2 = c.p2().node()
+            p1 = c.p1().node()
+            p2 = c.p2().node()
+            if p1 in successors:
+                p1 = successors[p1]
+            if p2 in successors:
+                p2 = successors[p2]
             mc = context.memctx(
                 repo, (p1, p2), c.description(),
                 c.files(), filectxfn,
                 user=c.user(), date=c.date(), extra=fixedextra)
             newnode = repo.commitctx(mc)
-            oldp = c.node()
-            newp = newnode
+            successors[c.node()] = newnode
             ui.debug('new node id is %s\n' % node.hex(newnode))
             needevolve = needevolve or (len(c.children()) > 0)
             obsolete.createmarkers(repo, [(c, (repo[newnode],))])
--- a/tests/test-topic.t	Wed Jun 21 11:55:45 2017 +0200
+++ b/tests/test-topic.t	Wed Jun 21 07:21:50 2017 +0530
@@ -707,3 +707,73 @@
   |    date:        Thu Jan 01 00:00:00 1970 +0000
   |    summary:     start on fran
   |
+
+Case with branching:
+
+  $ hg up changewat
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg up t1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo gamma >> gamma
+  $ hg ci -m gamma
+  $ hg log -Gr 'draft()'
+  @  changeset:   22:373f490f8854
+  |  tag:         tip
+  |  topic:       changewat
+  |  parent:      20:a96ac830b62e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     gamma
+  |
+  | o  changeset:   21:58e15a6365ca
+  |/   topic:       changewat
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     fran?
+  |
+  o  changeset:   20:a96ac830b62e
+  |  topic:       changewat
+  |  parent:      3:a53952faf762
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     start on fran
+  |
+  $ hg topics --rev 't1::' changewut
+  changed topic on 3 changes
+  please run hg evolve --rev "topic(changewut)" now
+  $ hg log -Gr 'draft()'
+  o  changeset:   25:05d1bf93e1d8
+  |  tag:         tip
+  |  topic:       changewut
+  |  parent:      23:1f668635e0c2
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     gamma
+  |
+  | o  changeset:   24:696f1024fbfb
+  |/   topic:       changewut
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     fran?
+  |
+  o  changeset:   23:1f668635e0c2
+  |  topic:       changewut
+  |  parent:      3:a53952faf762
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     start on fran
+  |
+  | @  changeset:   22:373f490f8854
+  | |  topic:       changewat
+  | |  parent:      20:a96ac830b62e
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     gamma
+  | |
+  | x  changeset:   20:a96ac830b62e
+  |/   topic:       changewat
+  |    parent:      3:a53952faf762
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     start on fran
+  |