Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 43778:888bd39ed555
lock: pass "success" boolean to _afterlock callbacks
This lets the callback decide if it should actually run or not. I suspect that
most callbacks (and hooks) *should not* run in this scenario, but I'm trying
to not break any existing behavior. `persistmanifestcache`, however, seems
actively dangerous to run: we just encountered an exception and the repo is in
an unknown state (hopefully a consistent one due to transactions, but this is
not 100% guaranteed), and the data we cache may be based on this unknown
state.
This was observed by our users since we wrap some of the functions that
persistmanifestcache calls and it expects that the repo object is in a certain
state that we'd set up earlier. If the user hits ctrl-c before we establish
that state, we end up crashing there. I'm going to make that extension
resilient to this issue, but figured it might be a common issue and should be
handled here as well instead of just working around the issue.
Differential Revision: https://phab.mercurial-scm.org/D7459
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Tue, 19 Nov 2019 18:38:17 -0800 |
parents | e89e3275f658 |
children | 8042856c90b6 |
comparison
equal
deleted
inserted
replaced
43777:c8e9a3636abe | 43778:888bd39ed555 |
---|---|
2201 # This reduces memory consumption when there are multiple | 2201 # This reduces memory consumption when there are multiple |
2202 # transactions per lock. This can likely go away if issue5045 | 2202 # transactions per lock. This can likely go away if issue5045 |
2203 # fixes the function accumulation. | 2203 # fixes the function accumulation. |
2204 hookargs = tr2.hookargs | 2204 hookargs = tr2.hookargs |
2205 | 2205 |
2206 def hookfunc(): | 2206 def hookfunc(unused_success): |
2207 repo = reporef() | 2207 repo = reporef() |
2208 if hook.hashook(repo.ui, b'txnclose-bookmark'): | 2208 if hook.hashook(repo.ui, b'txnclose-bookmark'): |
2209 bmchanges = sorted(tr.changes[b'bookmarks'].items()) | 2209 bmchanges = sorted(tr.changes[b'bookmarks'].items()) |
2210 for name, (old, new) in bmchanges: | 2210 for name, (old, new) in bmchanges: |
2211 args = tr.hookargs.copy() | 2211 args = tr.hookargs.copy() |
2613 l = ref and ref() | 2613 l = ref and ref() |
2614 if l and l.held: | 2614 if l and l.held: |
2615 l.postrelease.append(callback) | 2615 l.postrelease.append(callback) |
2616 break | 2616 break |
2617 else: # no lock have been found. | 2617 else: # no lock have been found. |
2618 callback() | 2618 callback(True) |
2619 | 2619 |
2620 def lock(self, wait=True): | 2620 def lock(self, wait=True): |
2621 '''Lock the repository store (.hg/store) and return a weak reference | 2621 '''Lock the repository store (.hg/store) and return a weak reference |
2622 to the lock. Use this before modifying the store (e.g. committing or | 2622 to the lock. Use this before modifying the store (e.g. committing or |
2623 stripping). If you are opening a transaction, get a lock as well.) | 2623 stripping). If you are opening a transaction, get a lock as well.) |
2951 self.ui.write( | 2951 self.ui.write( |
2952 _(b'note: commit message saved in %s\n') % msgfn | 2952 _(b'note: commit message saved in %s\n') % msgfn |
2953 ) | 2953 ) |
2954 raise | 2954 raise |
2955 | 2955 |
2956 def commithook(): | 2956 def commithook(unused_success): |
2957 # hack for command that use a temporary commit (eg: histedit) | 2957 # hack for command that use a temporary commit (eg: histedit) |
2958 # temporary commit got stripped before hook release | 2958 # temporary commit got stripped before hook release |
2959 if self.changelog.hasnode(ret): | 2959 if self.changelog.hasnode(ret): |
2960 self.hook( | 2960 self.hook( |
2961 b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 | 2961 b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 |
3397 self.ui.write_err(_(b"(%s)\n") % exc.hint) | 3397 self.ui.write_err(_(b"(%s)\n") % exc.hint) |
3398 return False | 3398 return False |
3399 self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) | 3399 self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) |
3400 ret = pushkey.push(self, namespace, key, old, new) | 3400 ret = pushkey.push(self, namespace, key, old, new) |
3401 | 3401 |
3402 def runhook(): | 3402 def runhook(unused_success): |
3403 self.hook( | 3403 self.hook( |
3404 b'pushkey', | 3404 b'pushkey', |
3405 namespace=namespace, | 3405 namespace=namespace, |
3406 key=key, | 3406 key=key, |
3407 old=old, | 3407 old=old, |