Patchwork [07,of,10] changelog: rely on transaction for finalization

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 28, 2014, 3:41 p.m.
Message ID <bdb9c60529bcda403e08.1414510881@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6486/
State Superseded
Commit 2d54aa5397cdb1c697673ba10b7618d5ac25c69e
Headers show

Comments

Pierre-Yves David - Oct. 28, 2014, 3:41 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1413619781 25200
#      Sat Oct 18 01:09:41 2014 -0700
# Branch stable
# Node ID bdb9c60529bcda403e081e07d8d4c835b3750299
# Parent  81fed2b4a62ebd04121d4e072bce6b26666e5f64
changelog: rely on transaction for finalization

Instead of calling `cl.finalize()` by hand (possibly at a bogus time) we
register it to the transaction during `delayupdate` and rely on `tr.close()` to
call it at the right time.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -720,12 +720,10 @@  def addchangegroup(repo, source, srctype
             # publishing only alter behavior during push
             #
             # strip should not touch boundary at all
             phases.retractboundary(repo, tr, targetphase, added)
 
-        # make changelog see real files again
-        cl.finalize(trp)
 
         tr.close()
 
         if changesets > 0:
             if srctype != 'strip':
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -3,10 +3,11 @@ 
 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import weakref
 from node import bin, hex, nullid
 from i18n import _
 import util, error, revlog, encoding
 
 _defaultextra = {'branch': 'default'}
@@ -237,12 +238,14 @@  class changelog(revlog.revlog):
                 self._delaybuf = []
                 self.opener = _delayopener(self._realopener, self.indexfile,
                                            self._delaybuf)
         self._delayed = True
         tr.addpending('cl-%i' % id(self), self._writepending)
+        trp = weakref.proxy(tr)
+        tr.addfinalize('cl-%i' % id(self), lambda: self._finalize(trp))
 
-    def finalize(self, tr):
+    def _finalize(self, tr):
         "finalize index updates"
         self._delayed = False
         self.opener = self._realopener
         # move redirected index data back into place
         if self._divert:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1439,11 +1439,10 @@  class localrepository(object):
                                    user, ctx.date(), ctx.extra().copy())
             p = lambda: tr.writepending() and self.root or ""
             xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
             self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
                       parent2=xp2, pending=p)
-            self.changelog.finalize(trp)
             # set the new commit is proper phase
             targetphase = subrepo.newcommitphase(self.ui, ctx)
             if targetphase:
                 # retract boundary do not alter parent changeset.
                 # if a parent have higher the resulting phase will