@@ -4,7 +4,54 @@ use gix_hashtable::HashSet;
44use smallvec:: SmallVec ;
55use std:: collections:: VecDeque ;
66
7- /// The error is part of the item returned by the [Ancestors](super::Ancestors) iterator.
7+ /// Specify how to sort commits during a [simple](super::Simple) traversal.
8+ ///
9+ /// ### Sample History
10+ ///
11+ /// The following history will be referred to for explaining how the sort order works, with the number denoting the commit timestamp
12+ /// (*their X-alignment doesn't matter*).
13+ ///
14+ /// ```text
15+ /// ---1----2----4----7 <- second parent of 8
16+ /// \ \
17+ /// 3----5----6----8---
18+ /// ```
19+ #[ derive( Default , Debug , Copy , Clone ) ]
20+ pub enum Sorting {
21+ /// Commits are sorted as they are mentioned in the commit graph.
22+ ///
23+ /// In the *sample history* the order would be `8, 6, 7, 5, 4, 3, 2, 1`
24+ ///
25+ /// ### Note
26+ ///
27+ /// This is not to be confused with `git log/rev-list --topo-order`, which is notably different from
28+ /// as it avoids overlapping branches.
29+ #[ default]
30+ BreadthFirst ,
31+ /// Commits are sorted by their commit time in descending order, that is newest first.
32+ ///
33+ /// The sorting applies to all currently queued commit ids and thus is full.
34+ ///
35+ /// In the *sample history* the order would be `8, 7, 6, 5, 4, 3, 2, 1`
36+ ///
37+ /// # Performance
38+ ///
39+ /// This mode benefits greatly from having an object_cache in `find()`
40+ /// to avoid having to lookup each commit twice.
41+ ByCommitTimeNewestFirst ,
42+ /// This sorting is similar to `ByCommitTimeNewestFirst`, but adds a cutoff to not return commits older than
43+ /// a given time, stopping the iteration once no younger commits is queued to be traversed.
44+ ///
45+ /// As the query is usually repeated with different cutoff dates, this search mode benefits greatly from an object cache.
46+ ///
47+ /// In the *sample history* and a cut-off date of 4, the returned list of commits would be `8, 7, 6, 4`
48+ ByCommitTimeNewestFirstCutoffOlderThan {
49+ /// The amount of seconds since unix epoch, the same value obtained by any `gix_date::Time` structure and the way git counts time.
50+ seconds : gix_date:: SecondsSinceUnixEpoch ,
51+ } ,
52+ }
53+
54+ /// The error is part of the item returned by the [Ancestors](super::Simple) iterator.
855#[ derive( Debug , thiserror:: Error ) ]
956#[ allow( missing_docs) ]
1057pub enum Error {
@@ -33,7 +80,7 @@ mod init {
3380 use gix_object:: { CommitRefIter , FindExt } ;
3481
3582 use super :: {
36- super :: { Ancestors , Either , Info , ParentIds , Parents , Sorting } ,
83+ super :: { simple :: Sorting , Either , Info , ParentIds , Parents , Simple } ,
3784 collect_parents, Error , State ,
3885 } ;
3986
@@ -60,7 +107,7 @@ mod init {
60107 }
61108
62109 /// Builder
63- impl < Find , Predicate > Ancestors < Find , Predicate >
110+ impl < Find , Predicate > Simple < Find , Predicate >
64111 where
65112 Find : gix_object:: Find ,
66113 {
@@ -121,7 +168,7 @@ mod init {
121168 }
122169
123170 /// Lifecyle
124- impl < Find > Ancestors < Find , fn ( & oid ) -> bool >
171+ impl < Find > Simple < Find , fn ( & oid ) -> bool >
125172 where
126173 Find : gix_object:: Find ,
127174 {
@@ -139,7 +186,7 @@ mod init {
139186 }
140187
141188 /// Lifecyle
142- impl < Find , Predicate > Ancestors < Find , Predicate >
189+ impl < Find , Predicate > Simple < Find , Predicate >
143190 where
144191 Find : gix_object:: Find ,
145192 Predicate : FnMut ( & oid ) -> bool ,
@@ -183,7 +230,7 @@ mod init {
183230 }
184231
185232 /// Access
186- impl < Find , Predicate > Ancestors < Find , Predicate > {
233+ impl < Find , Predicate > Simple < Find , Predicate > {
187234 /// Return an iterator for accessing data of the current commit, parsed lazily.
188235 pub fn commit_iter ( & self ) -> CommitRefIter < ' _ > {
189236 CommitRefIter :: from_bytes ( & self . state . buf )
@@ -195,7 +242,7 @@ mod init {
195242 }
196243 }
197244
198- impl < Find , Predicate > Iterator for Ancestors < Find , Predicate >
245+ impl < Find , Predicate > Iterator for Simple < Find , Predicate >
199246 where
200247 Find : gix_object:: Find ,
201248 Predicate : FnMut ( & oid ) -> bool ,
@@ -228,7 +275,7 @@ mod init {
228275 }
229276
230277 /// Utilities
231- impl < Find , Predicate > Ancestors < Find , Predicate >
278+ impl < Find , Predicate > Simple < Find , Predicate >
232279 where
233280 Find : gix_object:: Find ,
234281 Predicate : FnMut ( & oid ) -> bool ,
@@ -298,7 +345,7 @@ mod init {
298345 }
299346
300347 /// Utilities
301- impl < Find , Predicate > Ancestors < Find , Predicate >
348+ impl < Find , Predicate > Simple < Find , Predicate >
302349 where
303350 Find : gix_object:: Find ,
304351 Predicate : FnMut ( & oid ) -> bool ,
0 commit comments