@@ -6,12 +6,13 @@ use std::cmp::Reverse;
66use 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.
1010pub 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.
15+ #[ doc( alias = "Sort::REVERSE" , alias = "git2" ) ]
1516 OldestFirst ,
1617}
1718
@@ -31,7 +32,7 @@ pub enum CommitTimeOrder {
3132pub enum Sorting {
3233 /// Commits are sorted as they are mentioned in the commit graph.
3334 ///
34- /// In the *sample history* the order would be `8, 6, 7, 5, 4, 3, 2, 1`
35+ /// In the *sample history* the order would be `8, 6, 7, 5, 4, 3, 2, 1`.
3536 ///
3637 /// ### Note
3738 ///
@@ -43,22 +44,22 @@ pub enum Sorting {
4344 ///
4445 /// The sorting applies to all currently queued commit ids and thus is full.
4546 ///
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
47+ /// In the *sample history* the order would be `8, 7, 6, 5, 4, 3, 2, 1` for [` NewestFirst`](CommitTimeOrder::NewestFirst),
48+ /// or `1, 2, 3, 4, 5, 6, 7, 8` for [` OldestFirst`](CommitTimeOrder::OldestFirst).
4849 ///
4950 /// # Performance
5051 ///
5152 /// This mode benefits greatly from having an object_cache in `find()`
5253 /// to avoid having to lookup each commit twice.
5354 ByCommitTime ( CommitTimeOrder ) ,
54- /// This sorting is similar to `ByCommitTime`, but adds a cutoff to not return commits older than
55+ /// This sorting is similar to [ `ByCommitTime`](Sorting::ByCommitTime) , but adds a cutoff to not return commits older than
5556 /// a given time, stopping the iteration once no younger commits is queued to be traversed.
5657 ///
5758 /// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
5859 ///
59- /// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`
60+ /// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`.
6061 ByCommitTimeCutoff {
61- /// The order in wich to prioritize lookups
62+ /// The order in which to prioritize lookups.
6263 order : CommitTimeOrder ,
6364 /// The amount of seconds since unix epoch, the same value obtained by any `gix_date::Time` structure and the way git counts time.
6465 seconds : gix_date:: SecondsSinceUnixEpoch ,
@@ -125,11 +126,10 @@ mod init {
125126 }
126127 }
127128
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) )
129+ fn to_queue_key ( i : i64 , order : CommitTimeOrder ) -> super :: QueueKey < i64 > {
130+ match order {
131+ CommitTimeOrder :: NewestFirst => Newest ( i) ,
132+ CommitTimeOrder :: OldestFirst => Oldest ( Reverse ( i) ) ,
133133 }
134134 }
135135
@@ -151,17 +151,14 @@ mod init {
151151 for commit_id in state. next . drain ( ..) {
152152 let commit_iter = self . objects . find_commit_iter ( & commit_id, & mut state. buf ) ?;
153153 let time = commit_iter. committer ( ) ?. time . seconds ;
154- let ordered_time = order_time ( time, order) ;
154+ let key = to_queue_key ( time, order) ;
155155 match ( cutoff_time, order) {
156- ( Some ( cutoff_time) , CommitTimeOrder :: NewestFirst ) if time >= cutoff_time => {
157- state. queue . insert ( ordered_time, commit_id) ;
158- }
159- ( Some ( cutoff_time) , CommitTimeOrder :: OldestFirst ) if time <= cutoff_time => {
160- state. queue . insert ( ordered_time, commit_id) ;
156+ ( Some ( cutoff_time) , _) if time >= cutoff_time => {
157+ state. queue . insert ( key, commit_id) ;
161158 }
162159 ( Some ( _) , _) => { }
163160 ( None , _) => {
164- state. queue . insert ( ordered_time , commit_id) ;
161+ state. queue . insert ( key , commit_id) ;
165162 }
166163 }
167164 }
@@ -334,19 +331,10 @@ mod init {
334331 continue ;
335332 }
336333
337- let time = order_time ( parent_commit_time, order) ;
338- match ( cutoff, order) {
339- ( Some ( cutoff_older_than) , CommitTimeOrder :: NewestFirst )
340- if parent_commit_time < cutoff_older_than =>
341- {
342- continue
343- }
344- ( Some ( cutoff_newer_than) , CommitTimeOrder :: OldestFirst )
345- if parent_commit_time > cutoff_newer_than =>
346- {
347- continue
348- }
349- ( Some ( _) | None , _) => state. queue . insert ( time, id) ,
334+ let key = to_queue_key ( parent_commit_time, order) ;
335+ match cutoff {
336+ Some ( cutoff_older_than) if parent_commit_time < cutoff_older_than => continue ,
337+ Some ( _) | None => state. queue . insert ( key, id) ,
350338 }
351339 }
352340 }
@@ -366,19 +354,10 @@ mod init {
366354 . and_then ( |parent| parent. committer ( ) . ok ( ) . map ( |committer| committer. time . seconds ) )
367355 . unwrap_or_default ( ) ;
368356
369- let time = order_time ( parent_commit_time, order) ;
370- match ( cutoff, order) {
371- ( Some ( cutoff_older_than) , CommitTimeOrder :: NewestFirst )
372- if parent_commit_time < cutoff_older_than =>
373- {
374- continue
375- }
376- ( Some ( cutoff_newer_than) , CommitTimeOrder :: OldestFirst )
377- if parent_commit_time > cutoff_newer_than =>
378- {
379- continue
380- }
381- ( Some ( _) | None , _) => state. queue . insert ( time, id) ,
357+ let time = to_queue_key ( parent_commit_time, order) ;
358+ match cutoff {
359+ Some ( cutoff_older_than) if parent_commit_time < cutoff_older_than => continue ,
360+ Some ( _) | None => state. queue . insert ( time, id) ,
382361 }
383362 }
384363 Ok ( _unused_token) => break ,
0 commit comments