@@ -13,6 +13,7 @@ public class CommitCollection : IQueryableCommitCollection
13
13
{
14
14
private readonly Repository repo ;
15
15
private ObjectId pushedObjectId ;
16
+ private ObjectId hiddenObjectId ;
16
17
private readonly GitSortOptions sortOptions ;
17
18
18
19
/// <summary>
@@ -53,10 +54,10 @@ public IEnumerator<Commit> GetEnumerator()
53
54
{
54
55
if ( pushedObjectId == null )
55
56
{
56
- throw new NotImplementedException ( ) ;
57
+ throw new InvalidOperationException ( ) ;
57
58
}
58
59
59
- return new CommitEnumerator ( repo , pushedObjectId , sortOptions ) ;
60
+ return new CommitEnumerator ( repo , pushedObjectId , hiddenObjectId , sortOptions ) ;
60
61
}
61
62
62
63
/// <summary>
@@ -80,21 +81,35 @@ public ICommitCollection QueryBy(Filter filter)
80
81
Ensure . ArgumentNotNull ( filter , "filter" ) ;
81
82
Ensure . ArgumentNotNull ( filter . Since , "filter.Since" ) ;
82
83
83
- string shaOrRefName = filter . Since . ToString ( ) ;
84
+ string sinceIdentifier = filter . Since . ToString ( ) ;
84
85
85
- if ( ( repo . Info . IsEmpty ) & & PointsAtTheHead ( shaOrRefName ) )
86
+ if ( ( repo . Info . IsEmpty ) & & PointsAtTheHead ( sinceIdentifier ) )
86
87
{
87
88
return new EmptyCommitCollection ( filter . SortBy ) ;
88
- }
89
+ }
90
+
91
+ ObjectId sinceObjectId = RetrieveCommitId ( sinceIdentifier ) ;
92
+ ObjectId untilObjectId = null ;
93
+
94
+ if ( filter . Until != null )
95
+ {
96
+ untilObjectId = RetrieveCommitId ( filter . Until . ToString ( ) ) ;
97
+ }
98
+
99
+ return new CommitCollection ( repo , filter . SortBy ) { pushedObjectId = sinceObjectId , hiddenObjectId = untilObjectId } ;
100
+ }
89
101
90
- GitObject gitObj = repo . Lookup ( shaOrRefName ) ;
102
+ private ObjectId RetrieveCommitId ( string shaOrReferenceName )
103
+ {
104
+ GitObject gitObj = repo . Lookup ( shaOrReferenceName ) ;
91
105
92
- if ( gitObj == null ) // TODO: Should we check the type? Git-log allows TagAnnotation oid as parameter. But what about Blobs and Trees?
106
+ // TODO: Should we check the type? Git-log allows TagAnnotation oid as parameter. But what about Blobs and Trees?
107
+ if ( gitObj == null )
93
108
{
94
- throw new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture , "No valid git object pointed at by '{0}' exists in the repository." , filter . Since ) ) ;
109
+ throw new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture , "No valid git object pointed at by '{0}' exists in the repository." , shaOrReferenceName ) ) ;
95
110
}
96
111
97
- return new CommitCollection ( repo , filter . SortBy ) { pushedObjectId = gitObj . Id } ;
112
+ return gitObj . Id ;
98
113
}
99
114
100
115
private static bool PointsAtTheHead ( string shaOrRefName )
@@ -110,14 +125,15 @@ private class CommitEnumerator : IEnumerator<Commit>
110
125
private readonly RevWalkerSafeHandle handle ;
111
126
private ObjectId currentOid ;
112
127
113
- public CommitEnumerator ( Repository repo , ObjectId pushedOid , GitSortOptions sortingStrategy )
128
+ public CommitEnumerator ( Repository repo , ObjectId pushedOid , ObjectId hiddenOid , GitSortOptions sortingStrategy )
114
129
{
115
130
this . repo = repo ;
116
131
int res = NativeMethods . git_revwalk_new ( out handle , repo . Handle ) ;
117
132
Ensure . Success ( res ) ;
118
133
119
134
Sort ( sortingStrategy ) ;
120
135
Push ( pushedOid ) ;
136
+ Hide ( hiddenOid ) ;
121
137
}
122
138
123
139
#region IEnumerator<Commit> Members
@@ -187,6 +203,18 @@ private void Push(ObjectId pushedOid)
187
203
Ensure . Success ( res ) ;
188
204
}
189
205
206
+ private void Hide ( ObjectId hiddenOid )
207
+ {
208
+ if ( hiddenOid == null )
209
+ {
210
+ return ;
211
+ }
212
+
213
+ var oid = hiddenOid . Oid ;
214
+ int res = NativeMethods . git_revwalk_hide ( handle , ref oid ) ;
215
+ Ensure . Success ( res ) ;
216
+ }
217
+
190
218
private void Sort ( GitSortOptions options )
191
219
{
192
220
NativeMethods . git_revwalk_sorting ( handle , options ) ;
0 commit comments