Skip to content

Commit 42ac5d2

Browse files
committed
WIP
1 parent 11aae8b commit 42ac5d2

10 files changed

+102
-96
lines changed

LibGit2Sharp/Core/NativeMethods.cs

+27-32
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ internal static extern unsafe int git_rebase_next(
322322
internal static extern unsafe int git_rebase_commit(
323323
ref GitOid id,
324324
RebaseHandle rebase,
325-
git_signature* author,
326-
git_signature* committer,
325+
SignatureHandle author,
326+
SignatureHandle committer,
327327
IntPtr message_encoding,
328328
IntPtr message);
329329

@@ -334,7 +334,7 @@ internal static extern unsafe int git_rebase_abort(
334334
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
335335
internal static extern unsafe int git_rebase_finish(
336336
RebaseHandle repo,
337-
git_signature* signature);
337+
SignatureHandle signature);
338338

339339
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
340340
internal static extern unsafe void git_rebase_free(RebaseHandle rebase);
@@ -380,18 +380,18 @@ internal static extern unsafe int git_clone(
380380
ref GitCloneOptions opts);
381381

382382
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
383-
internal static extern unsafe git_signature* git_commit_author(ObjectHandle commit);
383+
internal static extern unsafe SignatureHandle git_commit_author(ObjectHandle commit);
384384

385385
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
386-
internal static extern unsafe git_signature* git_commit_committer(ObjectHandle commit);
386+
internal static extern unsafe SignatureHandle git_commit_committer(ObjectHandle commit);
387387

388388
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
389389
internal static extern unsafe int git_commit_create_from_ids(
390390
out GitOid id,
391391
RepositoryHandle repo,
392392
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string updateRef,
393-
git_signature* author,
394-
git_signature* committer,
393+
SignatureHandle author,
394+
SignatureHandle committer,
395395
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string encoding,
396396
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
397397
ref GitOid tree,
@@ -402,8 +402,8 @@ internal static extern unsafe int git_commit_create_from_ids(
402402
internal static extern unsafe int git_commit_create_buffer(
403403
GitBuf res,
404404
RepositoryHandle repo,
405-
git_signature* author,
406-
git_signature* committer,
405+
SignatureHandle author,
406+
SignatureHandle committer,
407407
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string encoding,
408408
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
409409
ObjectHandle tree,
@@ -1020,8 +1020,8 @@ internal static extern unsafe int git_note_create(
10201020
out GitOid noteOid,
10211021
RepositoryHandle repo,
10221022
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string notes_ref,
1023-
git_signature* author,
1024-
git_signature* committer,
1023+
SignatureHandle author,
1024+
SignatureHandle committer,
10251025
ref GitOid oid,
10261026
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string note,
10271027
int force);
@@ -1047,8 +1047,8 @@ internal static extern unsafe int git_note_read(
10471047
internal static extern unsafe int git_note_remove(
10481048
RepositoryHandle repo,
10491049
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string notes_ref,
1050-
git_signature* author,
1051-
git_signature* committer,
1050+
SignatureHandle author,
1051+
SignatureHandle committer,
10521052
ref GitOid oid);
10531053

10541054
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
@@ -1306,25 +1306,20 @@ internal static extern unsafe UIntPtr git_reflog_entrycount
13061306
(ReflogHandle reflog);
13071307

13081308
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1309-
internal static extern unsafe git_reflog_entry* git_reflog_entry_byindex(
1310-
ReflogHandle reflog,
1311-
UIntPtr idx);
1309+
internal static extern unsafe nint git_reflog_entry_byindex(ReflogHandle reflog, UIntPtr idx);
13121310

13131311
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1314-
internal static extern unsafe git_oid* git_reflog_entry_id_old(
1315-
git_reflog_entry* entry);
1312+
internal static extern unsafe git_oid* git_reflog_entry_id_old(nint entry);
13161313

13171314
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1318-
internal static extern unsafe git_oid* git_reflog_entry_id_new(
1319-
git_reflog_entry* entry);
1315+
internal static extern unsafe git_oid* git_reflog_entry_id_new(nint entry);
13201316

13211317
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1322-
internal static extern unsafe git_signature* git_reflog_entry_committer(
1323-
git_reflog_entry* entry);
1318+
internal static extern unsafe SignatureHandle git_reflog_entry_committer(nint entry);
13241319

13251320
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
13261321
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1327-
internal static extern unsafe string git_reflog_entry_message(git_reflog_entry* entry);
1322+
internal static extern unsafe string git_reflog_entry_message(nint entry);
13281323

13291324
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
13301325
internal static extern int git_refspec_transform(
@@ -1422,7 +1417,7 @@ internal static extern unsafe int git_remote_fetch(
14221417
internal static extern unsafe int git_remote_get_fetch_refspecs(out GitStrArray array, RemoteHandle remote);
14231418

14241419
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1425-
internal static extern unsafe git_refspec* git_remote_get_refspec(RemoteHandle remote, UIntPtr n);
1420+
internal static extern unsafe nint git_remote_get_refspec(RemoteHandle remote, UIntPtr n);
14261421

14271422
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
14281423
internal static extern unsafe int git_remote_get_push_refspecs(out GitStrArray array, RemoteHandle remote);
@@ -1717,30 +1712,30 @@ internal static extern unsafe int git_revparse_ext(
17171712
internal static extern unsafe int git_revwalk_simplify_first_parent(RevWalkerHandle walk);
17181713

17191714
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1720-
internal static extern unsafe void git_signature_free(git_signature* signature);
1715+
internal static extern unsafe void git_signature_free(SignatureHandle signature);
17211716

17221717
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
17231718
internal static extern unsafe int git_signature_new(
1724-
out git_signature* signature,
1719+
out SignatureHandle signature,
17251720
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
17261721
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email,
17271722
long time,
17281723
int offset);
17291724

17301725
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
17311726
internal static extern unsafe int git_signature_now(
1732-
out git_signature* signature,
1727+
out SignatureHandle signature,
17331728
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
17341729
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email);
17351730

17361731
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1737-
internal static extern unsafe int git_signature_dup(out git_signature* dest, git_signature* sig);
1732+
internal static extern unsafe int git_signature_dup(out SignatureHandle dest, SignatureHandle sig);
17381733

17391734
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
17401735
internal static extern unsafe int git_stash_save(
17411736
out GitOid id,
17421737
RepositoryHandle repo,
1743-
git_signature* stasher,
1738+
SignatureHandle stasher,
17441739
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
17451740
StashModifiers flags);
17461741

@@ -1897,7 +1892,7 @@ internal static extern unsafe int git_tag_annotation_create(
18971892
RepositoryHandle repo,
18981893
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
18991894
ObjectHandle target,
1900-
git_signature* signature,
1895+
SignatureHandle signature,
19011896
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message);
19021897

19031898
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
@@ -1906,7 +1901,7 @@ internal static extern unsafe int git_tag_create(
19061901
RepositoryHandle repo,
19071902
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
19081903
ObjectHandle target,
1909-
git_signature* signature,
1904+
SignatureHandle signature,
19101905
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
19111906
[MarshalAs(UnmanagedType.Bool)]
19121907
bool force);
@@ -1937,7 +1932,7 @@ internal static extern unsafe int git_tag_delete(
19371932
internal static extern unsafe string git_tag_name(ObjectHandle tag);
19381933

19391934
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1940-
internal static extern unsafe git_signature* git_tag_tagger(ObjectHandle tag);
1935+
internal static extern unsafe SignatureHandle git_tag_tagger(ObjectHandle tag);
19411936

19421937
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
19431938
internal static extern unsafe git_oid* git_tag_target_id(ObjectHandle tag);

LibGit2Sharp/Core/ObjectSafeWrapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allow
1313

1414
if (allowNullObjectId && id == null)
1515
{
16-
objectPtr = new ObjectHandle(null, false);
16+
objectPtr = new ObjectHandle(IntPtr.Zero, false);
1717
}
1818
else
1919
{

LibGit2Sharp/Core/Proxy.cs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1995,27 +1995,27 @@ public static unsafe int git_reflog_entrycount(ReflogHandle reflog)
19951995
return (int)NativeMethods.git_reflog_entrycount(reflog);
19961996
}
19971997

1998-
public static unsafe git_reflog_entry* git_reflog_entry_byindex(ReflogHandle reflog, int idx)
1998+
public static unsafe nint git_reflog_entry_byindex(ReflogHandle reflog, int idx)
19991999
{
20002000
return NativeMethods.git_reflog_entry_byindex(reflog, (UIntPtr)idx);
20012001
}
20022002

2003-
public static unsafe ObjectId git_reflog_entry_id_old(git_reflog_entry* entry)
2003+
public static unsafe ObjectId git_reflog_entry_id_old(nint entry)
20042004
{
20052005
return ObjectId.BuildFromPtr(NativeMethods.git_reflog_entry_id_old(entry));
20062006
}
20072007

2008-
public static unsafe ObjectId git_reflog_entry_id_new(git_reflog_entry* entry)
2008+
public static unsafe ObjectId git_reflog_entry_id_new(nint entry)
20092009
{
20102010
return ObjectId.BuildFromPtr(NativeMethods.git_reflog_entry_id_new(entry));
20112011
}
20122012

2013-
public static unsafe Signature git_reflog_entry_committer(git_reflog_entry* entry)
2013+
public static unsafe Signature git_reflog_entry_committer(nint entry)
20142014
{
20152015
return new Signature(NativeMethods.git_reflog_entry_committer(entry));
20162016
}
20172017

2018-
public static unsafe string git_reflog_entry_message(git_reflog_entry* entry)
2018+
public static unsafe string git_reflog_entry_message(nint entry)
20192019
{
20202020
return NativeMethods.git_reflog_entry_message(entry);
20212021
}
@@ -2142,7 +2142,7 @@ public static unsafe void git_remote_delete(RepositoryHandle repo, string name)
21422142
Ensure.ZeroResult(res);
21432143
}
21442144

2145-
public static unsafe git_refspec* git_remote_get_refspec(RemoteHandle remote, int n)
2145+
public static unsafe nint git_remote_get_refspec(RemoteHandle remote, int n)
21462146
{
21472147
return NativeMethods.git_remote_get_refspec(remote, (UIntPtr)n);
21482148
}
@@ -2742,28 +2742,23 @@ public static unsafe int git_revwalk_simplify_first_parent(RevWalkerHandle walke
27422742

27432743
public static unsafe SignatureHandle git_signature_new(string name, string email, DateTimeOffset when)
27442744
{
2745-
git_signature* ptr;
2746-
2747-
int res = NativeMethods.git_signature_new(out ptr, name, email, when.ToUnixTimeSeconds(),
2748-
(int)when.Offset.TotalMinutes);
2745+
int res = NativeMethods.git_signature_new(out var signature, name, email, when.ToUnixTimeSeconds(), (int)when.Offset.TotalMinutes);
27492746
Ensure.ZeroResult(res);
27502747

2751-
return new SignatureHandle(ptr, true);
2748+
return signature;
27522749
}
27532750

27542751
public static unsafe SignatureHandle git_signature_now(string name, string email)
27552752
{
2756-
git_signature* ptr;
2757-
int res = NativeMethods.git_signature_now(out ptr, name, email);
2753+
int res = NativeMethods.git_signature_now(out var signature, name, email);
27582754
Ensure.ZeroResult(res);
27592755

2760-
return new SignatureHandle(ptr, true);
2756+
return signature;
27612757
}
27622758

2763-
public static unsafe git_signature* git_signature_dup(git_signature* sig)
2759+
public static unsafe SignatureHandle git_signature_dup(SignatureHandle sig)
27642760
{
2765-
git_signature* handle;
2766-
int res = NativeMethods.git_signature_dup(out handle, sig);
2761+
int res = NativeMethods.git_signature_dup(out var handle, sig);
27672762
Ensure.ZeroResult(res);
27682763
return handle;
27692764
}
@@ -3098,14 +3093,15 @@ public static unsafe string git_tag_name(ObjectHandle tag)
30983093

30993094
public static unsafe Signature git_tag_tagger(ObjectHandle tag)
31003095
{
3101-
git_signature* taggerHandle = NativeMethods.git_tag_tagger(tag);
3096+
var taggerSignatureHandle = NativeMethods.git_tag_tagger(tag);
31023097

31033098
// Not all tags have a tagger signature - we need to handle
31043099
// this case.
31053100
Signature tagger = null;
3106-
if (taggerHandle != null)
3101+
3102+
if (!taggerSignatureHandle.IsInvalid)
31073103
{
3108-
tagger = new Signature(taggerHandle);
3104+
tagger = new Signature(taggerSignatureHandle);
31093105
}
31103106

31113107
return tagger;

LibGit2Sharp/Identity.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LibGit2Sharp.Core;
1+
using System;
2+
using LibGit2Sharp.Core;
23
using LibGit2Sharp.Core.Handles;
34

45
namespace LibGit2Sharp
@@ -52,7 +53,7 @@ internal SignatureHandle BuildNowSignatureHandle()
5253
internal static class IdentityHelpers
5354
{
5455
/// <summary>
55-
/// Build the handle for the Indentity with the current time, or return a handle
56+
/// Build the handle for the Identity with the current time, or return a handle
5657
/// to an empty signature.
5758
/// </summary>
5859
/// <param name="identity"></param>
@@ -61,7 +62,7 @@ public static unsafe SignatureHandle SafeBuildNowSignatureHandle(this Identity i
6162
{
6263
if (identity == null)
6364
{
64-
return new SignatureHandle(null, false);
65+
return new SignatureHandle(IntPtr.Zero, false);
6566
}
6667

6768
return identity.BuildNowSignatureHandle();

LibGit2Sharp/Rebase.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using LibGit2Sharp.Core;
33
using LibGit2Sharp.Core.Handles;
4-
using System.Globalization;
54

65
namespace LibGit2Sharp
76
{
@@ -65,7 +64,7 @@ internal Rebase(Repository repo)
6564
unsafe AnnotatedCommitHandle AnnotatedCommitHandleFromRefHandle(ReferenceHandle refHandle)
6665
{
6766
return (refHandle == null) ?
68-
new AnnotatedCommitHandle(null, false) :
67+
new AnnotatedCommitHandle(IntPtr.Zero, false) :
6968
Proxy.git_annotated_commit_from_ref(this.repository.Handle, refHandle);
7069
}
7170

LibGit2Sharp/RefSpec.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Diagnostics;
33
using System.Globalization;
44
using LibGit2Sharp.Core;
5-
using LibGit2Sharp.Core.Handles;
65

76
namespace LibGit2Sharp
87
{
@@ -18,10 +17,10 @@ public class RefSpec
1817
#pragma warning restore 0414
1918
readonly IntPtr handle;
2019

21-
internal unsafe RefSpec(Remote remote, git_refspec* handle)
20+
internal unsafe RefSpec(Remote remote, nint handle)
2221
{
2322
this.remote = remote;
24-
this.handle = new IntPtr(handle);
23+
this.handle = handle;
2524
}
2625

2726
/// <summary>
@@ -37,7 +36,7 @@ public virtual string Specification
3736
{
3837
get
3938
{
40-
return Proxy.git_refspec_string(this.handle);
39+
return Proxy.git_refspec_string(handle);
4140
}
4241
}
4342

@@ -48,7 +47,7 @@ public virtual RefSpecDirection Direction
4847
{
4948
get
5049
{
51-
return Proxy.git_refspec_direction(this.handle);
50+
return Proxy.git_refspec_direction(handle);
5251
}
5352
}
5453

@@ -59,7 +58,7 @@ public virtual string Source
5958
{
6059
get
6160
{
62-
return Proxy.git_refspec_src(this.handle);
61+
return Proxy.git_refspec_src(handle);
6362
}
6463
}
6564

@@ -70,7 +69,7 @@ public virtual string Destination
7069
{
7170
get
7271
{
73-
return Proxy.git_refspec_dst(this.handle);
72+
return Proxy.git_refspec_dst(handle);
7473
}
7574
}
7675

@@ -81,7 +80,7 @@ public virtual bool ForceUpdate
8180
{
8281
get
8382
{
84-
return Proxy.git_refspec_force(this.handle);
83+
return Proxy.git_refspec_force(handle);
8584
}
8685
}
8786

0 commit comments

Comments
 (0)