@@ -6,12 +6,13 @@ use std::cmp::Reverse;
6
6
use std:: collections:: VecDeque ;
7
7
8
8
#[ derive( Default , Debug , Copy , Clone ) ]
9
- /// The order with which to prioritize the search
9
+ /// The order with which to prioritize the search.
10
10
pub enum CommitTimeOrder {
11
11
#[ default]
12
- /// sort commits by newest first
12
+ /// Sort commits by newest first.
13
13
NewestFirst ,
14
- /// sort commits by oldest first
14
+ /// Sort commits by oldest first.
15
+ #[ doc( alias = "Sort::REVERSE" , alias = "git2" ) ]
15
16
OldestFirst ,
16
17
}
17
18
@@ -31,7 +32,7 @@ pub enum CommitTimeOrder {
31
32
pub enum Sorting {
32
33
/// Commits are sorted as they are mentioned in the commit graph.
33
34
///
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`.
35
36
///
36
37
/// ### Note
37
38
///
@@ -43,22 +44,22 @@ pub enum Sorting {
43
44
///
44
45
/// The sorting applies to all currently queued commit ids and thus is full.
45
46
///
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).
48
49
///
49
50
/// # Performance
50
51
///
51
52
/// This mode benefits greatly from having an object_cache in `find()`
52
53
/// to avoid having to lookup each commit twice.
53
54
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
55
56
/// a given time, stopping the iteration once no younger commits is queued to be traversed.
56
57
///
57
58
/// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
58
59
///
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`.
60
61
ByCommitTimeCutoff {
61
- /// The order in wich to prioritize lookups
62
+ /// The order in which to prioritize lookups.
62
63
order : CommitTimeOrder ,
63
64
/// The amount of seconds since unix epoch, the same value obtained by any `gix_date::Time` structure and the way git counts time.
64
65
seconds : gix_date:: SecondsSinceUnixEpoch ,
@@ -125,11 +126,10 @@ mod init {
125
126
}
126
127
}
127
128
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) ) ,
133
133
}
134
134
}
135
135
@@ -151,17 +151,14 @@ mod init {
151
151
for commit_id in state. next . drain ( ..) {
152
152
let commit_iter = self . objects . find_commit_iter ( & commit_id, & mut state. buf ) ?;
153
153
let time = commit_iter. committer ( ) ?. time . seconds ;
154
- let ordered_time = order_time ( time, order) ;
154
+ let key = to_queue_key ( time, order) ;
155
155
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) ;
161
158
}
162
159
( Some ( _) , _) => { }
163
160
( None , _) => {
164
- state. queue . insert ( ordered_time , commit_id) ;
161
+ state. queue . insert ( key , commit_id) ;
165
162
}
166
163
}
167
164
}
@@ -334,19 +331,10 @@ mod init {
334
331
continue ;
335
332
}
336
333
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) ,
350
338
}
351
339
}
352
340
}
@@ -366,19 +354,10 @@ mod init {
366
354
. and_then ( |parent| parent. committer ( ) . ok ( ) . map ( |committer| committer. time . seconds ) )
367
355
. unwrap_or_default ( ) ;
368
356
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) ,
382
361
}
383
362
}
384
363
Ok ( _unused_token) => break ,
0 commit comments