Skip to content

Commit 04b9535

Browse files
committed
simplify builds and deps - replace LibGit2Sharp with GitCore
In the past, we had used LibGit2Sharp to clone Git repositories and read their commits and files. That often worked, but the native dependencies of such a solution have caused [many](ba6abfc) [problems](1c7d3e4). This commit resolves these problems by switching to an implementation of Git without such complicated dependencies.
1 parent 3edd9eb commit 04b9535

12 files changed

Lines changed: 2913 additions & 301 deletions
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Linq;
5+
6+
namespace GitCore.Common;
7+
8+
/// <summary>
9+
/// Extension methods for <see cref="IEnumerable{T}"/>.
10+
/// </summary>
11+
public static class EnumerableExtensions
12+
{
13+
/// <summary>
14+
/// Creates an <see cref="IEqualityComparer{T}"/> for sequences of <see cref="IComparable"/> elements.
15+
/// </summary>
16+
/// <typeparam name="T">The type of the enumerable, which must implement <see cref="IEnumerable{IComparable}"/>.</typeparam>
17+
/// <returns>An <see cref="IEqualityComparer{T}"/> that compares sequences element by element.</returns>
18+
public static IEqualityComparer<T> EqualityComparer<T>() where T : IEnumerable<IComparable> =>
19+
new IEnumerableEqualityComparer<T>();
20+
21+
/// <summary>
22+
/// Creates an <see cref="IComparer{T}"/> for sequences of <see cref="IComparable"/> elements.
23+
/// </summary>
24+
/// <typeparam name="T">The type of the enumerable, which must implement <see cref="IEnumerable{IComparable}"/>.</typeparam>
25+
/// <returns>An <see cref="IComparer{T}"/> that compares sequences element by element.</returns>
26+
public static IComparer<T> Comparer<T>() where T : IEnumerable<IComparable> => new IEnumerableComparer<T>();
27+
28+
private class IEnumerableEqualityComparer<T> : IEqualityComparer<T> where T : IEnumerable<IComparable>
29+
{
30+
public bool Equals(T? x, T? y)
31+
{
32+
if (ReferenceEquals(x, y))
33+
return true;
34+
35+
if (x is null || y is null)
36+
{
37+
return false;
38+
}
39+
40+
return x.SequenceEqual(y);
41+
}
42+
43+
public int GetHashCode(T obj) => 0;
44+
}
45+
46+
private class IEnumerableComparer<T> : IComparer<T> where T : IEnumerable<IComparable>
47+
{
48+
public static int Compare([AllowNull] IEnumerable<IComparable> x, [AllowNull] IEnumerable<IComparable> y)
49+
{
50+
if (ReferenceEquals(x, y))
51+
return 0;
52+
53+
if (x is null)
54+
return -1;
55+
56+
if (y is null)
57+
return 1;
58+
59+
if (x.Equals(y))
60+
return 0;
61+
62+
var xEnumerator = x.GetEnumerator();
63+
var yEnumerator = y.GetEnumerator();
64+
65+
while (true)
66+
{
67+
var xHasCurrent = xEnumerator.MoveNext();
68+
var yHasCurrent = yEnumerator.MoveNext();
69+
70+
if (!xHasCurrent && !yHasCurrent)
71+
return 0;
72+
73+
if (!xHasCurrent)
74+
return -1;
75+
76+
if (!yHasCurrent)
77+
return 1;
78+
79+
var currentComparison = xEnumerator.Current.CompareTo(yEnumerator.Current);
80+
81+
if (currentComparison is not 0)
82+
return currentComparison;
83+
}
84+
}
85+
86+
public int Compare(T? x, T? y)
87+
{
88+
return IEnumerableComparer<T>.Compare(x, y);
89+
}
90+
}
91+
}

implement/GitCore/GitCore.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="SharpZipLib" Version="1.4.2" />
10+
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)