Skip to content

Commit 97e598f

Browse files
Use "populate" instead of "transpose" for pin filter
We didn't realize that we can use those existing functions instead of creating a new one. Going via pathstree() and populate() might not be the absolute best possible route, but those use memoization and should be much faster for repeated application that the transpose() which always needs to look at all paths.
1 parent 9f1585c commit 97e598f

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

josh-core/src/filter/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,12 +1543,14 @@ fn per_rev_filter(
15431543
)?;
15441544

15451545
let parent = transaction.repo().find_commit(parent)?;
1546-
let parent = parent.tree()?;
15471546

1548-
let pin_subtract = pin_subtract.tree();
1549-
let pin_overlay = tree::transpose(transaction, pin_subtract, &parent)?;
1547+
let pin_overlay = tree::populate(
1548+
transaction,
1549+
tree::pathstree("", pin_subtract.tree.id(), transaction)?.id(),
1550+
parent.tree_id(),
1551+
)?;
15501552

1551-
Some((pin_subtract.id(), pin_overlay.id()))
1553+
Some((pin_subtract.tree.id(), pin_overlay))
15521554
} else {
15531555
None
15541556
}

josh-core/src/filter/tree.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::*;
2-
use std::path::PathBuf;
32

43
use crate::cache::TransactionContext;
54
use crate::cache_stack::CacheStack;
@@ -890,7 +889,7 @@ pub fn repopulated_tree(
890889
populate(transaction, ipaths.id(), partial_tree.id())
891890
}
892891

893-
fn populate(
892+
pub fn populate(
894893
transaction: &cache::Transaction,
895894
paths: git2::Oid,
896895
content: git2::Oid,
@@ -1002,41 +1001,6 @@ pub fn get_blob(repo: &git2::Repository, tree: &git2::Tree, path: &Path) -> Stri
10021001
content.to_owned()
10031002
}
10041003

1005-
/// Compose a new tree by taking paths out of `paths`,
1006-
/// and actual blobs out of `blobs`.
1007-
pub fn transpose<'a>(
1008-
transaction: &'a cache::Transaction,
1009-
paths: &'a git2::Tree,
1010-
blobs: &'a git2::Tree,
1011-
) -> JoshResult<git2::Tree<'a>> {
1012-
use git2::build::TreeUpdateBuilder;
1013-
use git2::{TreeWalkMode, TreeWalkResult};
1014-
1015-
let mut builder = TreeUpdateBuilder::new();
1016-
1017-
paths.walk(TreeWalkMode::PostOrder, |path, entry| {
1018-
let path = PathBuf::from(path).join(entry.name().unwrap_or(""));
1019-
1020-
let entry = match blobs.get_path(&path) {
1021-
Ok(entry) => entry,
1022-
Err(e) if e.code() == git2::ErrorCode::NotFound => return TreeWalkResult::Ok,
1023-
Err(_) => return TreeWalkResult::Abort,
1024-
};
1025-
1026-
if entry.kind() != Some(git2::ObjectType::Blob) {
1027-
return TreeWalkResult::Ok;
1028-
}
1029-
1030-
builder.upsert(path, entry.id(), git2::FileMode::Blob);
1031-
TreeWalkResult::Ok
1032-
})?;
1033-
1034-
let repo = transaction.repo();
1035-
let tree = builder.create_updated(repo, &empty(repo))?;
1036-
1037-
Ok(repo.find_tree(tree)?)
1038-
}
1039-
10401004
pub fn empty_id() -> git2::Oid {
10411005
git2::Oid::from_str("4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap()
10421006
}

0 commit comments

Comments
 (0)