Skip to content

Commit

Permalink
Merge pull request #35 from dogged/ethomson/libgit2_v18
Browse files Browse the repository at this point in the history
Support libgit2 v1.8.0 and macOS arm64
  • Loading branch information
ethomson committed Apr 21, 2024
2 parents a3581b0 + b847f39 commit 32f8779
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 39 deletions.
7 changes: 6 additions & 1 deletion Dogged.Native.Tests/Dogged.Native.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0;net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<PropertyGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == 'osx-arm64'">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Dogged.Native\Dogged.Native.csproj" />
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion Dogged.Native/Dogged.Native.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
<RepositoryUrl>https://github.com/ethomson/dogged.git</RepositoryUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == 'osx-arm64'">
<DefineConstants>MACOS_ARM64;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Include="..\Images\dogged-light.png" Pack="true" PackagePath="Images\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dogged.Native.Binaries" Version="[1.6.2]" />
<PackageReference Include="Dogged.Native.Binaries" Version="[1.8.0]" />
</ItemGroup>

<Import Project="..\Targets\GenerateNativeLibrary.targets" />
Expand Down
7 changes: 6 additions & 1 deletion Dogged.Native/config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ public enum git_config_level_t
/// </summary>
GIT_CONFIG_LEVEL_LOCAL = 5,

/// <summary>
/// Worktree specific configuration file; $GIT_DIR/config.worktree
/// </summary>
GIT_CONFIG_LEVEL_WORKTREE = 6,

/// <summary>
/// Application specific configuration file; freely defined by
/// applications.
/// </summary>
GIT_CONFIG_LEVEL_APP = 6,
GIT_CONFIG_LEVEL_APP = 7,

/// <summary>
/// Represents the highest level available config file (i.e. the
Expand Down
96 changes: 62 additions & 34 deletions Dogged.Native/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,47 +162,75 @@ public enum git_error_code
/// Patch application failed.
/// </summary>
GIT_EAPPLYFAIL = -35,

/// <summary>
/// The object is not owned by the current user
/// </summary>
GIT_EOWNER = -36,

/// <summary>
/// The operation timed out
/// </summary>
GIT_TIMEOUT = -37,

/// <summary>
/// There were no changes
/// </summary>
GIT_EUNCHANGED = -38,

/// <summary>
/// An option is not supported
/// </summary>
GIT_ENOTSUPPORTED = -39,

/// <summary>
/// The subject is read-only
/// </summary>
GIT_EREADONLY = -40
}

/// <summary>
/// Error classes store the area of the code where the error occurred.
/// </summary>
public enum git_error_t
{
GITERR_NONE = 0,
GITERR_NOMEMORY,
GITERR_OS,
GITERR_INVALID,
GITERR_REFERENCE,
GITERR_ZLIB,
GITERR_REPOSITORY,
GITERR_CONFIG,
GITERR_REGEX,
GITERR_ODB,
GITERR_INDEX,
GITERR_OBJECT,
GITERR_NET,
GITERR_TAG,
GITERR_TREE,
GITERR_INDEXER,
GITERR_SSL,
GITERR_SUBMODULE,
GITERR_THREAD,
GITERR_STASH,
GITERR_CHECKOUT,
GITERR_FETCHHEAD,
GITERR_MERGE,
GITERR_SSH,
GITERR_FILTER,
GITERR_REVERT,
GITERR_CALLBACK,
GITERR_CHERRYPICK,
GITERR_DESCRIBE,
GITERR_REBASE,
GITERR_FILESYSTEM,
GITERR_PATCH,
GITERR_WORKTREE,
GITERR_SHA1
GIT_ERROR_NONE = 0,
GIT_ERROR_NOMEMORY,
GIT_ERROR_OS,
GIT_ERROR_INVALID,
GIT_ERROR_REFERENCE,
GIT_ERROR_ZLIB,
GIT_ERROR_REPOSITORY,
GIT_ERROR_CONFIG,
GIT_ERROR_REGEX,
GIT_ERROR_ODB,
GIT_ERROR_INDEX,
GIT_ERROR_OBJECT,
GIT_ERROR_NET,
GIT_ERROR_TAG,
GIT_ERROR_TREE,
GIT_ERROR_INDEXER,
GIT_ERROR_SSL,
GIT_ERROR_SUBMODULE,
GIT_ERROR_THREAD,
GIT_ERROR_STASH,
GIT_ERROR_CHECKOUT,
GIT_ERROR_FETCHHEAD,
GIT_ERROR_MERGE,
GIT_ERROR_SSH,
GIT_ERROR_FILTER,
GIT_ERROR_REVERT,
GIT_ERROR_CALLBACK,
GIT_ERROR_CHERRYPICK,
GIT_ERROR_DESCRIBE,
GIT_ERROR_REBASE,
GIT_ERROR_FILESYSTEM,
GIT_ERROR_PATCH,
GIT_ERROR_WORKTREE,
GIT_ERROR_SHA,
GIT_ERROR_HTTP,
GIT_ERROR_INTERNAL,
GIT_ERROR_GRAFTS
}

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions Dogged.Native/libgit2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,35 @@ static libgit2()
/// <param name="option">The option value to get or set</param>
/// <param name="...">The options to set</param>
/// <returns>0 on success or an error code</returns>

// macOS arm64 requires padding before varargs, we'll set up the
// PInvoke methods with the extra padding as private, then use a
// public C# method to proxy to them. This gives us a consistent
// API between macOS arm64 and everything else.
// see https://github.com/dotnet/runtime/issues/48796
#if MACOS_ARM64
[DllImport(libgit2_dll, CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe int git_libgit2_opts(git_libgit2_opt_t option, IntPtr padding1, IntPtr padding2, IntPtr padding3, IntPtr padding4, IntPtr padding5, IntPtr padding6, IntPtr padding7, git_config_level_t level, git_buf buf);

public static int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, git_buf buf)
{
return git_libgit2_opts(option, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, level, buf);
}

[DllImport(libgit2_dll, CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe int git_libgit2_opts(git_libgit2_opt_t option, IntPtr padding1, IntPtr padding2, IntPtr padding3, IntPtr padding4, IntPtr padding5, IntPtr padding6, IntPtr padding7, git_config_level_t level, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = Utf8Marshaler.ToNative, MarshalTypeRef = typeof(Utf8Marshaler))] string path);

public static int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, string path)
{
return git_libgit2_opts(option, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, level, path);
}
#else
[DllImport(libgit2_dll, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, git_buf buf);

[DllImport(libgit2_dll, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = Utf8Marshaler.ToNative, MarshalTypeRef = typeof(Utf8Marshaler))] string path);
#endif

/// <summary>
/// Shutdown the global state.
Expand Down
6 changes: 5 additions & 1 deletion Dogged.Tests/Dogged.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<PropertyGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == 'osx-arm64'">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Dogged\Dogged.csproj" />
</ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion Dogged/ConfigurationLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public enum ConfigurationLevel
/// </summary>
Local = 5,

/// <summary>
/// Worktree specific configuration file; $GIT_DIR/config.worktree
/// </summary>
Worktree = 6,

/// <summary>
/// Application specific configuration file; freely defined by
/// applications.
/// </summary>
Application = 6,
Application = 7,

/// <summary>
/// Represents the highest level available config file (i.e. the
Expand Down

0 comments on commit 32f8779

Please sign in to comment.