( )⚙ D10557 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer

This is an archive of the discontinued Mercurial Phabricator instance.

dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
ClosedPublic

Authored by SimonSapin on May 3 2021, 6:26 AM.

Details

Summary

… that has the contents of the .hg/dirstate file.
This only applies to the tree-based flavor of DirstateMap.

For now only the entire &[u8] slice is stored, so this is not useful yet.

Adding a lifetime parameter to the DirstateMap struct (in hg-core) makes
Python bindings non-trivial because we keep that struct in a Python object
that has a dynamic lifetime tied to Python’s reference-counting and GC.
As long as we keep the PyBytes that owns the borrowed bytes buffer next to
the borrowing struct, the buffer will live long enough for the borrows to stay
valid. However this relationship cannot be expressed in safe Rust code in a
way that would statisfy they borrow-checker. We use unsafe code to erase
that lifetime parameter, and encapsulate it in a safe abstraction similar to
the owning-ref crate: https://docs.rs/owning_ref/

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

SimonSapin created this revision.May 3 2021, 6:26 AM
Alphare accepted this revision.May 3 2021, 12:21 PM
Alphare added a subscriber: Alphare.

Note: Simon and I discussed this at length beforehand.

This revision is now accepted and ready to land.May 3 2021, 12:21 PM
baymax updated this revision to Diff 27633.May 6 2021, 12:04 PM

✅ refresh by Heptapod after a successful CI run (🐙 💚)