Skip to content

Commit 7419552

Browse files
committed
add tests for new simple commit ordering
1 parent 1dbb94a commit 7419552

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

gix-traverse/src/commit/simple.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::cmp::Reverse;
66
use std::collections::VecDeque;
77

88
#[derive(Default, Debug, Copy, Clone)]
9-
/// The order with which to prioritize the search
9+
/// The order with which to prioritize the search.
1010
pub enum CommitTimeOrder {
1111
#[default]
12-
/// sort commits by newest first
12+
/// Sort commits by newest first.
1313
NewestFirst,
14-
/// sort commits by oldest first
14+
/// Sort commits by oldest first.
1515
OldestFirst,
1616
}
1717

@@ -31,7 +31,7 @@ pub enum CommitTimeOrder {
3131
pub enum Sorting {
3232
/// Commits are sorted as they are mentioned in the commit graph.
3333
///
34-
/// In the *sample history* the order would be `8, 6, 7, 5, 4, 3, 2, 1`
34+
/// In the *sample history* the order would be `8, 6, 7, 5, 4, 3, 2, 1`.
3535
///
3636
/// ### Note
3737
///
@@ -43,22 +43,22 @@ pub enum Sorting {
4343
///
4444
/// The sorting applies to all currently queued commit ids and thus is full.
4545
///
46-
/// In the *sample history* the order would be `8, 7, 6, 5, 4, 3, 2, 1` for NewestFirst
47-
/// Or `1, 2, 3, 4, 5, 6, 7, 8` for OldestFirst
46+
/// In the *sample history* the order would be `8, 7, 6, 5, 4, 3, 2, 1` for [`NewestFirst`](CommitTimeOrder::NewestFirst),
47+
/// or `1, 2, 3, 4, 5, 6, 7, 8` for [`OldestFirst`](CommitTimeOrder::OldestFirst).
4848
///
4949
/// # Performance
5050
///
5151
/// This mode benefits greatly from having an object_cache in `find()`
5252
/// to avoid having to lookup each commit twice.
5353
ByCommitTime(CommitTimeOrder),
54-
/// This sorting is similar to `ByCommitTime`, but adds a cutoff to not return commits older than
54+
/// This sorting is similar to [`ByCommitTime`](Sorting::ByCommitTime), but adds a cutoff to not return commits older than
5555
/// a given time, stopping the iteration once no younger commits is queued to be traversed.
5656
///
5757
/// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
5858
///
59-
/// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`
59+
/// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`.
6060
ByCommitTimeCutoff {
61-
/// The order in wich to prioritize lookups
61+
/// The order in which to prioritize lookups.
6262
order: CommitTimeOrder,
6363
/// The amount of seconds since unix epoch, the same value obtained by any `gix_date::Time` structure and the way git counts time.
6464
seconds: gix_date::SecondsSinceUnixEpoch,
@@ -125,11 +125,10 @@ mod init {
125125
}
126126
}
127127

128-
fn order_time(i: i64, order: CommitTimeOrder) -> super::QueueKey<i64> {
129-
if let CommitTimeOrder::NewestFirst = order {
130-
Newest(i)
131-
} else {
132-
Oldest(Reverse(i))
128+
fn to_queue_key(i: i64, order: CommitTimeOrder) -> super::QueueKey<i64> {
129+
match order {
130+
CommitTimeOrder::NewestFirst => Newest(i),
131+
CommitTimeOrder::OldestFirst => Oldest(Reverse(i)),
133132
}
134133
}
135134

@@ -151,17 +150,17 @@ mod init {
151150
for commit_id in state.next.drain(..) {
152151
let commit_iter = self.objects.find_commit_iter(&commit_id, &mut state.buf)?;
153152
let time = commit_iter.committer()?.time.seconds;
154-
let ordered_time = order_time(time, order);
153+
let key = to_queue_key(time, order);
155154
match (cutoff_time, order) {
156155
(Some(cutoff_time), CommitTimeOrder::NewestFirst) if time >= cutoff_time => {
157-
state.queue.insert(ordered_time, commit_id);
156+
state.queue.insert(key, commit_id);
158157
}
159158
(Some(cutoff_time), CommitTimeOrder::OldestFirst) if time <= cutoff_time => {
160-
state.queue.insert(ordered_time, commit_id);
159+
state.queue.insert(key, commit_id);
161160
}
162161
(Some(_), _) => {}
163162
(None, _) => {
164-
state.queue.insert(ordered_time, commit_id);
163+
state.queue.insert(key, commit_id);
165164
}
166165
}
167166
}
@@ -334,7 +333,7 @@ mod init {
334333
continue;
335334
}
336335

337-
let time = order_time(parent_commit_time, order);
336+
let key = to_queue_key(parent_commit_time, order);
338337
match (cutoff, order) {
339338
(Some(cutoff_older_than), CommitTimeOrder::NewestFirst)
340339
if parent_commit_time < cutoff_older_than =>
@@ -346,7 +345,7 @@ mod init {
346345
{
347346
continue
348347
}
349-
(Some(_) | None, _) => state.queue.insert(time, id),
348+
(Some(_) | None, _) => state.queue.insert(key, id),
350349
}
351350
}
352351
}
@@ -366,7 +365,7 @@ mod init {
366365
.and_then(|parent| parent.committer().ok().map(|committer| committer.time.seconds))
367366
.unwrap_or_default();
368367

369-
let time = order_time(parent_commit_time, order);
368+
let time = to_queue_key(parent_commit_time, order);
370369
match (cutoff, order) {
371370
(Some(cutoff_older_than), CommitTimeOrder::NewestFirst)
372371
if parent_commit_time < cutoff_older_than =>

0 commit comments

Comments
 (0)