Skip to content

Commit 469cf64

Browse files
committed
Store dirs cache in transaction
1 parent a162566 commit 469cf64

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/cache.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct Transaction2 {
5151
commit_map: HashMap<git2::Oid, HashMap<git2::Oid, git2::Oid>>,
5252
apply_map: HashMap<git2::Oid, HashMap<git2::Oid, git2::Oid>>,
5353
unapply_map: HashMap<git2::Oid, HashMap<git2::Oid, git2::Oid>>,
54+
dir_map: HashMap<(git2::Oid, String), git2::Oid>,
5455
sled_trees: HashMap<git2::Oid, sled::Tree>,
5556
missing: Vec<(filter::Filter, git2::Oid)>,
5657
misses: usize,
@@ -84,6 +85,7 @@ impl Transaction {
8485
commit_map: HashMap::new(),
8586
apply_map: HashMap::new(),
8687
unapply_map: HashMap::new(),
88+
dir_map: HashMap::new(),
8789
sled_trees: HashMap::new(),
8890
missing: vec![],
8991
misses: 0,
@@ -153,6 +155,11 @@ impl Transaction {
153155
.insert(from, to);
154156
}
155157

158+
pub fn insert_dir(&self, tree: (git2::Oid, String), result: git2::Oid) {
159+
let mut t2 = self.t2.borrow_mut();
160+
t2.dir_map.entry(tree).or_insert(result);
161+
}
162+
156163
pub fn insert_ref(
157164
&self,
158165
filter: filter::Filter,
@@ -194,6 +201,11 @@ impl Transaction {
194201
return None;
195202
}
196203

204+
pub fn get_dir(&self, tree: (git2::Oid, String)) -> Option<git2::Oid> {
205+
let t2 = self.t2.borrow_mut();
206+
return t2.dir_map.get(&tree).cloned();
207+
}
208+
197209
pub fn insert(
198210
&self,
199211
filter: filter::Filter,

src/filter/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,7 @@ fn apply2<'a>(
497497
Ok(repo.find_tree(tree::subtract(&repo, af.id(), ba.id())?)?)
498498
}
499499

500-
Op::Dirs => tree::dirtree(
501-
&repo,
502-
"",
503-
tree.id(),
504-
&mut std::collections::HashMap::new(),
505-
),
500+
Op::Dirs => tree::dirtree("", tree.id(), transaction),
506501

507502
Op::Workspace(path) => {
508503
let base = to_filter(Op::Subdir(path.to_owned()));

src/filter/tree.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use super::*;
22

33
pub fn dirtree<'a>(
4-
repo: &'a git2::Repository,
54
root: &str,
65
input: git2::Oid,
7-
cache: &mut std::collections::HashMap<(git2::Oid, String), git2::Oid>,
6+
transaction: &'a cache::Transaction,
87
) -> super::JoshResult<git2::Tree<'a>> {
9-
if let Some(cached) = cache.get(&(input, root.to_string())) {
10-
return Ok(repo.find_tree(*cached)?);
8+
let repo = transaction.repo();
9+
if let Some(cached) = transaction.get_dir((input, root.to_string())) {
10+
return Ok(repo.find_tree(cached)?);
1111
}
1212

1313
let tree = repo.find_tree(input)?;
@@ -32,15 +32,14 @@ pub fn dirtree<'a>(
3232

3333
if entry.kind() == Some(git2::ObjectType::Tree) {
3434
let s = dirtree(
35-
&repo,
3635
&format!(
3736
"{}{}{}",
3837
root,
3938
if root == "" { "" } else { "/" },
4039
entry.name().ok_or(super::josh_error("no name"))?
4140
),
4241
entry.id(),
43-
cache,
42+
transaction,
4443
)?
4544
.id();
4645

@@ -72,7 +71,7 @@ pub fn dirtree<'a>(
7271
&result,
7372
)?;
7473
}
75-
cache.insert((input, root.to_string()), result.id());
74+
transaction.insert_dir((input, root.to_string()), result.id());
7675
return Ok(result);
7776
}
7877

0 commit comments

Comments
 (0)