/// <summary> /// Try to lookup an object by its <see cref = "ObjectId" /> and <see cref = "GitObjectType" />. If no matching object is found, null will be returned. /// </summary> /// <param name = "id">The id to lookup.</param> /// <param name = "type">The kind of GitObject being looked up</param> /// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns> public GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any) { Ensure.ArgumentNotNull(id, "id"); GitOid oid = id.Oid; IntPtr obj; int res; if (id is AbbreviatedObjectId) { res = NativeMethods.git_object_lookup_prefix(out obj, handle, ref oid, (uint)((AbbreviatedObjectId)id).Length, type); } else { res = NativeMethods.git_object_lookup(out obj, handle, ref oid, type); } if (res == (int)GitErrorCode.GIT_ENOTFOUND || res == (int)GitErrorCode.GIT_EINVALIDTYPE) { return(null); } Ensure.Success(res); if (id is AbbreviatedObjectId) { id = GitObject.ObjectIdOf(obj); } return(GitObject.CreateFromPtr(obj, id, this)); }
internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath knownPath) { Ensure.ArgumentNotNull(id, "id"); GitOid oid = id.Oid; GitObjectSafeHandle obj = null; try { int res; if (id is AbbreviatedObjectId) { res = NativeMethods.git_object_lookup_prefix(out obj, handle, ref oid, (uint)((AbbreviatedObjectId)id).Length, type); } else { res = NativeMethods.git_object_lookup(out obj, handle, ref oid, type); } if (res == (int)GitErrorCode.GIT_ENOTFOUND) { return(null); } Ensure.Success(res); if (id is AbbreviatedObjectId) { id = GitObject.ObjectIdOf(obj); } return(GitObject.CreateFromPtr(obj, id, this, knownPath)); } finally { obj.SafeDispose(); } }