tree_builder: initialize base trees with the root entry

This helps to rewrite populate_trees() as recursive function call.
This commit is contained in:
Yuya Nishihara 2023-06-01 10:39:56 +09:00
parent 7cf96bcae0
commit 941f41e62e

View file

@ -115,17 +115,15 @@ impl TreeBuilder {
}
fn get_base_trees(&self) -> BTreeMap<RepoPath, backend::Tree> {
let mut tree_cache = BTreeMap::new();
let store = self.store.clone();
let mut tree_cache = {
let dir = RepoPath::root();
let tree = store.get_tree(&dir, &self.base_tree_id).unwrap();
BTreeMap::from([(dir, tree)])
};
let mut populate_trees = |dir: &RepoPath| {
let mut current_dir = RepoPath::root();
if !tree_cache.contains_key(&current_dir) {
let tree = store.get_tree(&current_dir, &self.base_tree_id).unwrap();
tree_cache.insert(current_dir.clone(), tree);
}
for component in dir.components() {
let next_dir = current_dir.join(component);
let current_tree = tree_cache.get(&current_dir).unwrap();