( )⚙ D10913 rhg: refactor relative path resolution in utility fn

This is an archive of the discontinued Mercurial Phabricator instance.

rhg: refactor relative path resolution in utility fn
AbandonedPublic

Authored by pulkit on Jun 25 2021, 1:47 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

The same code is being used in rhg files and rhg status and I expect it to
be used at more places in upcoming future. So let's have a utility function for
that.

rhg files still doesn't use this codepath but will start using in upcoming
patches.

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

pulkit created this revision.Jun 25 2021, 1:47 PM
SimonSapin added inline comments.
rust/rhg/src/commands/status.rs
293

Since this now only used once it can be moved into the relativize_paths call without assigning to a variable. This gives "more local" information to type inference, so type annotations in the closure signature won’t be needed anymore.

rust/rhg/src/utils/path_utils.rs
17

In order not to force callers to allocate a Vec of of Cows just to call this, the parameter could be made a generic iterable of generic items:

paths: impl IntoIterator<Item = impl AsRef<HgPath>>

Then in the for loop below use file.as_ref() to go from the generic item type to &HgPath.

18

There is no need for dynamic dispatch here. Replacing &dyn Fn with impl Fn will let the compiler inline and optimize for each specific callback.

21–23

This is from code that I originally wrote, but even though in mercurial we talk about a repository’s "working directory", this code is slightly confusing because cwd also means "current working directory" but is not necessarily the same directory.

Maybe rename working_directory to something like repo_root?

pulkit planned changes to this revision.Oct 5 2021, 7:51 AM
pulkit abandoned this revision.Oct 5 2021, 8:49 AM

Superseeded by D11613.