Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 42696:36c692eb28d3
transaction: leave unfinished without crashing when not properly released
I think the transaction.__del__ is there just as a last resort in case
we (or an extension) forgot to release the transaction. When that
happens, the repo can (or will on Python 3?) get deleted before the
transaction. This leads to a crash in test-devel-warnings.t on Python
3 because we tried to access repo.dirstate, where repo was retried
from a weak reference. There's not much we can do here, but let's at
least avoid the crash. The user will have run `hg recover` afterwards
regardless.
Differential Revision: https://phab.mercurial-scm.org/D6664
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 21 Jul 2019 07:59:16 -0700 |
parents | 99ebde4fec99 |
children | 863e9e7f8850 |
comparison
equal
deleted
inserted
replaced
42695:52a383451739 | 42696:36c692eb28d3 |
---|---|
1891 | 1891 |
1892 repo.hook('pretxnclose', throw=True, | 1892 repo.hook('pretxnclose', throw=True, |
1893 **pycompat.strkwargs(tr.hookargs)) | 1893 **pycompat.strkwargs(tr.hookargs)) |
1894 def releasefn(tr, success): | 1894 def releasefn(tr, success): |
1895 repo = reporef() | 1895 repo = reporef() |
1896 if repo is None: | |
1897 # If the repo has been GC'd (and this release function is being | |
1898 # called from transaction.__del__), there's not much we can do, | |
1899 # so just leave the unfinished transaction there and let the | |
1900 # user run `hg recover`. | |
1901 return | |
1896 if success: | 1902 if success: |
1897 # this should be explicitly invoked here, because | 1903 # this should be explicitly invoked here, because |
1898 # in-memory changes aren't written out at closing | 1904 # in-memory changes aren't written out at closing |
1899 # transaction, if tr.addfilegenerator (via | 1905 # transaction, if tr.addfilegenerator (via |
1900 # dirstate.write or so) isn't invoked while | 1906 # dirstate.write or so) isn't invoked while |