8000 Get rid of IndexNameEntrySafeHandle and IndexReucEntrySafeHandle · vrkcse2011/libgit2sharp@707bbc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 707bbc7

Browse files
committed
Get rid of IndexNameEntrySafeHandle and IndexReucEntrySafeHandle
1 parent b2d9e44 commit 707bbc7

11 files changed

+38
-64
lines changed

LibGit2Sharp/Core/GitIndexNameEntry.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
namespace LibGit2Sharp.Core
55
{
66
[StructLayout(LayoutKind.Sequential)]
7-
internal class GitIndexNameEntry
7+
internal unsafe struct git_index_name_entry
88
{
9-
public IntPtr Ancestor;
10-
public IntPtr Ours;
11-
public IntPtr Theirs;
9+
public char* ancestor;
10+
public char* ours;
11+
public char* theirs;
1212
}
1313
}

LibGit2Sharp/Core/GitIndexReucEntry.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
namespace LibGit2Sharp.Core
55
{
66
[StructLayout(LayoutKind.Sequential)]
7-
internal class GitIndexReucEntry
7+
internal unsafe struct git_index_reuc_entry
88
{
99
public uint AncestorMode;
1010
public uint OurMode;
1111
public uint TheirMode;
12-
public GitOid AncestorId;
13-
public GitOid OurId;
14-
public GitOid TheirId;
15-
public IntPtr Path;
12+
public git_oid AncestorId;
13+
public git_oid OurId;
14+
public git_oid TheirId;
15+
public char* Path;
1616
}
1717
}

LibGit2Sharp/Core/Handles/IndexNameEntrySafeHandle.cs

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

