diff -r 2e3f63f4a519 -r b5723184fc62 hgext3rd/topic/__init__.py --- 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],))])