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