1
1
use gix_hash:: ObjectId ;
2
2
use gix_object:: FindExt ;
3
+ use gix_traverse:: commit:: simple:: CommitTimeOrder ;
3
4
4
5
use crate :: { ext:: ObjectIdExt , revision, Repository } ;
5
6
@@ -39,24 +40,27 @@ pub enum Sorting {
39
40
/// as it avoids overlapping branches.
40
41
#[ default]
41
42
BreadthFirst ,
42
- /// Commits are sorted by their commit time in descending order, that is newest first.
43
+ /// Commits are sorted by their commit time in the order specified, either newest or oldest first.
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, 4, 5, 2, 3, 1`
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).
47
49
///
48
50
/// # Performance
49
51
///
50
52
/// This mode benefits greatly from having an [object cache](crate::Repository::object_cache_size) configured
51
53
/// to avoid having to look up each commit twice.
52
- ByCommitTimeNewestFirst ,
53
- /// This sorting is similar to `ByCommitTimeNewestFirst` , but adds a cutoff to not return commits older than
54
+ ByCommitTime ( CommitTimeOrder ) ,
55
+ /// This sorting is similar to [`ByCommitTime`](Sorting::ByCommitTimeCutoff) , but adds a cutoff to not return commits older than
54
56
/// a given time, stopping the iteration once no younger commits is queued to be traversed.
55
57
///
56
58
/// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
57
59
///
58
60
/// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`
59
- ByCommitTimeNewestFirstCutoffOlderThan {
61
+ ByCommitTimeCutoff {
62
+ /// The order in wich to prioritize lookups
63
+ order : CommitTimeOrder ,
60
64
/// The amount of seconds since unix epoch to use as cut-off time.
61
65
seconds : gix_date:: SecondsSinceUnixEpoch ,
62
66
} ,
@@ -66,9 +70,9 @@ impl Sorting {
66
70
fn into_simple ( self ) -> Option < gix_traverse:: commit:: simple:: Sorting > {
67
71
Some ( match self {
68
72
Sorting :: BreadthFirst => gix_traverse:: commit:: simple:: Sorting :: BreadthFirst ,
69
- Sorting :: ByCommitTimeNewestFirst => gix_traverse:: commit:: simple:: Sorting :: ByCommitTimeNewestFirst ,
70
- Sorting :: ByCommitTimeNewestFirstCutoffOlderThan { seconds } => {
71
- gix_traverse:: commit:: simple:: Sorting :: ByCommitTimeNewestFirstCutoffOlderThan { seconds }
73
+ Sorting :: ByCommitTime ( order ) => gix_traverse:: commit:: simple:: Sorting :: ByCommitTime ( order ) ,
74
+ Sorting :: ByCommitTimeCutoff { seconds, order } => {
75
+ gix_traverse:: commit:: simple:: Sorting :: ByCommitTimeCutoff { order , seconds }
72
76
}
73
77
} )
74
78
}
@@ -208,15 +212,16 @@ impl<'repo> Platform<'repo> {
208
212
/// Prune the commit with the given `ids` such that they won't be returned, and such that none of their ancestors is returned either.
209
213
///
210
214
/// Note that this forces the [sorting](Self::sorting) to
211
- /// [`ByCommitTimeNewestFirstCutoffOlderThan `](Sorting::ByCommitTimeNewestFirstCutoffOlderThan ) configured with
215
+ /// [`ByCommitTimeCutoff `](Sorting::ByCommitTimeCutoff ) configured with
212
216
/// the oldest available commit time, ensuring that no commits older than the oldest of `ids` will be returned either.
213
217
///
214
218
/// Also note that commits that can't be accessed or are missing are simply ignored for the purpose of obtaining the cutoff date.
215
219
#[ doc( alias = "hide" , alias = "git2" ) ]
216
220
pub fn with_pruned ( mut self , ids : impl IntoIterator < Item = impl Into < ObjectId > > ) -> Self {
217
- let mut cutoff = match self . sorting {
218
- Sorting :: ByCommitTimeNewestFirstCutoffOlderThan { seconds } => Some ( seconds) ,
219
- Sorting :: BreadthFirst | Sorting :: ByCommitTimeNewestFirst => None ,
221
+ let ( mut cutoff, order) = match self . sorting {
222
+ Sorting :: ByCommitTimeCutoff { seconds, order } => ( Some ( seconds) , order) ,
223
+ Sorting :: ByCommitTime ( order) => ( None , order) ,
224
+ Sorting :: BreadthFirst => ( None , CommitTimeOrder :: default ( ) ) ,
220
225
} ;
221
226
for id in ids. into_iter ( ) {
222
227
let id = id. into ( ) ;
@@ -231,7 +236,7 @@ impl<'repo> Platform<'repo> {
231
236
}
232
237
233
238
if let Some ( cutoff) = cutoff {
234
- self . sorting = Sorting :: ByCommitTimeNewestFirstCutoffOlderThan { seconds : cutoff }
239
+ self . sorting = Sorting :: ByCommitTimeCutoff { seconds : cutoff, order }
235
240
}
236
241
self
237
242
}
0 commit comments