diff --git a/LibGit2Sharp/Core/Handles/UnownedTreeEntryHandle.cs b/LibGit2Sharp/Core/Handles/UnownedTreeEntryHandle.cs new file mode 100644 index 000000000..f2d422d58 --- /dev/null +++ b/LibGit2Sharp/Core/Handles/UnownedTreeEntryHandle.cs @@ -0,0 +1,16 @@ +using System; + +namespace LibGit2Sharp.Core.Handles; + +internal unsafe class UnownedTreeEntryHandle : TreeEntryHandle +{ + internal UnownedTreeEntryHandle() + : base(IntPtr.Zero, false) + { + } + + internal UnownedTreeEntryHandle(IntPtr ptr) + : base(ptr, false) + { + } +} diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 0991fbf53..61128f1f4 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1998,7 +1998,7 @@ internal static extern int git_transport_unregister( internal static extern unsafe uint git_tree_entry_filemode(TreeEntryHandle entry); [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] - internal static extern unsafe TreeEntryHandle git_tree_entry_byindex(ObjectHandle tree, UIntPtr idx); + internal static extern unsafe UnownedTreeEntryHandle git_tree_entry_byindex(ObjectHandle tree, UIntPtr idx); [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] internal static extern unsafe int git_tree_entry_bypath( diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index a910e5f85..bc7520c2e 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -3189,12 +3189,13 @@ public static unsafe Mode git_tree_entry_attributes(TreeEntryHandle entry) public static unsafe TreeEntryHandle git_tree_entry_byindex(ObjectHandle tree, long idx) { var handle = NativeMethods.git_tree_entry_byindex(tree, (UIntPtr)idx); + if (handle == null) { return null; } - return new TreeEntryHandle(handle, false); + return handle; } public static unsafe TreeEntryHandle git_tree_entry_bypath(RepositoryHandle repo, ObjectId id, string treeentry_path)