@@ -14,9 +14,7 @@ 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
+ private readonly Filter queryFilter ;
20
18
21
19
/// <summary>
22
20
/// Needed for mocking purposes.
@@ -30,27 +28,27 @@ protected CommitLog()
30
28
/// </summary>
31
29
/// <param name = "repo">The repository.</param>
32
30
internal CommitLog ( Repository repo )
33
- : this ( repo , GitSortOptions . Time )
31
+ : this ( repo , new Filter ( ) )
34
32
{
35
33
}
36
34
37
35
/// <summary>
38
36
/// Initializes a new instance of the <see cref = "CommitLog" /> class.
39
37
/// </summary>
40
38
/// <param name = "repo">The repository.</param>
41
- /// <param name = "sortingStrategy ">The sorting strategy which should be applied when enumerating the commits. </param>
42
- internal CommitLog ( Repository repo , GitSortOptions sortingStrategy )
39
+ /// <param name="queryFilter ">The filter to use in querying commits</param>
40
+ internal CommitLog ( Repository repo , Filter queryFilter )
43
41
{
44
42
this . repo = repo ;
45
- sortOptions = sortingStrategy ;
43
+ this . queryFilter = queryFilter ;
46
44
}
47
45
48
46
/// <summary>
49
47
/// Gets the current sorting strategy applied when enumerating the log
50
48
/// </summary>
51
49
public virtual GitSortOptions SortedBy
52
50
{
53
- get { return sortOptions ; }
51
+ get { return queryFilter . SortBy ; }
54
52
}
55
53
56
54
#region IEnumerable<Commit> Members
@@ -61,12 +59,12 @@ public virtual GitSortOptions SortedBy
61
59
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the log.</returns>
62
60
public virtual IEnumerator < Commit > GetEnumerator ( )
63
61
{
64
- if ( ( repo . Info . IsEmpty ) & & includedIdentifier . Any ( o => PointsAtTheHead ( o . ToString ( ) ) ) ) // TODO: ToString() == fragile
62
+ if ( ( repo . Info . IsEmpty ) & & queryFilter . SinceList . Any ( o => PointsAtTheHead ( o . ToString ( ) ) ) ) // TODO: ToString() == fragile
65
63
{
66
64
return Enumerable . Empty < Commit > ( ) . GetEnumerator ( ) ;
67
65
}
68
66
69
- return new CommitEnumerator ( repo , includedIdentifier , excludedIdentifier , sortOptions ) ;
67
+ return new CommitEnumerator ( repo , queryFilter ) ;
70
68
}
71
69
72
70
/// <summary>
@@ -91,38 +89,7 @@ public virtual ICommitLog QueryBy(Filter filter)
91
89
Ensure . ArgumentNotNull ( filter . Since , "filter.Since" ) ;
92
90
Ensure . ArgumentNotNullOrEmptyString ( filter . Since . ToString ( ) , "filter.Since" ) ;
93
91
94
- return new CommitLog ( repo , filter . SortBy )
95
- {
96
- includedIdentifier = ToList ( filter . Since ) ,
97
- excludedIdentifier = ToList ( filter . Until )
98
- } ;
99
- }
100
-
101
- private static IList < object > ToList ( object obj )
102
- {
103
- var list = new List < object > ( ) ;
104
-
105
- if ( obj == null )
106
- {
107
- return list ;
108
- }
109
-
110
- var types = new [ ]
111
- {
112
- typeof ( string ) , typeof ( ObjectId ) ,
113
- typeof ( Commit ) , typeof ( TagAnnotation ) ,
114
- typeof ( Tag ) , typeof ( Branch ) , typeof ( DetachedHead ) ,
115
- typeof ( Reference ) , typeof ( DirectReference ) , typeof ( SymbolicReference )
116
- } ;
117
-
118
- if ( types . Contains ( obj . GetType ( ) ) )
119
- {
120
- list . Add ( obj ) ;
121
- return list ;
122
- }
123
-
124
- list . AddRange ( ( ( IEnumerable ) obj ) . Cast < object > ( ) ) ;
125
- return list ;
92
+ return new CommitLog ( repo , filter ) ;
126
93
}
127
94
128
95
private static bool PointsAtTheHead ( string shaOrRefName )
@@ -222,17 +189,17 @@ private class CommitEnumerator : IEnumerator<Commit>
222
189
private readonly RevWalkerSafeHandle handle ;
223
190
private ObjectId currentOid ;
224
191
225
- public CommitEnumerator ( Repository repo , IList < object > includedIdentifier , IList < object > excludedIdentifier , GitSortOptions sortingStrategy )
192
+ public CommitEnumerator ( Repository repo , Filter filter )
226
193
{
227
194
this . repo = repo ;
228
195
int res = NativeMethods . git_revwalk_new ( out handle , repo . Handle ) ;
229
196
repo . RegisterForCleanup ( handle ) ;
230
197
231
198
Ensure . Success ( res ) ;
232
199
233
- Sort ( sortingStrategy ) ;
234
- Push ( includedIdentifier ) ;
235
- Hide ( excludedIdentifier ) ;
200
+ Sort ( filter . SortBy ) ;
201
+ Push ( filter . SinceList ) ;
202
+ Hide ( filter . UntilList ) ;
236
203
}
237
204
238
205
#region IEnumerator<Commit> Members
0 commit comments