topics: make sure we commit on new parents while changing topics (issue5441)
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 18 Jun 2017 03:23:46 +0530
changeset 2624 fd602980f7ee
parent 2623 a263f4c0f2ee
child 2625 8f2901f4749e
topics: make sure we commit on new parents while changing topics (issue5441) While changing topics of a set of linear commits, we used to commit our new changesets with new topic on parents of its predecessor i.e. changeset before the topic change. If the topic of parent was also changed, that parent will become obsolete and hence resulting the cnew commit in unstable state. For a set of linear commits this repeats and we end up in a tree state as mentioned in the bug. This patch fixes the bug by checking whether the parent was obsoleted and if yes, commit on the new parent.
README
hgext3rd/topic/__init__.py
tests/test-topic.t
--- a/README	Sun Jun 18 03:20:52 2017 +0530
+++ b/README	Sun Jun 18 03:23:46 2017 +0530
@@ -121,6 +121,11 @@
 Changelog
 =========
 
+6.5.0 - in progress
+-------------------
+
+ - topic: fix issue5441 in the linear case,
+
 6.4.0 -- 2017-06-16
 -------------------
 
--- a/hgext3rd/topic/__init__.py	Sun Jun 18 03:20:52 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Sun Jun 18 03:23:46 2017 +0530
@@ -282,6 +282,10 @@
         l = repo.lock()
         txn = repo.transaction('rewrite-topics')
         try:
+            newp = None
+            oldp = None
+            p1 = None
+            p2 = None
             for c in repo.set('%r', change):
                 def filectxfn(repo, ctx, path):
                     try:
@@ -309,11 +313,25 @@
                 ui.debug('changing topic of %s from %s to %s\n' % (
                     c, oldtopic, newtopic))
                 ui.debug('fixedextra: %r\n' % fixedextra)
+                # 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()
                 mc = context.memctx(
-                    repo, (c.p1().node(), c.p2().node()), c.description(),
+                    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
                 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	Sun Jun 18 03:20:52 2017 +0530
+++ b/tests/test-topic.t	Sun Jun 18 03:23:46 2017 +0530
@@ -679,30 +679,28 @@
   changed topic on 2 changes
   please run hg evolve --rev "topic(changewat)" now
   $ hg log -Gr 'draft()'
-  o  changeset:   21:3c7d84fcabcd
+  o  changeset:   21:58e15a6365ca
   |  tag:         tip
   |  topic:       changewat
-  |  parent:      13:d91cd8fd490e
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  trouble:     unstable
   |  summary:     fran?
   |
-  | o  changeset:   20:a96ac830b62e
-  | |  topic:       changewat
-  | |  parent:      3:a53952faf762
+  o  changeset:   20:a96ac830b62e
+  |  topic:       changewat
+  |  parent:      3:a53952faf762
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     start on fran
+  |
+  | @  changeset:   19:b72b86a1f96b
+  | |  topic:       watwat
+  | |  parent:      13:d91cd8fd490e
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
-  | |  summary:     start on fran
+  | |  summary:     fran?
   | |
-  +---@  changeset:   19:b72b86a1f96b
-  | |    topic:       watwat
-  | |    parent:      13:d91cd8fd490e
-  | |    user:        test
-  | |    date:        Thu Jan 01 00:00:00 1970 +0000
-  | |    summary:     fran?
-  | |
-  x |  changeset:   13:d91cd8fd490e
+  | x  changeset:   13:d91cd8fd490e
   |/   topic:       wat
   |    parent:      3:a53952faf762
   |    user:        test