Skip to content

Commit

Permalink
rewrite: use MergedTree::diff_stream() when restoring from tree
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed Nov 5, 2023
1 parent 5b02987 commit 6a5615c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use futures::StreamExt;
use itertools::Itertools;
use pollster::FutureExt;
use tracing::instrument;

use crate::backend::{BackendError, BackendResult, CommitId, MergedTreeId, ObjectId};
Expand Down Expand Up @@ -83,10 +85,15 @@ pub fn restore_tree(
// TODO: We should be able to not traverse deeper in the diff if the matcher
// matches an entire subtree.
let mut tree_builder = MergedTreeBuilder::new(destination.id().clone());
for (repo_path, diff) in source.diff(destination, matcher) {
let (source_value, _destination_value) = diff?;
tree_builder.set_or_remove(repo_path, source_value);
async {
let mut diff_stream = source.diff_stream(destination, matcher);
while let Some((repo_path, diff)) = diff_stream.next().await {
let (source_value, _destination_value) = diff?;
tree_builder.set_or_remove(repo_path, source_value);
}
Ok::<(), BackendError>(())
}
.block_on()?;
tree_builder.write_tree(destination.store())
}
}
Expand Down

0 comments on commit 6a5615c

Please sign in to comment.