@@ -14,37 +14,35 @@ namespace LibGit2Sharp
14
14
public class CommitLog : IQueryableCommitLog
15
15
{
16
16
private readonly Repository repo ;
17
- private IList < object > includedIdentifier = new List < object > { "HEAD" } ;
18
- private IList < object > excludedIdentifier = new List < object > ( ) ;
19
- private readonly GitSortOptions sortOptions ;
17
+ readonly Filter queryFilter ;
20
18
21
19
/// <summary>
22
20
/// Initializes a new instance of the <see cref = "CommitLog" /> class.
23
21
/// The commits will be enumerated according in reverse chronological order.
24
22
/// </summary>
25
23
/// <param name = "repo">The repository.</param>
26
24
internal CommitLog ( Repository repo )
27
- : this ( repo , GitSortOptions . Time )
25
+ : this ( repo , new Filter ( ) )
28
26
{
29
27
}
30
28
31
29
/// <summary>
32
30
/// Initializes a new instance of the <see cref = "CommitLog" /> class.
33
31
/// </summary>
34
32
/// <param name = "repo">The repository.</param>
35
- /// <param name = "sortingStrategy ">The sorting strategy which should be applied when enumerating the commits. </param>
36
- internal CommitLog ( Repository repo , GitSortOptions sortingStrategy )
33
+ /// <param name="queryFilter ">The filter to use in querying commits</param>
34
+ internal CommitLog ( Repository repo , Filter queryFilter )
37
35
{
38
36
this . repo = repo ;
39
- sortOptions = sortingStrategy ;
37
+ this . queryFilter = queryFilter ;
40
38
}
41
39
42
40
/// <summary>
43
41
/// Gets the current sorting strategy applied when enumerating the log
44
42
/// </summary>
45
43
public GitSortOptions SortedBy
46
44
{
47
- get { return sortOptions ; }
45
+ get { return queryFilter . SortBy ; }
48
46
}
49
47
50
48
#region IEnumerable<Commit> Members
@@ -55,12 +53,12 @@ public GitSortOptions SortedBy
55
53
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the log.</returns>
56
54
public IEnumerator < Commit > GetEnumerator ( )
57
55
{
58
- if ( ( repo . Info . IsEmpty ) & & includedIdentifier . Any ( o => PointsAtTheHead ( o . ToString ( ) ) ) ) // TODO: ToString() == fragile
56
+ if ( ( repo . Info . IsEmpty ) & & queryFilter . SinceList . Any ( o => PointsAtTheHead ( o . ToString ( ) ) ) ) // TODO: ToString() == fragile
59
57
{
60
58
return Enumerable . Empty < Commit > ( ) . GetEnumerator ( ) ;
61
59
}
62
60
63
- return new CommitEnumerator ( repo , includedIdentifier , excludedIdentifier , sortOptions ) ;
61
+ return new CommitEnumerator ( repo , queryFilter ) ;
64
62
}
65
63
66
64
/// <summary>
@@ -85,38 +83,7 @@ public ICommitLog QueryBy(Filter filter)
85
83
Ensure . ArgumentNotNull ( filter . Since , "filter.Since" ) ;
86
84
Ensure . ArgumentNotNullOrEmptyString ( filter . Since . ToString ( ) , "filter.Since" ) ;
87
85
88
- return new CommitLog ( repo , filter . SortBy )
89
- {
90
- includedIdentifier = ToList ( filter . Since ) ,
91
- excludedIdentifier = ToList ( filter . Until )
92
- } ;
93
- }
94
-
95
- private static IList < object > ToList ( object obj )
96
- {
97
- var list = new List < object > ( ) ;
98
-
99
- if ( obj == null )
100
- {
101
- return list ;
102
- }
103
-
104
- var types = new [ ]
105
- {
106
- typeof ( string ) , typeof ( ObjectId ) ,
107
- typeof ( Commit ) , typeof ( TagAnnotation ) ,
108
- typeof ( Tag ) , typeof ( Branch ) , typeof ( DetachedHead ) ,
109
- typeof ( Reference ) , typeof ( DirectReference ) , typeof ( SymbolicReference )
110
- } ;
111
-
112
- if ( types . Contains ( obj . GetType ( ) ) )
113
- {
114
- list . Add ( obj ) ;
115
- return list ;
116
- }
117
-
118
- list . AddRange ( ( ( IEnumerable ) obj ) . Cast < object > ( ) ) ;
119
- return list ;
86
+ return new CommitLog ( repo , filter ) ;
120
87
}
121
88
122
89
private static bool PointsAtTheHead ( string shaOrRefName )
@@ -215,17 +182,27 @@ private class CommitEnumerator : IEnumerator<Commit>
215
182
private readonly RevWalkerSafeHandle handle ;
216
183
private ObjectId currentOid ;
217
184
218
- public CommitEnumerator ( Repository repo , IList < object > includedIdentifier , IList < object > excludedIdentifier , GitSortOptions sortingStrategy )
185
+ public CommitEnumerator ( Repository repo , Filter filter )
219
186
{
220
187
this . repo = repo ;
221
188
int res = NativeMethods . git_revwalk_new ( out handle , repo . Handle ) ;
222
189
repo . RegisterForCleanup ( handle ) ;
223
190
224
191
Ensure . Success ( res ) ;
225
192
226
- Sort ( sortingStrategy ) ;
227
- Push ( includedIdentifier ) ;
228
- Hide ( excludedIdentifier ) ;
193
+ Sort ( filter . SortBy ) ;
194
+ Push ( filter . SinceList ) ;
195
+ Hide ( filter . UntilList ) ;
196
+
197
+ if ( ! string . IsNullOrEmpty ( filter . SinceGlob ) )
198
+ {
199
+ Ensure . Success ( NativeMethods . git_revwalk_push_glob ( handle , filter . SinceGlob ) ) ;
200
+ }
201
+
202
+ if ( ! string . IsNullOrEmpty ( filter . UntilGlob ) )
203
+ {
204
+ Ensure . Success ( NativeMethods . git_revwalk_hide_glob ( handle , filter . UntilGlob ) ) ;
205
+ }
229
206
}
230
207
231
208
#region IEnumerator<Commit> Members
0 commit comments