Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commit.py @ 45257:5d0998ccedbb
commitctx: stop using weakref proxy for transaction
This weakref proxy was introduced in 2007 by 30d4d8985dd8.
If I understand it correctly, the logic at that time was relying on the
transaction destructor, triggered at garbage collection time to rollback failed
transaction. passing the object to sub function directly mean it would live in
the function scope and be trapped in the traceback on exception, leading to the
transaction rollback too late in some case.
Modern transaction usage use explicit opening and closing of transaction and no
longer rely on some internal reference counting details. So this weakref proxy
is no longer necessary. Absolutely no test are affected when we drop it.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 24 Jul 2020 12:52:32 +0200 |
parents | d056a131c93f |
children | f0d4d1343cb4 |
comparison
equal
deleted
inserted
replaced
45256:d056a131c93f | 45257:5d0998ccedbb |
---|---|
4 # GNU General Public License version 2 or any later version. | 4 # GNU General Public License version 2 or any later version. |
5 | 5 |
6 from __future__ import absolute_import | 6 from __future__ import absolute_import |
7 | 7 |
8 import errno | 8 import errno |
9 import weakref | |
10 | 9 |
11 from .i18n import _ | 10 from .i18n import _ |
12 from .node import ( | 11 from .node import ( |
13 hex, | 12 hex, |
14 nullid, | 13 nullid, |
60 if writechangesetcopy: | 59 if writechangesetcopy: |
61 p1copies = ctx.p1copies() | 60 p1copies = ctx.p1copies() |
62 p2copies = ctx.p2copies() | 61 p2copies = ctx.p2copies() |
63 filesadded, filesremoved = None, None | 62 filesadded, filesremoved = None, None |
64 with repo.lock(), repo.transaction(b"commit") as tr: | 63 with repo.lock(), repo.transaction(b"commit") as tr: |
65 trp = weakref.proxy(tr) | |
66 | |
67 if ctx.manifestnode(): | 64 if ctx.manifestnode(): |
68 # reuse an existing manifest revision | 65 # reuse an existing manifest revision |
69 repo.ui.debug(b'reusing known manifest\n') | 66 repo.ui.debug(b'reusing known manifest\n') |
70 mn = ctx.manifestnode() | 67 mn = ctx.manifestnode() |
71 files = ctx.files() | 68 files = ctx.files() |
100 if fctx is None: | 97 if fctx is None: |
101 removed.append(f) | 98 removed.append(f) |
102 else: | 99 else: |
103 added.append(f) | 100 added.append(f) |
104 m[f], is_touched = _filecommit( | 101 m[f], is_touched = _filecommit( |
105 repo, fctx, m1, m2, linkrev, trp, writefilecopymeta, | 102 repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, |
106 ) | 103 ) |
107 if is_touched: | 104 if is_touched: |
108 touched.append(f) | 105 touched.append(f) |
109 if writechangesetcopy and is_touched == 'added': | 106 if writechangesetcopy and is_touched == 'added': |
110 filesadded.append(f) | 107 filesadded.append(f) |
154 # one case where we might have files outside the narrowspec | 151 # one case where we might have files outside the narrowspec |
155 # at this point is merges, and we already error out in the | 152 # at this point is merges, and we already error out in the |
156 # case where the merge has files outside of the narrowspec, | 153 # case where the merge has files outside of the narrowspec, |
157 # so this is safe. | 154 # so this is safe. |
158 mn = mctx.write( | 155 mn = mctx.write( |
159 trp, | 156 tr, |
160 linkrev, | 157 linkrev, |
161 p1.manifestnode(), | 158 p1.manifestnode(), |
162 p2.manifestnode(), | 159 p2.manifestnode(), |
163 added, | 160 added, |
164 drop, | 161 drop, |
189 repo.changelog.delayupdate(tr) | 186 repo.changelog.delayupdate(tr) |
190 n = repo.changelog.add( | 187 n = repo.changelog.add( |
191 mn, | 188 mn, |
192 files, | 189 files, |
193 ctx.description(), | 190 ctx.description(), |
194 trp, | 191 tr, |
195 p1.node(), | 192 p1.node(), |
196 p2.node(), | 193 p2.node(), |
197 user, | 194 user, |
198 ctx.date(), | 195 ctx.date(), |
199 ctx.extra().copy(), | 196 ctx.extra().copy(), |