Skip to content

Commit

Permalink
remove repeat tree creation when history is being listed
Browse files Browse the repository at this point in the history
  • Loading branch information
krlvi committed Jun 11, 2024
1 parent 119107c commit a5f3649
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/gitbutler-core/src/ops/oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ impl Project {

let mut snapshots = Vec::new();

let mut wd_trees_cache: HashMap<git2::Oid, git2::Oid> = HashMap::new();

for commit_id in revwalk {
if snapshots.len() == limit {
break;
Expand All @@ -282,16 +284,22 @@ impl Project {
continue;
}

let wd_tree_id = tree_from_applied_vbranches(&repo, commit_id)?;
let wd_tree = repo.find_tree(wd_tree_id)?;
// Get tree id from cache or calculate it
let wd_tree_id = wd_trees_cache
.entry(commit_id)
.or_insert_with(|| tree_from_applied_vbranches(&repo, commit_id).unwrap());
let wd_tree = repo.find_tree(wd_tree_id.to_owned())?;

let details = commit
.message()
.and_then(|msg| SnapshotDetails::from_str(msg).ok());

if let Ok(parent) = commit.parent(0) {
let parent_wd_tree_id = tree_from_applied_vbranches(&repo, parent.id())?;
let parent_tree = repo.find_tree(parent_wd_tree_id)?;
// Get tree id from cache or calculate it
let parent_wd_tree_id = wd_trees_cache
.entry(parent.id())
.or_insert_with(|| tree_from_applied_vbranches(&repo, parent.id()).unwrap());
let parent_tree = repo.find_tree(parent_wd_tree_id.to_owned())?;

let diff = repo.diff_tree_to_tree(Some(&parent_tree), Some(&wd_tree), None)?;

Expand Down

0 comments on commit a5f3649

Please sign in to comment.