Patchwork [4,of,5,topic-experiment] topics: use a dict for successors of changesets produced by topic change

login
register
mail settings
Submitter Pulkit Goyal
Date June 21, 2017, 2:09 a.m.
Message ID <fd9e563f9e2b12615231.1498010965@workspace>
Download mbox | patch
Permalink /patch/21570/
State Accepted
Headers show

Comments

Pulkit Goyal - June 21, 2017, 2:09 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1498009910 -19800
#      Wed Jun 21 07:21:50 2017 +0530
# Node ID fd9e563f9e2b12615231839c847f42a98b5581fd
# Parent  06359d495ef9cc44163a35e16ca763148053e69c
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.

Patch

diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -310,10 +310,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:
@@ -343,22 +342,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],))])