Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make aot friendly #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">net472;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">net472;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp/AmbiguousSpecificationException.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using LibGit2Sharp.Core;
using System;
using System.Runtime.Serialization;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class AmbiguousSpecificationException : NativeException
{
/// <summary>
Expand Down Expand Up @@ -43,6 +44,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a serialized data.
/// </summary>
Expand All @@ -51,6 +53,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal override GitErrorCode ErrorCode
{
Expand Down
7 changes: 5 additions & 2 deletions LibGit2Sharp/BareRepositoryException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown when an operation which requires a
/// working directory is performed against a bare repository.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class BareRepositoryException : NativeException
{
/// <summary>
Expand Down Expand Up @@ -43,6 +44,7 @@ public BareRepositoryException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a serialized data.
/// </summary>
Expand All @@ -51,6 +53,7 @@ public BareRepositoryException(string message, Exception innerException)
protected BareRepositoryException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal BareRepositoryException(string message, GitErrorCategory category)
: base(message, category)
Expand Down
9 changes: 6 additions & 3 deletions LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
Expand All @@ -9,7 +8,9 @@ namespace LibGit2Sharp
/// because of a conflicting change staged in the index, or unstaged
/// in the working directory.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class CheckoutConflictException : NativeException
{
/// <summary>
Expand Down Expand Up @@ -44,6 +45,7 @@ public CheckoutConflictException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a serialized data.
/// </summary>
Expand All @@ -52,6 +54,7 @@ public CheckoutConflictException(string message, Exception innerException)
protected CheckoutConflictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal CheckoutConflictException(string message, GitErrorCategory category)
: base(message, category)
Expand Down
5 changes: 3 additions & 2 deletions LibGit2Sharp/Core/GitObjectLazyGroup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using LibGit2Sharp.Core.Handles;
using System;
using System.Diagnostics.CodeAnalysis;

namespace LibGit2Sharp.Core
{
Expand All @@ -21,7 +22,7 @@ protected override void EvaluateInternal(Action<ObjectHandle> evaluator)
}
}

public static ILazy<TResult> Singleton<TResult>(Repository repo, ObjectId id, Func<ObjectHandle, TResult> resultSelector, bool throwIfMissing = false)
public static ILazy<TResult> Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Repository repo, ObjectId id, Func<ObjectHandle, TResult> resultSelector, bool throwIfMissing = false)
{
return Singleton(() =>
{
Expand Down
9 changes: 5 additions & 4 deletions LibGit2Sharp/Core/LazyGroup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace LibGit2Sharp.Core
{
internal abstract class LazyGroup<T>
internal abstract class LazyGroup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T>
{
private readonly IList<IEvaluator<T>> evaluators = new List<IEvaluator<T>>();
private readonly object @lock = new object();
Expand Down Expand Up @@ -44,7 +45,7 @@ public void Evaluate()

protected abstract void EvaluateInternal(Action<T> evaluator);

protected static ILazy<TResult> Singleton<TResult>(Func<TResult> resultSelector)
protected static ILazy<TResult> Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Func<TResult> resultSelector)
{
return new LazyWrapper<TResult>(resultSelector);
}
Expand All @@ -54,7 +55,7 @@ private interface IEvaluator<TInput>
void Evaluate(TInput input);
}

private class Dependent<TInput, TOutput> : ILazy<TOutput>, IEvaluator<TInput>
private class Dependent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TInput, TOutput> : ILazy<TOutput>, IEvaluator<TInput>
{
private readonly Func<TInput, TOutput> valueFactory;
private readonly LazyGroup<TInput> lazyGroup;
Expand Down Expand Up @@ -90,7 +91,7 @@ void IEvaluator<TInput>.Evaluate(TInput input)
}
}

protected class LazyWrapper<TType> : Lazy<TType>, ILazy<TType>
protected class LazyWrapper<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TType> : Lazy<TType>, ILazy<TType>
{
public LazyWrapper(Func<TType> evaluator)
: base(evaluator)
Expand Down
11 changes: 9 additions & 2 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using LibGit2Sharp.Core.Handles;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using LibGit2Sharp.Core.Handles;

// Restrict the set of directories where the native library is loaded from to safe directories.
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.ApplicationDirectory | DllImportSearchPath.SafeDirectories)]
Expand Down Expand Up @@ -76,6 +77,7 @@ private static bool TryUseNativeLibrary()
return true;
}

[UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "The AOT case is handled at runtime")]
private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
IntPtr handle = IntPtr.Zero;
Expand All @@ -102,7 +104,12 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
{
// The libraries are located at 'runtimes/<rid>/native/lib{libraryName}.so'
// The <rid> ends with the processor architecture. e.g. fedora-x64.
string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
var directoryName = typeof(NativeMethods).Assembly.Location;
if (String.IsNullOrEmpty(directoryName)) // If AOT compiled, this will be true
{
directoryName = System.AppContext.BaseDirectory;
}
string assemblyDirectory = Path.GetDirectoryName(directoryName);
string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes");

Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp/EmptyCommitException.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Runtime.Serialization;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown when a commit would create an "empty"
/// commit that is treesame to its parent without an explicit override.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class EmptyCommitException : LibGit2SharpException
{
/// <summary>
Expand Down Expand Up @@ -42,6 +43,7 @@ public EmptyCommitException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a serialized data.
/// </summary>
Expand All @@ -50,5 +52,6 @@ public EmptyCommitException(string message, Exception innerException)
protected EmptyCommitException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif
}
}
9 changes: 6 additions & 3 deletions LibGit2Sharp/EntryExistsException.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown attempting to create a resource that already exists.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class EntryExistsException : LibGit2SharpException
{
/// <summary>
Expand Down Expand Up @@ -42,6 +43,7 @@ public EntryExistsException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a serialized data.
/// </summary>
Expand All @@ -50,6 +52,7 @@ public EntryExistsException(string message, Exception innerException)
protected EntryExistsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal EntryExistsException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
Expand Down
7 changes: 5 additions & 2 deletions LibGit2Sharp/InvalidSpecificationException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
Expand All @@ -10,7 +9,9 @@ namespace LibGit2Sharp
/// if the spec refers to an object of an incorrect type (e.g. asking to
/// create a branch from a blob, or peeling a blob to a commit).
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class InvalidSpecificationException : NativeException
{
/// <summary>
Expand Down Expand Up @@ -45,6 +46,7 @@ public InvalidSpecificationException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a serialized data.
/// </summary>
Expand All @@ -53,6 +55,7 @@ public InvalidSpecificationException(string message, Exception innerException)
protected InvalidSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal InvalidSpecificationException(string message, GitErrorCategory category)
: base(message, category)
Expand Down
7 changes: 6 additions & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET</Description>
Expand All @@ -23,6 +23,11 @@
<MinVerBuildMetadata Condition="'$(libgit2_hash)' != ''">libgit2-$(libgit2_hash.Substring(0,7))</MinVerBuildMetadata>
</PropertyGroup>

<!-- Apply this property group if targeting .NET 8 -->
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
<None Include="..\square-logo.png" Pack="true" PackagePath="" Visible="false" />
<None Include="..\README.md" Pack="true" PackagePath="App_Readme/" Visible="false" />
Expand Down
6 changes: 4 additions & 2 deletions LibGit2Sharp/LibGit2SharpException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Globalization;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown when an error occurs during application execution.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class LibGit2SharpException : Exception
{
/// <summary>
Expand Down Expand Up @@ -44,6 +44,7 @@ public LibGit2SharpException(string format, params object[] args)
{
}

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a serialized data.
/// </summary>
Expand All @@ -52,5 +53,6 @@ public LibGit2SharpException(string format, params object[] args)
protected LibGit2SharpException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif
}
}
9 changes: 6 additions & 3 deletions LibGit2Sharp/LockedFileException.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
/// <summary>
/// The exception that is thrown attempting to open a locked file.
/// </summary>
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class LockedFileException : NativeException
{
/// <summary>
Expand Down Expand Up @@ -42,6 +43,7 @@ public LockedFileException(string message, Exception innerException)
: base(message, innerException)
{ }

#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a serialized data.
/// </summary>
Expand All @@ -50,6 +52,7 @@ public LockedFileException(string message, Exception innerException)
protected LockedFileException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif

internal LockedFileException(string message, GitErrorCategory category)
: base(message, category)
Expand Down
Loading