diff --git a/lib/src/copies.rs b/lib/src/copies.rs index 6b3da3c6c6..7ce3baceb5 100644 --- a/lib/src/copies.rs +++ b/lib/src/copies.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use std::pin::Pin; use std::task::{Context, Poll}; -use futures::Stream; +use futures::{ready, Stream}; use crate::backend::{BackendResult, CopyRecord}; use crate::merge::MergedTreeValue; @@ -121,28 +121,26 @@ impl Stream for CopiesTreeDiffStream<'_> { type Item = CopiesTreeDiffEntry; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.inner.as_mut().poll_next(cx).map(|option| { - option.map(|diff_entry| { - let Some(CopyRecord { source, .. }) = - self.copy_records.for_target(&diff_entry.path) - else { - return CopiesTreeDiffEntry { - source: diff_entry.path.clone(), - target: diff_entry.path, - value: diff_entry.value, - }; - }; - - CopiesTreeDiffEntry { - source: source.clone(), - target: diff_entry.path, - value: diff_entry.value.and_then(|(_, target_value)| { - self.source_tree - .path_value(source) - .map(|source_value| (source_value, target_value)) - }), - } - }) - }) + let Some(diff_entry) = ready!(self.inner.as_mut().poll_next(cx)) else { + return Poll::Ready(None); + }; + + let Some(CopyRecord { source, .. }) = self.copy_records.for_target(&diff_entry.path) else { + return Poll::Ready(Some(CopiesTreeDiffEntry { + source: diff_entry.path.clone(), + target: diff_entry.path, + value: diff_entry.value, + })); + }; + + Poll::Ready(Some(CopiesTreeDiffEntry { + source: source.clone(), + target: diff_entry.path, + value: diff_entry.value.and_then(|(_, target_value)| { + self.source_tree + .path_value(source) + .map(|source_value| (source_value, target_value)) + }), + })) } }