Skip to content

Commit 966ec5a

Browse files
committed
Get rid of the index entry SafeHandle
1 parent 92fc8f5 commit 966ec5a

File tree

7 files changed

+15
-41
lines changed

7 files changed

+15
-41
lines changed

LibGit2Sharp/Core/GitIndexEntry.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal unsafe struct git_index_mtime
1313
[StructLayout(LayoutKind.Sequential)]
1414
internal unsafe struct git_index_entry
1515
{
16+
internal const ushort GIT_IDXENTRY_VALID = 0x8000;
17+
1618
public git_index_mtime ctime;
1719
public git_index_mtime mtime;
1820
public uint dev;
@@ -26,23 +28,4 @@ internal unsafe struct git_index_entry
2628
public ushort extended_flags;
2729
public char* path;
2830
}
29-
30-
[StructLayout(LayoutKind.Sequential)]
31-
internal class GitIndexEntry
32-
{
33-
internal const ushort GIT_IDXENTRY_VALID = 0x8000;
34-
35-
public GitIndexTime CTime;
36-
public GitIndexTime MTime;
37-
public uint Dev;
38-
public uint Ino;
39-
public uint Mode;
40-
public uint Uid;
41-
public uint Gid;
42-
public uint file_size;
43-
public GitOid Id;
44-
public ushort Flags;
45-
public ushort ExtendedFlags;
46-
public IntPtr Path;
47-
}
4831
}

LibGit2Sharp/Core/Handles/IndexEntrySafeHandle.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,9 @@ internal static extern int git_index_add_bypath(
629629
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
630630

631631
[DllImport(libgit2)]
632-
internal static extern int git_index_add(
632+
internal static extern unsafe int git_index_add(
633633
IndexSafeHandle index,
634-
GitIndexEntry entry);
634+
git_index_entry* entry);
635635

636636
[DllImport(libgit2)]
637637
internal static extern unsafe int git_index_conflict_get(

LibGit2Sharp/Core/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public static bool git_ignore_path_is_ignored(RepositorySafeHandle repo, string
893893

894894
#region git_index_
895895

896-
public static void git_index_add(IndexSafeHandle index, GitIndexEntry entry)
896+
public static unsafe void git_index_add(IndexSafeHandle index, git_index_entry* entry)
897897
{
898898
int res = NativeMethods.git_index_add(index, entry);
899899
Ensure.ZeroResult(res);

LibGit2Sharp/Index.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Diagnostics;
55
using System.Globalization;
6+
using System.Runtime.InteropServices;
67
using LibGit2Sharp.Core;
78
using LibGit2Sharp.Core.Handles;
89

@@ -270,17 +271,18 @@ public virtual ConflictCollection Conflicts
270271
get { return conflicts; }
271272
}
272273

273-
private void AddEntryToTheIndex(string path, ObjectId id, Mode mode)
274+
private unsafe void AddEntryToTheIndex(string path, ObjectId id, Mode mode)
274275
{
275-
var indexEntry = new GitIndexEntry
276+
IntPtr pathPtr = StrictFilePathMarshaler.FromManaged(path);
277+
var indexEntry = new git_index_entry
276278
{
277-
Mode = (uint)mode,
278-
Id = id.Oid,
279-
Path = StrictFilePathMarshaler.FromManaged(path),
279+
mode = (uint)mode,
280+
path = (char*) pathPtr,
280281
};
282+
Marshal.Copy(id.RawId, 0, new IntPtr(indexEntry.id.Id), GitOid.Size);
281283

282-
Proxy.git_index_add(handle, indexEntry);
283-
EncodingMarshaler.Cleanup(indexEntry.Path);
284+
Proxy.git_index_add(handle, &indexEntry);
285+
EncodingMarshaler.Cleanup(pathPtr);
284286
}
285287

286288
private string DebuggerDisplay

LibGit2Sharp/IndexEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal static unsafe IndexEntry BuildFromPtr(git_index_entry* entry)
5555
Id = new ObjectId(entry->id.Id),
5656
StageLevel = Proxy.git_index_entry_stage(entry),
5757
Mode = (Mode)entry->mode,
58-
AssumeUnchanged = (GitIndexEntry.GIT_IDXENTRY_VALID & entry->flags) == GitIndexEntry.GIT_IDXENTRY_VALID
58+
AssumeUnchanged = (git_index_entry.GIT_IDXENTRY_VALID & entry->flags) == git_index_entry.GIT_IDXENTRY_VALID
5959
};
6060
}
6161

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@
284284
<Compile Include="Core\Handles\ObjectDatabaseSafeHandle.cs" />
285285
<Compile Include="Core\Handles\DiffSafeHandle.cs" />
286286
<Compile Include="Core\Handles\GitObjectSafeHandle.cs" />
287-
<Compile Include="Core\Handles\IndexEntrySafeHandle.cs" />
288287
<Compile Include="Core\Handles\NotOwnedSafeHandleBase.cs" />
289288
<Compile Include="Core\Handles\OidSafeHandle.cs" />
290289
<Compile Include="Core\Handles\TreeBuilderSafeHandle.cs" />

0 commit comments

Comments
 (0)