diff --git a/gix-blame/src/file/function.rs b/gix-blame/src/file/function.rs index 05293053231..76e8f68e4fe 100644 --- a/gix-blame/src/file/function.rs +++ b/gix-blame/src/file/function.rs @@ -106,8 +106,9 @@ pub fn file( let (mut buf, mut buf2) = (Vec::new(), Vec::new()); let commit = find_commit(cache.as_ref(), &odb, &suspect, &mut buf)?; - let mut queue: gix_revwalk::PriorityQueue = gix_revwalk::PriorityQueue::new(); - queue.insert(commit_time(commit)?, suspect); + let mut queue: gix_revwalk::PriorityQueue = + gix_revwalk::PriorityQueue::new(); + queue.insert(commit.commit_time()?, suspect); let mut out = Vec::new(); let mut diff_state = gix_diff::tree::State::default(); @@ -126,7 +127,7 @@ pub fn file( } let commit = find_commit(cache.as_ref(), &odb, &suspect, &mut buf)?; - let commit_time = commit_time(commit)?; + let commit_time = commit.commit_time()?; if let Some(since) = options.since { if commit_time < since.seconds { @@ -651,17 +652,6 @@ fn find_path_entry_in_commit( Ok(res.map(|e| e.oid)) } -type CommitTime = i64; - -fn commit_time(commit: gix_traverse::commit::Either<'_, '_>) -> Result { - match commit { - gix_traverse::commit::Either::CommitRefIter(commit_ref_iter) => { - commit_ref_iter.committer().map(|c| c.seconds()) - } - gix_traverse::commit::Either::CachedCommit(commit) => Ok(commit.committer_timestamp() as i64), - } -} - type ParentIds = SmallVec<[(gix_hash::ObjectId, i64); 2]>; fn collect_parents( diff --git a/gix-traverse/src/commit/mod.rs b/gix-traverse/src/commit/mod.rs index 35bca8f2b6a..59c51e72c23 100644 --- a/gix-traverse/src/commit/mod.rs +++ b/gix-traverse/src/commit/mod.rs @@ -77,7 +77,7 @@ pub enum Either<'buf, 'cache> { } impl Either<'_, '_> { - /// Get a commits `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if + /// Get a commit’s `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 { @@ -85,6 +85,15 @@ impl Either<'_, '_> { Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()), } } + + /// Get a committer timestamp by either getting it from a [`gix_commitgraph::Graph`], if + /// present, or a [`gix_object::CommitRefIter`] otherwise. + pub fn commit_time(self) -> Result { + match self { + Self::CommitRefIter(commit_ref_iter) => commit_ref_iter.committer().map(|c| c.seconds()), + Self::CachedCommit(commit) => Ok(commit.committer_timestamp() as gix_date::SecondsSinceUnixEpoch), + } + } } /// Find information about a commit by either getting it from a [`gix_commitgraph::Graph`], if