@@ -4,7 +4,54 @@ use gix_hashtable::HashSet;
4
4
use smallvec:: SmallVec ;
5
5
use std:: collections:: VecDeque ;
6
6
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.
8
55
#[ derive( Debug , thiserror:: Error ) ]
9
56
#[ allow( missing_docs) ]
10
57
pub enum Error {
@@ -33,7 +80,7 @@ mod init {
33
80
use gix_object:: { CommitRefIter , FindExt } ;
34
81
35
82
use super :: {
36
- super :: { Ancestors , Either , Info , ParentIds , Parents , Sorting } ,
83
+ super :: { simple :: Sorting , Either , Info , ParentIds , Parents , Simple } ,
37
84
collect_parents, Error , State ,
38
85
} ;
39
86
@@ -60,7 +107,7 @@ mod init {
60
107
}
61
108
62
109
/// Builder
63
- impl < Find , Predicate > Ancestors < Find , Predicate >
110
+ impl < Find , Predicate > Simple < Find , Predicate >
64
111
where
65
112
Find : gix_object:: Find ,
66
113
{
@@ -121,7 +168,7 @@ mod init {
121
168
}
122
169
123
170
/// Lifecyle
124
- impl < Find > Ancestors < Find , fn ( & oid ) -> bool >
171
+ impl < Find > Simple < Find , fn ( & oid ) -> bool >
125
172
where
126
173
Find : gix_object:: Find ,
127
174
{
@@ -139,7 +186,7 @@ mod init {
139
186
}
140
187
141
188
/// Lifecyle
142
- impl < Find , Predicate > Ancestors < Find , Predicate >
189
+ impl < Find , Predicate > Simple < Find , Predicate >
143
190
where
144
191
Find : gix_object:: Find ,
145
192
Predicate : FnMut ( & oid ) -> bool ,
@@ -183,7 +230,7 @@ mod init {
183
230
}
184
231
185
232
/// Access
186
- impl < Find , Predicate > Ancestors < Find , Predicate > {
233
+ impl < Find , Predicate > Simple < Find , Predicate > {
187
234
/// Return an iterator for accessing data of the current commit, parsed lazily.
188
235
pub fn commit_iter ( & self ) -> CommitRefIter < ' _ > {
189
236
CommitRefIter :: from_bytes ( & self . state . buf )
@@ -195,7 +242,7 @@ mod init {
195
242
}
196
243
}
197
244
198
- impl < Find , Predicate > Iterator for Ancestors < Find , Predicate >
245
+ impl < Find , Predicate > Iterator for Simple < Find , Predicate >
199
246
where
200
247
Find : gix_object:: Find ,
201
248
Predicate : FnMut ( & oid ) -> bool ,
@@ -228,7 +275,7 @@ mod init {
228
275
}
229
276
230
277
/// Utilities
231
- impl < Find , Predicate > Ancestors < Find , Predicate >
278
+ impl < Find , Predicate > Simple < Find , Predicate >
232
279
where
233
280
Find : gix_object:: Find ,
234
281
Predicate : FnMut ( & oid ) -> bool ,
@@ -298,7 +345,7 @@ mod init {
298
345
}
299
346
300
347
/// Utilities
301
- impl < Find , Predicate > Ancestors < Find , Predicate >
348
+ impl < Find , Predicate > Simple < Find , Predicate >
302
349
where
303
350
Find : gix_object:: Find ,
304
351
Predicate : FnMut ( & oid ) -> bool ,
0 commit comments