( )⚙ D152 repo: skip invalidation of changelog if it has 'delayed' changes (API)

This is an archive of the discontinued Mercurial Phabricator instance.

repo: skip invalidation of changelog if it has 'delayed' changes (API)
ClosedPublic

Authored by martinvonz on Jul 19 2017, 6:09 PM.

Details

Summary

The changelog object can store recently added revisions in memory
until the transaction is committed. We don't want to lose those
changes even if repo.invalidate(clearfilecache=True), so let's skip
the changelog when it has such 'delayed' changes.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

martinvonz created this revision.Jul 19 2017, 6:09 PM
quark added a subscriber: quark.Jul 19 2017, 6:14 PM

Could we call changelog._writepending() automatically to solve this problem?

In D152#2246, @quark wrote:

Could we call changelog._writepending() automatically to solve this problem?

Good question. I spent quite a lot of time trying to see if that would work. It was easy to get all tests to pass, but I couldn't get it to work with our extensions (and it didn't seem to be the extensions' faults). One problem was that cl.delayupdate() would happen again after repo.invalidate() and delayupdate() doesn't have a way of taking revisions already written to .a into account (it doesn't check if self._divert is set). Also, I think that writing to .a would mean that hooks would see changes they were not meant to see.

quark accepted this revision.Jul 25 2017, 12:40 PM

I think this is fine as a workaround now. It's better than losing data.

tests/test-context.py
185

Seems like f.write(b'4') is better.

indygreg accepted this revision as: indygreg.Jul 25 2017, 11:34 PM
indygreg added a subscriber: indygreg.

Aside from the test issue pointed out by @quark, I think this seems reasonable.

@martinvonz is correct that writing the .i.a file has hooks implications. We definitely need to keep the changes in memory.

I'm kinda surprised we haven't hit this bug in core. Unless you can find somewhere we can hit it, I'm leaning towards not taking this on stable.

FWIW, these are the kinds of caching bugs that I think a refactor of the repo class into immutable and mutable components can help prevent. The whole property cache mechanism for various things on localrepo is a bug's nest.

martinvonz marked an inline comment as done.Aug 8 2017, 12:29 AM
martinvonz updated this revision to Diff 619.

Can this be queued for default now?

tests/test-context.py
185

Oops, definitely. I also updated the line above for consistency. I don't know if other places should be updated, so I didn't.

This revision was automatically updated to reflect the committed changes.