Skip to content

Commit 46548c5

Browse files
committed
Prefer commit parent ObjectId over handle
1 parent feed150 commit 46548c5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

LibGit2Sharp/Commit.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@ private IEnumerable<Commit> RetrieveParentsOfCommit(ObjectId oid)
124124

125125
for (uint i = 0; i < parentsCount; i++)
126126
{
127-
using (var parentCommit = Proxy.git_commit_parent(obj, i))
128-
{
129-
yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo);
130-
}
127+
ObjectId parentCommitId = Proxy.git_commit_parent_oid(obj.ObjectPtr, i);
128+
yield return (Commit)repo.LookupInternal(parentCommitId, GitObjectType.Commit, null);
131129
}
132130
}
133131
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ internal static extern int git_commit_create(
180180
[DllImport(libgit2)]
181181
internal static extern int git_commit_parent(out GitObjectSafeHandle parentCommit, GitObjectSafeHandle commit, uint n);
182182

183+
[DllImport(libgit2)]
184+
internal static extern OidSafeHandle git_commit_parent_oid(GitObjectSafeHandle commit, uint n);
185+
183186
[DllImport(libgit2)]
184187
internal static extern uint git_commit_parentcount(GitObjectSafeHandle commit);
185188

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public static GitObjectSafeHandle git_commit_parent(ObjectSafeWrapper obj, uint
242242
}
243243
}
244244

245+
public static ObjectId git_commit_parent_oid(GitObjectSafeHandle obj, uint i)
246+
{
247+
return NativeMethods.git_commit_parent_oid(obj, i).MarshalAsObjectId();
248+
}
249+
245250
public static int git_commit_parentcount(RepositorySafeHandle repo, ObjectId id)
246251
{
247252
using (var obj = new ObjectSafeWrapper(id, repo))

0 commit comments

Comments
 (0)