8000 Get rid of GitRefSpecHandle · UiPath/libgit2sharp@70074f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70074f9

Browse files
committed
Get rid of GitRefSpecHandle
1 parent c0cf249 commit 70074f9

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

LibGit2Sharp/Core/Handles/GitRefSpecHandle.cs

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

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,31 +1110,31 @@ internal static extern IntPtr git_reflog_entry_committer(
11101110
internal static extern string git_reflog_entry_message(SafeHandle entry);
11111111

11121112
[DllImport(libgit2)]
1113-
internal static extern int git_refspec_rtransform(
1113+
internal static extern unsafe int git_refspec_rtransform(
11141114
GitBuf buf,
1115-
GitRefSpecHandle refSpec,
1115+
git_refspec* refSpec,
11161116
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name);
11171117

11181118
[DllImport(libgit2)]
11191119
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1120-
internal static extern string git_refspec_string(
1121-
GitRefSpecHandle refSpec);
1120+
internal static extern unsafe string git_refspec_string(
1121+
git_refspec* refSpec);
11221122

11231123
[DllImport(libgit2)]
1124-
internal static extern RefSpecDirection git_refspec_direction(GitRefSpecHandle refSpec);
1124+
internal static extern unsafe RefSpecDirection git_refspec_direction(git_refspec* refSpec);
11251125

11261126
[DllImport(libgit2)]
11271127
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1128-
internal static extern string git_refspec_dst(
1129-
GitRefSpecHandle refSpec);
1128+
internal static extern unsafe string git_refspec_dst(
1129+
git_refspec* refSpec);
11301130

11311131
[DllImport(libgit2)]
11321132
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1133-
internal static extern string git_refspec_src(
1134-
GitRefSpecHandle refSpec);
1133+
internal static extern unsafe string git_refspec_src(
1134+
git_refspec* refSpec);
11351135

11361136
[DllImport(libgit2)]
1137-
internal static extern bool git_refspec_force(GitRefSpecHandle refSpec);
1137+
internal static extern unsafe bool git_refspec_force(git_refspec* refSpec);
11381138

11391139
[DllImport(libgit2)]
11401140
internal static extern int git_remote_autotag(RemoteSafeHandle remote);
@@ -1187,7 +1187,7 @@ internal static extern int git_remote_fetch(
11871187
internal static extern int git_remote_get_fetch_refspecs(out GitStrArray array, RemoteSafeHandle remote);
11881188

11891189
[DllImport(libgit2)]
1190-
internal static extern GitRefSpecHandle git_remote_get_refspec(RemoteSafeHandle remote, UIntPtr n);
1190+
internal static extern unsafe git_refspec* git_remote_get_refspec(RemoteSafeHandle remote, UIntPtr n);
11911191

11921192
[DllImport(libgit2)]
11931193
internal static extern int git_remote_get_push_refspecs(out GitStrArray array, RemoteSafeHandle remote);

LibGit2Sharp/Core/Opaques.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ namespace LibGit2Sharp.Core
44
{
55
internal struct git_tree_entry {}
66
internal s A8C6 truct git_reference { }
7+
internal struct git_refspec {}
78
}
89

LibGit2Sharp/Core/Proxy.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ public static string git_reflog_entry_message(SafeHandle entry)
19901990

19911991
#region git_refspec
19921992

1993-
public static string git_refspec_rtransform(GitRefSpecHandle refSpecPtr, string name)
1993+
public static unsafe string git_refspec_rtransform(git_refspec* refSpecPtr, string name)
19941994
{
19951995
using (var buf = new GitBuf())
19961996
{
@@ -2001,27 +2001,27 @@ public static string git_refspec_rtransform(GitRefSpecHandle refSpecPtr, string
20012001
}
20022002
}
20032003

2004-
public static string git_refspec_string(GitRefSpecHandle refSpec)
2004+
public static unsafe string git_refspec_string(git_refspec* refSpec)
20052005
{
20062006
return NativeMethods.git_refspec_string(refSpec);
20072007
}
20082008

2009-
public static string git_refspec_src(GitRefSpecHandle refSpec)
2009+
public static unsafe string git_refspec_src(git_refspec* refSpec)
20102010
{
20112011
return NativeMethods.git_refspec_src(refSpec);
20122012
}
20132013

2014-
public static string git_refspec_dst(GitRefSpecHandle refSpec)
2014+
public static unsafe string git_refspec_dst(git_refspec* refSpec)
20152015
{
20162016
return NativeMethods.git_refspec_dst(refSpec);
20172017
}
20182018

2019-
public static RefSpecDirection git_refspec_direction(GitRefSpecHandle refSpec)
2019+
public static unsafe RefSpecDirection git_refspec_direction(git_refspec* refSpec)
20202020
{
20212021
return NativeMethods.git_refspec_direction(refSpec);
20222022
}
20232023

2024-
public static bool git_refspec_force(GitRefSpecHandle refSpec)
2024+
public static unsafe bool git_refspec_force(git_refspec* refSpec)
20252025
{
20262026
return NativeMethods.git_refspec_force(refSpec);
20272027
}
@@ -2089,7 +2089,7 @@ public static void git_remote_delete(RepositorySafeHandle repo, string name)
20892089
Ensure.ZeroResult(res);
20902090
}
20912091

2092-
public static GitRefSpecHandle git_remote_get_refspec(RemoteSafeHandle remote, int n)
2092+
public static unsafe git_refspec* git_remote_get_refspec(RemoteSafeHandle remote, int n)
20932093
{
20942094
return NativeMethods.git_remote_get_refspec(remote, (UIntPtr)n);
20952095
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@
192192
<Compile Include="ConflictCollection.cs" />
193193
<Compile Include="RemoteUpdater.cs" />
194194
<Compile Include="RemoveFromIndexException.cs" />
195-
<Compile Include="Core\Handles\GitRefSpecHandle.cs" />
196195
<Compile Include="Core\Handles\NullRepositorySafeHandle.cs" />
197196
<Compile Include="GitLink.cs" />
198197
<Compile Include="Core\RepositoryOpenFlags.cs" />

LibGit2Sharp/RefSpec.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System;
2+
using System.Diagnostics;
23
using System.Globalization;
34
using LibGit2Sharp.Core;
45
using LibGit2Sharp.Core.Handles;
@@ -30,9 +31,12 @@ private RefSpec(string refSpec, RefSpecDirection direction, string source, strin
3031
protected RefSpec()
3132
{ }
3233

33-
internal static RefSpec BuildFromPtr(GitRefSpecHandle handle)
34+
internal static unsafe RefSpec BuildFromPtr(git_refspec* handle)
3435
{
35-
Ensure.ArgumentNotNull(handle, "handle");
36+
if (handle == null)
37+
{
38+
throw new ArgumentNullException("handle");
39+
}
3640

3741
return new RefSpec(Proxy.git_refspec_string(handle), Proxy.git_refspec_direction(handle),
3842
Proxy.git_refspec_src(handle), Proxy.git_refspec_dst(handle), Proxy.git_refspec_force(handle));

LibGit2Sharp/RefSpecCollection.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ internal RefSpecCollection(RemoteSafeHandle handle)
2929
refspecs = RetrieveRefSpecs(handle);
3030
}
3131

32-
static IList<RefSpec> RetrieveRefSpecs(RemoteSafeHandle remoteHandle)
32+
static unsafe IList<RefSpec> RetrieveRefSpecs(RemoteSafeHandle remoteHandle)
3333
{
3434
int count = Proxy.git_remote_refspec_count(remoteHandle);
3535
List<RefSpec> refSpecs = new List<RefSpec>();
3636

3737
for (int i = 0; i < count; i++)
3838
{
39-
using (GitRefSpecHandle handle = Proxy.git_remote_get_refspec(remoteHandle, i))
40-
{
41-
refSpecs.Add(RefSpec.BuildFromPtr(handle));
42-
}
39+
git_refspec* handle = Proxy.git_remote_get_refspec(remoteHandle, i);
40+
refSpecs.Add(RefSpec.BuildFromPtr(handle));
4341
}
4442

4543
return refSpecs;

LibGit2Sharp/Remote.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public virtual IEnumerable<RefSpec> PushRefSpecs
9898
/// </summary>
9999
/// <param name="reference">The reference to transform.</param>
100100
/// <returns>The transformed reference.</returns>
101-
internal string FetchSpecTransformToSource(string reference)
101+
internal unsafe string FetchSpecTransformToSource(string reference)
102102
{
103103
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, Name, true))
104104
{
105-
GitRefSpecHandle fetchSpecPtr = Proxy.git_remote_get_refspec(remoteHandle, 0);
105+
git_refspec* fetchSpecPtr = Proxy.git_remote_get_refspec(remoteHandle, 0);
106106
return Proxy.git_refspec_rtransform(fetchSpecPtr, reference);
107107
}
108108
}

0 commit comments

Comments
 (0)
0