Add TreeMap::remove_between that can take abstract start and end points

This commit introduces a new adaptor trait for SeekTarget that works around
frustrating issues with lifetimes. It wraps the arguments in a newtype wrapper
that lives on the stack to avoid the lifetime getting extended to the caller
of the method.

This allows us to introduce a PathSuccessor object that can be passed as the
end argument of remove_between to remove a whole subtree.
This commit is contained in:
Nathan Sobo 2023-05-11 23:20:20 -06:00 committed by Mikayla Maki
parent 89352a2bdc
commit ee3637216e
No known key found for this signature in database
3 changed files with 94 additions and 114 deletions

View file

@ -54,7 +54,7 @@ use std::{
},
time::{Duration, SystemTime},
};
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet};
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet, PathDescendants};
use util::{paths::HOME, ResultExt, TakeUntilExt, TryFutureExt};
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
@ -3023,9 +3023,7 @@ impl BackgroundScanner {
snapshot.repository_entries.update(&work_dir, |entry| {
entry
.worktree_statuses
.remove_by(&repo_path, |stored_path| {
stored_path.starts_with(&repo_path)
})
.remove_range(&repo_path, &PathDescendants(&repo_path))
});
}