/// <summary> /// Lookup and return the git object in the repository as specified /// by the given ID. /// </summary> /// <param name="id">The object id to lookup</param> /// <returns>The Git object specified by the given ID</returns> public unsafe GitObject Lookup(ObjectId id) { Ensure.ArgumentNotNull(id, "id"); git_oid oid = id.ToNative(); git_object *obj = null; Ensure.NativeSuccess(() => libgit2.git_object_lookup(out obj, repository.NativeRepository, ref oid, git_object_t.GIT_OBJECT_ANY), repository); Ensure.NativePointerNotNull(obj); switch (libgit2.git_object_type(obj)) { case git_object_t.GIT_OBJECT_COMMIT: return(Commit.FromNative((git_commit *)obj, id)); case git_object_t.GIT_OBJECT_TREE: return(Tree.FromNative((git_tree *)obj, id)); case git_object_t.GIT_OBJECT_BLOB: return(Blob.FromNative((git_blob *)obj, id)); } libgit2.git_object_free(obj); throw new InvalidOperationException("unknown object type"); }
internal unsafe GitObject(git_object *nativeObject, ObjectId id = null) { Ensure.NativePointerNotNull(nativeObject); this.nativeObject = nativeObject; this.id = id; }
internal unsafe override void Dispose(bool disposing) { if (nativeObject != null) { libgit2.git_object_free(nativeObject); nativeObject = null; } }
internal ObjectHandle(git_object *ptr, bool owned) : base((void *)ptr, owned) { }
public static extern unsafe git_object_t git_object_type(git_object *obj);
public static extern unsafe int git_object_lookup(out git_object *obj, git_repository *repo, ref git_oid id, git_object_t type);
public static extern unsafe git_oid *git_object_id(git_object *obj);
public static extern unsafe void git_object_free(git_object *obj);