Skip to content

Commit 8be3193

Browse files
authored
Merge pull request #1974 from cruessler/move-commit-time-to-either
Move `commit_time` to `gix_traverse::commit::Either`
2 parents de13b16 + 9c3e288 commit 8be3193

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

gix-blame/src/file/function.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ pub fn file(
106106

107107
let (mut buf, mut buf2) = (Vec::new(), Vec::new());
108108
let commit = find_commit(cache.as_ref(), &odb, &suspect, &mut buf)?;
109-
let mut queue: gix_revwalk::PriorityQueue<CommitTime, ObjectId> = gix_revwalk::PriorityQueue::new();
110-
queue.insert(commit_time(commit)?, suspect);
109+
let mut queue: gix_revwalk::PriorityQueue<gix_date::SecondsSinceUnixEpoch, ObjectId> =
110+
gix_revwalk::PriorityQueue::new();
111+
queue.insert(commit.commit_time()?, suspect);
111112

112113
let mut out = Vec::new();
113114
let mut diff_state = gix_diff::tree::State::default();
@@ -126,7 +127,7 @@ pub fn file(
126127
}
127128

128129
let commit = find_commit(cache.as_ref(), &odb, &suspect, &mut buf)?;
129-
let commit_time = commit_time(commit)?;
130+
let commit_time = commit.commit_time()?;
130131

131132
if let Some(since) = options.since {
132133
if commit_time < since.seconds {
@@ -651,17 +652,6 @@ fn find_path_entry_in_commit(
651652
Ok(res.map(|e| e.oid))
652653
}
653654

654-
type CommitTime = i64;
655-
656-
fn commit_time(commit: gix_traverse::commit::Either<'_, '_>) -> Result<CommitTime, gix_object::decode::Error> {
657-
match commit {
658-
gix_traverse::commit::Either::CommitRefIter(commit_ref_iter) => {
659-
commit_ref_iter.committer().map(|c| c.seconds())
660-
}
661-
gix_traverse::commit::Either::CachedCommit(commit) => Ok(commit.committer_timestamp() as i64),
662-
}
663-
}
664-
665655
type ParentIds = SmallVec<[(gix_hash::ObjectId, i64); 2]>;
666656

667657
fn collect_parents(

gix-traverse/src/commit/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ pub enum Either<'buf, 'cache> {
7777
}
7878

7979
impl Either<'_, '_> {
80-
/// Get a commits `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if
80+
/// Get a commit’s `tree_id` by either getting it from a [`gix_commitgraph::Graph`], if
8181
/// present, or a [`gix_object::CommitRefIter`] otherwise.
8282
pub fn tree_id(self) -> Result<ObjectId, gix_object::decode::Error> {
8383
match self {
8484
Self::CommitRefIter(mut commit_ref_iter) => commit_ref_iter.tree_id(),
8585
Self::CachedCommit(commit) => Ok(commit.root_tree_id().into()),
8686
}
8787
}
88+
89+
/// Get a committer timestamp by either getting it from a [`gix_commitgraph::Graph`], if
90+
/// present, or a [`gix_object::CommitRefIter`] otherwise.
91+
pub fn commit_time(self) -> Result<gix_date::SecondsSinceUnixEpoch, gix_object::decode::Error> {
92+
match self {
93+
Self::CommitRefIter(commit_ref_iter) => commit_ref_iter.committer().map(|c| c.seconds()),
94+
Self::CachedCommit(commit) => Ok(commit.committer_timestamp() as gix_date::SecondsSinceUnixEpoch),
95+
}
96+
}
8897
}
8998

9099
/// Find information about a commit by either getting it from a [`gix_commitgraph::Graph`], if

0 commit comments

Comments
 (0)