libgit2 / libgit2/libgit2sharp

Please consider adding AOT support for .Diff.Compare<T>()

未关闭
#2,082 18 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
C#
星标
3.5k
派生
925
PR 合并指标
30 天内没有已合并 PR

描述

When utilizing libgit2sharp in combination with the .NET 8 PublishAot feature, all repository creation, file staging and committing operations are successful, however, the git diff function throws a NullReferenceException.

Is there a way to get this working under AOT?

Steps To Reproduce:
  1. Create a .NET 8 console project
    dotnet new console -o aot-test
    cd aot-test
    
  2. Adjust aot-test.csproj to include libgit2sharp reference and activate PublishAot feature
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
    	<OutputType>Exe</OutputType>
    	<TargetFramework>net8.0</TargetFramework>
    	<RootNamespace>aot_test</RootNamespace>
    	<ImplicitUsings>enable</ImplicitUsings>
    	<Nullable>enable</Nullable>
    	<PublishAot>true</PublishAot>
      </PropertyGroup>
    
      <ItemGroup>
    	<PackageReference Include="libgit2sharp" Version="0.29.0" />
      </ItemGroup>
    
    </Project>
    
  3. Insert the following code into Progmram.cs:
using LibGit2Sharp;

var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(path);
Repository.Init(path, false);
var userName = "Tester";
var email = "tester@mail.net";
Func<Signature> getSignature = () => new Signature(userName, email, DateTimeOffset.Now);
using (var repo = new Repository(path))
{
    var fileName = "test.txt";
    var filePath = Path.Combine(path, fileName);
    File.WriteAllText(filePath, "Hello, World!");
    Commands.Stage(repo, fileName);
    var commit1 = repo.Commit("Initial commit", getSignature(), getSignature());
    File.AppendAllText(filePath, "\nAppended Line");
    Commands.Stage(repo, fileName);
    var commit2 = repo.Commit("Second commit", getSignature(), getSignature());
    Console.WriteLine($"Commits Count {repo.Commits.Count()}");
    var changes = repo.Diff.Compare<Patch>(commit1.Tree, commit2.Tree);
    Console.WriteLine($"Diff Changes Count = {changes.Count()}");
}
  1. Use dotnet run for testing, it will display:
Commits Count 2
Diff Changes Count = 1
  1. Use dotnet publish, .\bin\Release\net8.0\win-x64\publish\aot-test.exe to test the native AOT version, it throws an exception on repo.Diff.Compare<Patch>():
Commits Count 2
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at aot-test!<BaseAddress>+0x19af4c
   at aot-test!<BaseAddress>+0x199437
Current Behavior:

The native AOT functions for repository creation, file staging, and committing operations are functional, but the git diff function is not.

Anticipated Behavior:

Please consider adding AOT support for the git diff API.

Version of LibGit2Sharp (release number or SHA1)

0.29.0

Operating system(s) tested; .NET runtime tested
  • OS: Windows 11
  • .NET: 8.0.100

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 .NET 8 控制台项目及其 aot-test.csproj/Program.cs 设置开始,然后使用 dotnet publish 和 repo.Diff.Compare(commit1.Tree, commit2.Tree) 重现故障。原生 AOT 可执行文件完成 diff 调用并报告一个 diff 变更,而不是抛出 NullReferenceException,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
api
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。