LibGit2Sharp/Core/Handles/IndexReucEntrySafeHandle.cs

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

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ internal static extern void git_index_conflict_iterator_free(
682682
internal static extern UIntPtr git_index_name_entrycount(IndexSafeHandle handle);
683683

684684
[DllImport(libgit2)]
685-
internal static extern IndexNameEntrySafeHandle git_index_name_get_byindex(IndexSafeHandle handle, UIntPtr n);
685+
internal static extern unsafe git_index_name_entry* git_index_name_get_byindex(IndexSafeHandle handle, UIntPtr n);
686686

687687
[DllImport(libgit2)]
688688
internal static extern int git_index_open(
@@ -704,10 +704,10 @@ internal static extern int git_index_remove_bypath(
704704
internal static extern UIntPtr git_index_reuc_entrycount(IndexSafeHandle handle);
705705

706706
[DllImport(libgit2)]
707-
internal static extern IndexReucEntrySafeHandle git_index_reuc_get_byindex(IndexSafeHandle handle, UIntPtr n);
707+
internal static extern unsafe git_index_reuc_entry* git_index_reuc_get_byindex(IndexSafeHandle handle, UIntPtr n);
708708

709709
[DllImport(libgit2)]
710-
internal static extern IndexReucEntrySafeHandle git_index_reuc_get_bypath(
710+
internal static extern unsafe git_index_reuc_entry* git_index_reuc_get_bypath(
711711
IndexSafeHandle handle,
712712
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
713713

LibGit2Sharp/Core/Proxy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ public static int git_index_name_entrycount(IndexSafeHandle index)
10221022
.ConvertToInt();
10231023
}
10241024

1025-
public static IndexNameEntrySafeHandle git_index_name_get_byindex(IndexSafeHandle index, UIntPtr n)
1025+
public static unsafe git_index_name_entry* git_index_name_get_byindex(IndexSafeHandle index, UIntPtr n)
10261026
{
10271027
return NativeMethods.git_index_name_get_byindex(index, n);
10281028
}
@@ -1054,12 +1054,12 @@ public static int git_index_reuc_entrycount(IndexSafeHandle index)
10541054
.ConvertToInt();
10551055
}
10561056

1057-
public static IndexReucEntrySafeHandle git_index_reuc_get_byindex(IndexSafeHandle index, UIntPtr n)
1057+
public static unsafe git_index_reuc_entry* git_index_reuc_get_byindex(IndexSafeHandle index, UIntPtr n)
10581058
{
10591059
return NativeMethods.git_index_reuc_get_byindex(index, n);
10601060
}
10611061

1062-
public static IndexReucEntrySafeHandle git_index_reuc_get_bypath(IndexSafeHandle index, string path)
1062+
public static unsafe git_index_reuc_entry* git_index_reuc_get_bypath(IndexSafeHandle index, string path)
10631063
{
10641064
return NativeMethods.git_index_reuc_get_bypath(index, path);
10651065
}

LibGit2Sharp/IndexNameEntry.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,21 @@ public class IndexNameEntry : IEquatable<IndexNameEntry>
2222
protected IndexNameEntry()
2323
{ }
2424

25-
internal static IndexNameEntry BuildFromPtr(IndexNameEntrySafeHandle handle)
25+
internal static unsafe IndexNameEntry BuildFromPtr(git_index_name_entry* entry)
2626
{
27-
if (handle == null || handle.IsZero)
27+
if (entry == null)
2828
{
2929
return null;
3030
}
3131

32-
GitIndexNameEntry entry = handle.MarshalAsGitIndexNameEntry();
33-
34-
string ancestor = entry.Ancestor != IntPtr.Zero
35-
? LaxFilePathMarshaler.FromNative(entry.Ancestor).Native
32+
string ancestor = entry->ancestor != null
33+
? LaxFilePathMarshaler.FromNative(entry->ancestor)
3634
: null;
37-
string ours = entry.Ours != IntPtr.Zero
38-
? LaxFilePathMarshaler.FromNative(entry.Ours).Native
35+
string ours = entry->ours != null
36+
? LaxFilePathMarshaler.FromNative(entry->ours)
3937
: null;
40-
string theirs = entry.Theirs != IntPtr.Zero
41-
? LaxFilePathMarshaler.FromNative(entry.Theirs).Native
38+
string theirs = entry->theirs != null
39+
? LaxFilePathMarshaler.FromNative(entry->theirs)
4240
: null;
4341

4442
return new IndexNameEntry

LibGit2Sharp/IndexNameEntryCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ internal IndexNameEntryCollection(Index index)
2626
this.index = index;
2727
}
2828

29-
private IndexNameEntry this[int idx]
29+
private unsafe IndexNameEntry this[int idx]
3030
{
3131
get
3232
{
33-
IndexNameEntrySafeHandle entryHandle = Proxy.git_index_name_get_byindex(index.Handle, (UIntPtr)idx);
33+
git_index_name_entry* entryHandle = Proxy.git_index_name_get_byindex(index.Handle, (UIntPtr)idx);
3434
return IndexNameEntry.BuildFromPtr(entryHandle);
3535
}
3636
}

LibGit2Sharp/IndexReucEntry.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,24 @@ public class IndexReucEntry : IEquatable<IndexReucEntry>
2525
protected IndexReucEntry()
2626
{ }
2727

28-
internal static IndexReucEntry BuildFromPtr(IndexReucEntrySafeHandle handle)
28+
internal static unsafe IndexReucEntry BuildFromPtr(git_index_reuc_entry* entry)
2929
{
30-
if (handle == null || handle.IsZero)
30+
if (entry == null)
3131
{
3232
return null;
3333
}
3434

35-
GitIndexReucEntry entry = handle.MarshalAsGitIndexReucEntry();
36-
37-
FilePath path = LaxFilePathMarshaler.FromNative(entry.Path);
35+
FilePath path = LaxUtf8Marshaler.FromNative(entry->Path);
3836

3937
return new IndexReucEntry
4038
{
4139
Path = path.Native,
42-
AncestorId = entry.AncestorId,
43-
AncestorMode = (Mode)entry.AncestorMode,
44-
OurId = entry.OurId,
45-
OurMode = (Mode)entry.OurMode,
46-
TheirId = entry.TheirId,
47-
TheirMode = (Mode)entry.TheirMode,
40+
AncestorId = ObjectId.BuildFromPtr(&entry->AncestorId),
41+
AncestorMode = (Mode)entry->AncestorMode,
42+
OurId = ObjectId.BuildFromPtr(&entry->OurId),
43+
OurMode = (Mode)entry->OurMode,
44+
TheirId = ObjectId.BuildFromPtr(&entry->TheirId),
45+
TheirMode = (Mode)entry->TheirMode,
4846
};
4947
}
5048

LibGit2Sharp/IndexReucEntryCollection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ internal IndexReucEntryCollection(Index index)
2929
/// <summary>
3030
/// Gets the <see cref="IndexReucEntry"/> with the specified relative path.
3131
/// </summary>
32-
public virtual IndexReucEntry this[string path]
32+
public virtual unsafe IndexReucEntry this[string path]
3333
{
3434
get
3535
{
3636
Ensure.ArgumentNotNullOrEmptyString(path, "path");
3737

38-
IndexReucEntrySafeHandle entryHandle = Proxy.git_index_reuc_get_bypath(index.Handle, path);
38+
git_index_reuc_entry* entryHandle = Proxy.git_index_reuc_get_bypath(index.Handle, path);
3939
return IndexReucEntry.BuildFromPtr(entryHandle);
4040
}
4141
}
4242

43-
private IndexReucEntry this[int idx]
43+
private unsafe IndexReucEntry this[int idx]
4444
{
4545
get
4646
{
47-
IndexReucEntrySafeHandle entryHandle = Proxy.git_index_reuc_get_byindex(index.Handle, (UIntPtr)idx);
< 9DF2 code>47+
git_index_reuc_entry* entryHandle = Proxy.git_index_reuc_get_byindex(index.Handle, (UIntPtr)idx);
4848
return IndexReucEntry.BuildFromPtr(entryHandle);
4949
}
5050
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@
8585
<Compile Include="Core\GitIndexReucEntry.cs" />
8686
<Compile Include="Core\GitSubmoduleOptions.cs" />
8787
<Compile Include="Core\Handles\DescribeResultSafeHandle.cs" />
88-
<Compile Include="Core\Handles\IndexNameEntrySafeHandle.cs" />
89-
<Compile Include="Core\Handles\IndexReucEntrySafeHandle.cs" />
9088
<Compile Include="DiffAlgorithm.cs" />
9189
<Compile Include="EntryExistsException.cs" />
9290
<Compile Include="FetchOptionsBase.cs" />

0 commit comments

Comments
 (0)
0