@@ -15,7 +15,7 @@ public class ObjectDatabase
15
15
{
16
16
private readonly Repository repo ;
17
17
private readonly ObjectDatabaseSafeHandle handle ;
18
- private List < ObjectId > objects = new List < ObjectId > ( ) ;
18
+ private List < ObjectId > objects = null ;
19
19
20
20
public Diff Diff
21
21
{
@@ -44,6 +44,8 @@ internal ObjectDatabase(Repository repo)
44
44
internal ObjectDatabase ( ObjectDatabaseSafeHandle handle )
45
45
{
46
46
this . handle = handle ;
47
+ this . repo = new Repository ( this ) ;
48
+ repo . RegisterForCleanup ( handle ) ;
47
49
}
48
50
49
51
internal ObjectDatabaseSafeHandle Handle
@@ -65,6 +67,10 @@ private int ForeachCallback(ref GitOid oid, IntPtr data)
65
67
/// </returns>
66
68
public List < ObjectId > AllObjects ( )
67
69
{
70
+ if ( objects != null )
71
+ return objects ;
72
+
73
+ objects = new List < ObjectId > ( ) ;
68
74
Ensure . Success ( NativeMethods . git_odb_foreach ( handle , ForeachCallback , IntPtr . Zero ) ) ;
69
75
return objects ;
70
76
}
@@ -168,43 +174,15 @@ internal Commit CreateCommit(string message, Signature author, Signature committ
168
174
return repo . Lookup < Commit > ( new ObjectId ( commitOid ) ) ;
169
175
}
170
176
171
- internal GitObject LookupInternal ( ObjectId id , GitObjectType type , FilePath knownPath )
177
+ /// <summary>
178
+ /// Try to lookup an object by its sha or a reference canonical name and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
179
+ /// </summary>
180
+ /// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
181
+ /// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
182
+ /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
183
+ public GitObject Lookup ( string shaOrReferenceName , GitObjectType type = GitObjectType . Any )
172
184
{
173
- Ensure . ArgumentNotNull ( id , "id" ) ;
174
-
175
- GitOid oid = id . Oid ;
176
- GitObjectSafeHandle obj = null ;
177
-
178
- try
179
- {
180
- int res ;
181
- if ( id is AbbreviatedObjectId )
182
- {
183
- res = NativeMethods . git_object_lookup_prefix_odb ( out obj , handle , ref oid , ( uint ) ( ( AbbreviatedObjectId ) id ) . Length , type ) ;
184
- }
185
- else
186
- {
187
- res = NativeMethods . git_object_lookup_odb ( out obj , handle , ref oid , type ) ;
188
- }
189
-
190
- if ( res == ( int ) GitErrorCode . GIT_ENOTFOUND )
191
- {
192
- return null ;
193
- }
194
-
195
- Ensure . Success ( res ) ;
196
-
197
- if ( id is AbbreviatedObjectId )
198
- {
199
- id = GitObject . ObjectIdOf ( obj ) ;
200
- }
201
-
202
- return GitObject . CreateFromPtr ( obj , id , this , knownPath ) ;
203
- }
204
- finally
205
- {
206
- obj . SafeDispose ( ) ;
207
- }
185
+ return repo . Lookup ( shaOrReferenceName , type , LookUpOptions . None ) ;
208
186
}
209
187
210
188
/// <summary>
@@ -215,12 +193,12 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
215
193
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
216
194
public GitObject Lookup ( ObjectId id , GitObjectType type = GitObjectType . Any )
217
195
{
218
- return LookupInternal ( id , type , null ) ;
196
+ return repo . Lookup ( id , type ) ;
219
197
}
220
198
221
199
internal GitObject LookupTreeEntryTarget ( ObjectId id , FilePath path )
222
200
{
223
- return LookupInternal ( id , GitObjectType . Any , path ) ;
201
+ return repo . LookupTreeEntryTarget ( id , path ) ;
224
202
}
225
203
226
204
}
0 commit comments