From patchwork Sun Nov 2 14:20:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5,of,5] changelog: rely on transaction for finalization From: Pierre-Yves David X-Patchwork-Id: 6527 Message-Id: <3270e2ef0b7d74003e49.1414938043@marginatus.alto.octopoid.net> To: mercurial-devel@selenic.com Cc: Pierre-Yves David Date: Sun, 02 Nov 2014 14:20:43 +0000 # HG changeset patch # User Pierre-Yves David # Date 1413619781 25200 # Sat Oct 18 01:09:41 2014 -0700 # Node ID 3270e2ef0b7d74003e49fcdec588763c258a1038 # Parent d434fffe10dac3cb137b3695426a69a4cef9ef35 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. 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 # # 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 @@ -1443,11 +1443,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