Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Nov 28, 2024
1 parent 11aae8b commit 42ac5d2
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 96 deletions.
59 changes: 27 additions & 32 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ internal static extern unsafe int git_rebase_next(
internal static extern unsafe int git_rebase_commit(
ref GitOid id,
RebaseHandle rebase,
git_signature* author,
git_signature* committer,
SignatureHandle author,
SignatureHandle committer,
IntPtr message_encoding,
IntPtr message);

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

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

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

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

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_commit_create_from_ids(
out GitOid id,
RepositoryHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string updateRef,
git_signature* author,
git_signature* committer,
SignatureHandle author,
SignatureHandle committer,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string encoding,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
ref GitOid tree,
Expand All @@ -402,8 +402,8 @@ internal static extern unsafe int git_commit_create_from_ids(
internal static extern unsafe int git_commit_create_buffer(
GitBuf res,
RepositoryHandle repo,
git_signature* author,
git_signature* committer,
SignatureHandle author,
SignatureHandle committer,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string encoding,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
ObjectHandle tree,
Expand Down Expand Up @@ -1020,8 +1020,8 @@ internal static extern unsafe int git_note_create(
out GitOid noteOid,
RepositoryHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string notes_ref,
git_signature* author,
git_signature* committer,
SignatureHandle author,
SignatureHandle committer,
ref GitOid oid,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string note,
int force);
Expand All @@ -1047,8 +1047,8 @@ internal static extern unsafe int git_note_read(
internal static extern unsafe int git_note_remove(
RepositoryHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string notes_ref,
git_signature* author,
git_signature* committer,
SignatureHandle author,
SignatureHandle committer,
ref GitOid oid);

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

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_reflog_entry* git_reflog_entry_byindex(
ReflogHandle reflog,
UIntPtr idx);
internal static extern unsafe nint git_reflog_entry_byindex(ReflogHandle reflog, UIntPtr idx);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_oid* git_reflog_entry_id_old(
git_reflog_entry* entry);
internal static extern unsafe git_oid* git_reflog_entry_id_old(nint entry);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_oid* git_reflog_entry_id_new(
git_reflog_entry* entry);
internal static extern unsafe git_oid* git_reflog_entry_id_new(nint entry);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_signature* git_reflog_entry_committer(
git_reflog_entry* entry);
internal static extern unsafe SignatureHandle git_reflog_entry_committer(nint entry);

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

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

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

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

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void git_signature_free(git_signature* signature);
internal static extern unsafe void git_signature_free(SignatureHandle signature);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_signature_new(
out git_signature* signature,
out SignatureHandle signature,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email,
long time,
int offset);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_signature_now(
out git_signature* signature,
out SignatureHandle signature,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email);

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

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_stash_save(
out GitOid id,
RepositoryHandle repo,
git_signature* stasher,
SignatureHandle stasher,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
StashModifiers flags);

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

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -1906,7 +1901,7 @@ internal static extern unsafe int git_tag_create(
RepositoryHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
ObjectHandle target,
git_signature* signature,
SignatureHandle signature,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
[MarshalAs(UnmanagedType.Bool)]
bool force);
Expand Down Expand Up @@ -1937,7 +1932,7 @@ internal static extern unsafe int git_tag_delete(
internal static extern unsafe string git_tag_name(ObjectHandle tag);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_signature* git_tag_tagger(ObjectHandle tag);
internal static extern unsafe SignatureHandle git_tag_tagger(ObjectHandle tag);

[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_oid* git_tag_target_id(ObjectHandle tag);
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/ObjectSafeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allow

if (allowNullObjectId && id == null)
{
objectPtr = new ObjectHandle(null, false);
objectPtr = new ObjectHandle(IntPtr.Zero, false);
}
else
{
Expand Down
36 changes: 16 additions & 20 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1995,27 +1995,27 @@ public static unsafe int git_reflog_entrycount(ReflogHandle reflog)
return (int)NativeMethods.git_reflog_entrycount(reflog);
}

public static unsafe git_reflog_entry* git_reflog_entry_byindex(ReflogHandle reflog, int idx)
public static unsafe nint git_reflog_entry_byindex(ReflogHandle reflog, int idx)
{
return NativeMethods.git_reflog_entry_byindex(reflog, (UIntPtr)idx);
}

public static unsafe ObjectId git_reflog_entry_id_old(git_reflog_entry* entry)
public static unsafe ObjectId git_reflog_entry_id_old(nint entry)
{
return ObjectId.BuildFromPtr(NativeMethods.git_reflog_entry_id_old(entry));
}

public static unsafe ObjectId git_reflog_entry_id_new(git_reflog_entry* entry)
public static unsafe ObjectId git_reflog_entry_id_new(nint entry)
{
return ObjectId.BuildFromPtr(NativeMethods.git_reflog_entry_id_new(entry));
}

public static unsafe Signature git_reflog_entry_committer(git_reflog_entry* entry)
public static unsafe Signature git_reflog_entry_committer(nint entry)
{
return new Signature(NativeMethods.git_reflog_entry_committer(entry));
}

public static unsafe string git_reflog_entry_message(git_reflog_entry* entry)
public static unsafe string git_reflog_entry_message(nint entry)
{
return NativeMethods.git_reflog_entry_message(entry);
}
Expand Down Expand Up @@ -2142,7 +2142,7 @@ public static unsafe void git_remote_delete(RepositoryHandle repo, string name)
Ensure.ZeroResult(res);
}

public static unsafe git_refspec* git_remote_get_refspec(RemoteHandle remote, int n)
public static unsafe nint git_remote_get_refspec(RemoteHandle remote, int n)
{
return NativeMethods.git_remote_get_refspec(remote, (UIntPtr)n);
}
Expand Down Expand Up @@ -2742,28 +2742,23 @@ public static unsafe int git_revwalk_simplify_first_parent(RevWalkerHandle walke

public static unsafe SignatureHandle git_signature_new(string name, string email, DateTimeOffset when)
{
git_signature* ptr;

int res = NativeMethods.git_signature_new(out ptr, name, email, when.ToUnixTimeSeconds(),
(int)when.Offset.TotalMinutes);
int res = NativeMethods.git_signature_new(out var signature, name, email, when.ToUnixTimeSeconds(), (int)when.Offset.TotalMinutes);
Ensure.ZeroResult(res);

return new SignatureHandle(ptr, true);
return signature;
}

public static unsafe SignatureHandle git_signature_now(string name, string email)
{
git_signature* ptr;
int res = NativeMethods.git_signature_now(out ptr, name, email);
int res = NativeMethods.git_signature_now(out var signature, name, email);
Ensure.ZeroResult(res);

return new SignatureHandle(ptr, true);
return signature;
}

public static unsafe git_signature* git_signature_dup(git_signature* sig)
public static unsafe SignatureHandle git_signature_dup(SignatureHandle sig)
{
git_signature* handle;
int res = NativeMethods.git_signature_dup(out handle, sig);
int res = NativeMethods.git_signature_dup(out var handle, sig);
Ensure.ZeroResult(res);
return handle;
}
Expand Down Expand Up @@ -3098,14 +3093,15 @@ public static unsafe string git_tag_name(ObjectHandle tag)

public static unsafe Signature git_tag_tagger(ObjectHandle tag)
{
git_signature* taggerHandle = NativeMethods.git_tag_tagger(tag);
var taggerSignatureHandle = NativeMethods.git_tag_tagger(tag);

// Not all tags have a tagger signature - we need to handle
// this case.
Signature tagger = null;
if (taggerHandle != null)

if (!taggerSignatureHandle.IsInvalid)
{
tagger = new Signature(taggerHandle);
tagger = new Signature(taggerSignatureHandle);
}

return tagger;
Expand Down
7 changes: 4 additions & 3 deletions LibGit2Sharp/Identity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibGit2Sharp.Core;
using System;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;

namespace LibGit2Sharp
Expand Down Expand Up @@ -52,7 +53,7 @@ internal SignatureHandle BuildNowSignatureHandle()
internal static class IdentityHelpers
{
/// <summary>
/// Build the handle for the Indentity with the current time, or return a handle
/// Build the handle for the Identity with the current time, or return a handle
/// to an empty signature.
/// </summary>
/// <param name="identity"></param>
Expand All @@ -61,7 +62,7 @@ public static unsafe SignatureHandle SafeBuildNowSignatureHandle(this Identity i
{
if (identity == null)
{
return new SignatureHandle(null, false);
return new SignatureHandle(IntPtr.Zero, false);
}

return identity.BuildNowSignatureHandle();
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Rebase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
using System.Globalization;

namespace LibGit2Sharp
{
Expand Down Expand Up @@ -65,7 +64,7 @@ internal Rebase(Repository repo)
unsafe AnnotatedCommitHandle AnnotatedCommitHandleFromRefHandle(ReferenceHandle refHandle)
{
return (refHandle == null) ?
new AnnotatedCommitHandle(null, false) :
new AnnotatedCommitHandle(IntPtr.Zero, false) :
Proxy.git_annotated_commit_from_ref(this.repository.Handle, refHandle);
}

Expand Down
15 changes: 7 additions & 8 deletions LibGit2Sharp/RefSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;

namespace LibGit2Sharp
{
Expand All @@ -18,10 +17,10 @@ public class RefSpec
#pragma warning restore 0414
readonly IntPtr handle;

internal unsafe RefSpec(Remote remote, git_refspec* handle)
internal unsafe RefSpec(Remote remote, nint handle)
{
this.remote = remote;
this.handle = new IntPtr(handle);
this.handle = handle;
}

/// <summary>
Expand All @@ -37,7 +36,7 @@ public virtual string Specification
{
get
{
return Proxy.git_refspec_string(this.handle);
return Proxy.git_refspec_string(handle);
}
}

Expand All @@ -48,7 +47,7 @@ public virtual RefSpecDirection Direction
{
get
{
return Proxy.git_refspec_direction(this.handle);
return Proxy.git_refspec_direction(handle);
}
}

Expand All @@ -59,7 +58,7 @@ public virtual string Source
{
get
{
return Proxy.git_refspec_src(this.handle);
return Proxy.git_refspec_src(handle);
}
}

Expand All @@ -70,7 +69,7 @@ public virtual string Destination
{
get
{
return Proxy.git_refspec_dst(this.handle);
return Proxy.git_refspec_dst(handle);
}
}

Expand All @@ -81,7 +80,7 @@ public virtual bool ForceUpdate
{
get
{
return Proxy.git_refspec_force(this.handle);
return Proxy.git_refspec_force(handle);
}
}

Expand Down
Loading

0 comments on commit 42ac5d2

Please sign in to comment.