gix_diff

Function tree_with_rewrites

Source
pub fn tree_with_rewrites<E>(
    lhs: TreeRefIter<'_>,
    rhs: TreeRefIter<'_>,
    resource_cache: &mut Platform,
    tree_diff_state: &mut State,
    objects: &impl FindObjectOrHeader,
    for_each: impl FnMut(ChangeRef<'_>) -> Result<Action, E>,
    options: Options,
) -> Result<Option<Outcome>, Error>
where E: Into<Box<dyn Error + Sync + Send + 'static>>,
Available on crate feature blob only.
Expand description

Call for_each repeatedly with all changes that are needed to convert lhs to rhs. Provide a resource_cache to speed up obtaining blobs for similarity checks. tree_diff_state can be used to re-use tree-diff memory between calls. objects are used to lookup trees while performing the diff. Use options to further configure how the rename tracking is performed.

Reusing resource_cache between multiple invocations saves a lot of IOps as it avoids the creation of a temporary resource_cache that triggers reading or checking for multiple gitattribute files. Note that it’s recommended to call clear_resource_cache() between the calls to avoid runaway memory usage, as the cache isn’t limited.

Note that to do rename tracking like git does, one has to configure the resource_cache with a conversion pipeline that uses crate::blob::pipeline::Mode::ToGit.

rhs or lhs can be empty to indicate deletion or addition of an entire tree.

Note that the rewrite outcome is only available if rewrite-tracking was enabled.