changeset 2624:fd602980f7ee

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 18 Jun 2017 03:23:46 +0530
parents a263f4c0f2ee
children 8f2901f4749e
files README hgext3rd/topic/__init__.py tests/test-topic.t
diffstat 3 files changed, 37 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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