11use gix_hash:: ObjectId ;
22use gix_object:: FindExt ;
3+ use gix_traverse:: commit:: simple:: CommitTimeOrder ;
34
45use crate :: { ext:: ObjectIdExt , revision, Repository } ;
56
@@ -39,24 +40,27 @@ pub enum Sorting {
3940 /// as it avoids overlapping branches.
4041 #[ default]
4142 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.
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, 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).
4749 ///
4850 /// # Performance
4951 ///
5052 /// This mode benefits greatly from having an [object cache](crate::Repository::object_cache_size) configured
5153 /// 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
5456 /// a given time, stopping the iteration once no younger commits is queued to be traversed.
5557 ///
5658 /// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
5759 ///
5860 /// 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 ,
6064 /// The amount of seconds since unix epoch to use as cut-off time.
6165 seconds : gix_date:: SecondsSinceUnixEpoch ,
6266 } ,
@@ -66,9 +70,9 @@ impl Sorting {
6670 fn into_simple ( self ) -> Option < gix_traverse:: commit:: simple:: Sorting > {
6771 Some ( match self {
6872 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 }
7276 }
7377 } )
7478 }
@@ -208,15 +212,16 @@ impl<'repo> Platform<'repo> {
208212 /// Prune the commit with the given `ids` such that they won't be returned, and such that none of their ancestors is returned either.
209213 ///
210214 /// Note that this forces the [sorting](Self::sorting) to
211- /// [`ByCommitTimeNewestFirstCutoffOlderThan `](Sorting::ByCommitTimeNewestFirstCutoffOlderThan ) configured with
215+ /// [`ByCommitTimeCutoff `](Sorting::ByCommitTimeCutoff ) configured with
212216 /// the oldest available commit time, ensuring that no commits older than the oldest of `ids` will be returned either.
213217 ///
214218 /// Also note that commits that can't be accessed or are missing are simply ignored for the purpose of obtaining the cutoff date.
215219 #[ doc( alias = "hide" , alias = "git2" ) ]
216220 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 ( ) ) ,
220225 } ;
221226 for id in ids. into_iter ( ) {
222227 let id = id. into ( ) ;
@@ -231,7 +236,7 @@ impl<'repo> Platform<'repo> {
231236 }
232237
233238 if let Some ( cutoff) = cutoff {
234- self . sorting = Sorting :: ByCommitTimeNewestFirstCutoffOlderThan { seconds : cutoff }
239+ self . sorting = Sorting :: ByCommitTimeCutoff { seconds : cutoff, order }
235240 }
236241 self
237242 }
0 commit comments