Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions gix-blame/src/file/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommitTime, ObjectId> = gix_revwalk::PriorityQueue::new();
queue.insert(commit_time(commit)?, suspect);
let mut queue: gix_revwalk::PriorityQueue<gix_date::SecondsSinceUnixEpoch, ObjectId> =
gix_revwalk::PriorityQueue::new();
queue.insert(commit.commit_time()?, suspect);

let mut out = Vec::new();
let mut diff_state = gix_diff::tree::State::default();
Expand All @@ -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 {
Expand Down Expand Up @@ -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<CommitTime, gix_object::decode::Error> {
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(
Expand Down
11 changes: 10 additions & 1 deletion gix-traverse/src/commit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,23 @@ 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<ObjectId, gix_object::decode::Error> {
match self {
Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
}
}

/// Get a commit’s `commit_time` by either getting it from a [`gix_commitgraph::Graph`], if
/// present, or a [`gix_object::CommitRefIter`] otherwise.
pub fn commit_time(self) -> Result<gix_date::SecondsSinceUnixEpoch, gix_object::decode::Error> {
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
Expand Down
Loading