diff --git a/gix-blame/src/file/function.rs b/gix-blame/src/file/function.rs index c6572e202d1..d9299689c21 100644 --- a/gix-blame/src/file/function.rs +++ b/gix-blame/src/file/function.rs @@ -452,12 +452,12 @@ fn tree_diff_at_file_path( lhs_tree_buf: &mut Vec, rhs_tree_buf: &mut Vec, ) -> Result, Error> { - let parent_tree_id = tree_id(find_commit(cache, &odb, &parent_id, commit_buf)?)?; + let parent_tree_id = find_commit(cache, &odb, &parent_id, commit_buf)?.tree_id()?; let parent_tree_iter = odb.find_tree_iter(&parent_tree_id, lhs_tree_buf)?; stats.trees_decoded += 1; - let tree_id = tree_id(find_commit(cache, &odb, &id, commit_buf)?)?; + let tree_id = find_commit(cache, &odb, &id, commit_buf)?.tree_id()?; let tree_iter = odb.find_tree_iter(&tree_id, rhs_tree_buf)?; stats.trees_decoded += 1; @@ -654,7 +654,7 @@ fn find_path_entry_in_commit( buf2: &mut Vec, stats: &mut Statistics, ) -> Result, Error> { - let tree_id = tree_id(find_commit(cache, odb, commit, buf)?)?; + let tree_id = find_commit(cache, odb, commit, buf)?.tree_id()?; let tree_iter = odb.find_tree_iter(&tree_id, buf)?; stats.trees_decoded += 1; @@ -710,13 +710,6 @@ fn collect_parents( Ok(parent_ids) } -fn tree_id(commit: gix_traverse::commit::Either<'_, '_>) -> Result { - match commit { - gix_traverse::commit::Either::CommitRefIter(mut commit_ref_iter) => Ok(commit_ref_iter.tree_id()?), - gix_traverse::commit::Either::CachedCommit(commit) => Ok(commit.root_tree_id().into()), - } -} - /// Return an iterator over tokens for use in diffing. These are usually lines, but it's important /// to unify them so the later access shows the right thing. pub(crate) fn tokens_for_diffing(data: &[u8]) -> impl TokenSource { diff --git a/gix-traverse/src/commit/mod.rs b/gix-traverse/src/commit/mod.rs index 4db6d4f64fc..1c19a13602a 100644 --- a/gix-traverse/src/commit/mod.rs +++ b/gix-traverse/src/commit/mod.rs @@ -77,6 +77,17 @@ pub enum Either<'buf, 'cache> { CachedCommit(gix_commitgraph::file::Commit<'cache>), } +impl Either<'_, '_> { + /// Get a commits `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if + /// present, or a [`gix_object::CommitRefIter`] otherwise. + pub fn tree_id(self) -> Result { + match self { + Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(), + Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()), + } + } +} + /// Find information about a commit by either getting it from a [`gix_commitgraph::Graph`], if /// present, or a [`gix_object::CommitRefIter`] otherwise. pub fn find<'cache, 'buf, Find>(