@@ -32,7 +32,7 @@ internal NoteCollection(Repository repo)
32
32
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
33
33
public IEnumerator < Note > GetEnumerator ( )
34
34
{
35
- throw new NotImplementedException ( ) ;
35
+ return this [ DefaultNamespace ] . GetEnumerator ( ) ;
36
36
}
37
37
38
38
/// <summary>
@@ -92,16 +92,33 @@ public IEnumerable<Note> this[ObjectId id]
92
92
}
93
93
}
94
94
95
- internal Note RetrieveNote ( ObjectId id , string canonicalNamespace )
95
+ /// <summary>
96
+ /// Gets the collection of <see cref = "Note"/> associated with the specified namespace.
97
+ /// <para>This is similar to the 'get notes list' command.</para>
98
+ /// </summary>
99
+ public IEnumerable < Note > this [ string @namespace ]
100
+ {
101
+ get
102
+ {
103
+ Ensure . ArgumentNotNull ( @namespace , "@namespace" ) ;
104
+
105
+ string canonicalNamespace = NormalizeToCanonicalName ( @namespace ) ;
106
+ var notesOidRetriever = new NotesOidRetriever ( repo , canonicalNamespace ) ;
107
+
108
+ return notesOidRetriever . Retrieve ( ) . Select ( oid => RetrieveNote ( new ObjectId ( oid ) , canonicalNamespace ) ) ;
109
+ }
110
+ }
111
+
112
+ internal Note RetrieveNote ( ObjectId targetObjectId , string canonicalNamespace )
96
113
{
97
- using ( NoteSafeHandle noteHandle = BuildNoteSafeHandle ( id , canonicalNamespace ) )
114
+ using ( NoteSafeHandle noteHandle = BuildNoteSafeHandle ( targetObjectId , canonicalNamespace ) )
98
115
{
99
116
if ( noteHandle == null )
100
117
{
101
118
return null ;
102
119
}
103
120
104
- return Note . BuildFromPtr ( repo , UnCanonicalizeName ( canonicalNamespace ) , id , noteHandle ) ;
121
+ return Note . BuildFromPtr ( repo , UnCanonicalizeName ( canonicalNamespace ) , targetObjectId , noteHandle ) ;
105
122
}
106
123
}
107
124
@@ -184,7 +201,7 @@ public Note Create(ObjectId targetId, string message, Signature author, Signatur
184
201
Ensure . Success ( NativeMethods . git_note_create ( out noteOid , repo . Handle , authorHandle , committerHandle , canonicalNamespace , ref oid , message ) ) ;
185
202
}
186
203
187
- return this [ targetId ] . First ( n => n . Namespace == @namespace ) ;
204
+ return RetrieveNote ( targetId , canonicalNamespace ) ;
188
205
}
189
206
190
207
/// <summary>
@@ -219,5 +236,27 @@ public void Delete(ObjectId targetId, Signature author, Signature committer, str
219
236
220
237
Ensure . Success ( res ) ;
221
238
}
239
+
240
+ private class NotesOidRetriever
241
+ {
242
+ private readonly List < GitOid > notesOid = new List < GitOid > ( ) ;
243
+
244
+ internal NotesOidRetriever ( Repository repo , string canonicalNamespace )
245
+ {
246
+ Ensure . Success ( NativeMethods . git_note_foreach ( repo . Handle , canonicalNamespace , NoteListCallBack , IntPtr . Zero ) ) ;
247
+ }
248
+
249
+ private int NoteListCallBack ( GitNoteData noteData , IntPtr intPtr )
250
+ {
251
+ notesOid . Add ( noteData . TargetOid ) ;
252
+
253
+ return 0 ;
254
+ }
255
+
256
+ public IEnumerable < GitOid > Retrieve ( )
257
+ {
258
+ return notesOid ;
259
+ }
260
+ }
222
261
}
223
262
}
0 commit comments