This is an archive of the discontinued Mercurial Phabricator instance.

rhg: Add support for `rhg status --copies`
ClosedPublic

Authored by SimonSapin on Dec 10 2021, 5:14 PM.

Details

Summary

Copy sources are collected during status() rather than after the fact like
in Python, because status() takes a &mut exclusive reference to the dirstate map
(in order to potentially mutate it for directory mtimes) and returns Cow<'_, HgPath>
that borrow the dirstate map.

Even though with Cow only some shared borrows remain, the still extend the same
lifetime of the initial &mut so the dirstate map cannot be borrowed again
to access copy sources after the fact:

https://doc.rust-lang.org/nomicon/lifetime-mismatch.html#limits-of-lifetimes

Additionally, collecting copy sources during the dirstate tree traversal that
status() already does avoids the cost of another traversal or other lookups
(though I haven’t benchmarked that cost).

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.Dec 10 2021, 5:14 PM
Alphare accepted this revision.Dec 13 2021, 8:18 AM
Alphare added a subscriber: Alphare.
Alphare added inline comments.
rust/hg-core/src/dirstate_tree/status.rs
151

I swear I had this enum somewhere. Maybe it got removed with the old flat dirstate implementation?

This revision is now accepted and ready to land.Dec 13 2021, 8:18 AM
This revision was automatically updated to reflect the committed changes.
SimonSapin added inline comments.Dec 13 2021, 8:40 AM
rust/hg-core/src/dirstate_tree/status.rs
151

Now that you say it that rings a bell, and yes it’s the likely explanation