Dev changes (#3)

* Fixed dependency

* Updates to NeoDictionary

* Changes to NeoDictionary

* Started working on a Git implementation to integrate into Game Engines in the future

* Added commit functionality to the git library

* New changes

* Added select for NeoDictionary.cs

* Fixed issue with previous new method

* Added a Benchmarking Tool to be used mostly in game engines

* Added IndexOf to NeoDictionary.cs

* Added new method for BenchmarkUtility.cs

* added an instacedobject class

* Added a new shuffle method for lists

* fixed return type

* Added new Changelog generator
This commit was merged in pull request #3.
This commit is contained in:
2025-02-18 21:09:25 +00:00
committed by GitHub
parent 8f249d2567
commit 7b6115da21
22 changed files with 759 additions and 3 deletions
+130
View File
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GameDevLibrary.Extensions;
using LibGit2Sharp;
using OmegaLeo.HelperLib.Git.Models;
namespace OmegaLeo.HelperLib.Git
{
public class GitClient
{
private Repository _repo;
public GitClient(string path)
{
if (path.IsNullOrEmpty())
{
path = AppDomain.CurrentDomain.BaseDirectory;
}
_repo = new Repository(path);
}
public void CheckoutBranch(string branchName)
{
var branch = _repo.Branches[branchName];
if (branch == null)
{
branch = _repo.CreateBranch(branchName);
}
Commands.Checkout(_repo, branch);
}
public bool HasChanges() => _repo.Diff.Compare<TreeChanges>().Count > 0;
public ChangeFolder GetChanges()
{
var folder = new ChangeFolder();
if (HasChanges())
{
var changes = _repo.Diff.Compare<TreeChanges>();
var allChanges = new List<TreeEntryChanges>();
allChanges.AddRange(changes.Added);
allChanges.AddRange(changes.Modified);
allChanges.AddRange(changes.Deleted);
var uniqueFolderPaths = allChanges.Select(x => Path.GetDirectoryName(x.Path)).Distinct();
foreach (var path in uniqueFolderPaths)
{
if (path.IsNullOrEmpty()) continue;
if (path.Contains(Path.DirectorySeparatorChar))
{
var paths = path.Split(Path.DirectorySeparatorChar);
for (var i = 0; i < paths.Length; i++)
{
var p = paths[i];
if (folder.FolderName.Equals(p))
{
if (folder.ChangesInFolder.Any()) continue;
folder.ChangesInFolder =
allChanges.Where(x => Path.GetDirectoryName(x.Path)!.Equals(p, StringComparison.OrdinalIgnoreCase));
}
else
{
var pathList = paths[0..(i+1)].ToList();
var subFolder = folder.RecursiveGet(pathList);
var fullPath = string.Join(Path.DirectorySeparatorChar, pathList);
if (!subFolder.ChangesInFolder.Any())
{
subFolder.ChangesInFolder = allChanges.Where(x =>
Path.GetDirectoryName(x.Path)!.Equals(fullPath, StringComparison.OrdinalIgnoreCase));
}
}
}
}
else
{
folder.FolderName = path;
folder.ChangesInFolder =
allChanges.Where(x => Path.GetDirectoryName(x.Path)!.Equals(path, StringComparison.OrdinalIgnoreCase));
}
}
}
return folder;
}
public void Commit(string message, Signature author)
{
if (HasChanges())
{
var changes = _repo.Diff.Compare<TreeChanges>();
var allChanges = new List<TreeEntryChanges>();
allChanges.AddRange(changes.Added);
allChanges.AddRange(changes.Modified);
allChanges.AddRange(changes.Deleted);
var filePaths = allChanges.Select(x => x.Path).Where(x => x.IsNotNullOrEmpty());
Commands.Stage(_repo, filePaths);
}
_repo.Commit(message, author, author);
}
public void Push()
{
try {
var remote = _repo.Network.Remotes["origin"];
var options = new PushOptions();
var pushRefSpec = @"refs/heads/master";
_repo.Network.Push(remote, new string[] {pushRefSpec}, options);
}
catch (Exception e) {
Console.WriteLine("Exception:RepoActions:PushChanges " + e.Message);
}
}
}
}
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;
namespace OmegaLeo.HelperLib.Git.Models
{
public class ChangeFolder
{
public string FolderName { get; set; }
public List<ChangeFolder> SubFolders { get; set; }
public IEnumerable<TreeEntryChanges> ChangesInFolder { get; set; }
public ChangeFolder()
{
FolderName = "";
SubFolders = new List<ChangeFolder>();
ChangesInFolder = new List<TreeEntryChanges>();
}
public ChangeFolder RecursiveGet(List<string> paths)
{
if (!paths.Any()) return null;
var tempPaths = paths;
var pathToCheck = tempPaths.FirstOrDefault();
ChangeFolder folder = new ChangeFolder();
if (FolderName.Equals(pathToCheck, StringComparison.OrdinalIgnoreCase))
{
folder = this;
}
else if (SubFolders.Any(x => x.FolderName.Equals(pathToCheck)))
{
folder = SubFolders.FirstOrDefault(x => x.FolderName.Equals(pathToCheck))!;
}
else
{
folder.FolderName = pathToCheck;
SubFolders.Add(folder);
}
tempPaths.RemoveAt(0);
if (tempPaths.Any())
{
return folder.RecursiveGet(tempPaths);
}
else
{
return folder;
}
}
}
}
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>GameDevLibrary.Git</RootNamespace>
<Version>0.0.2</Version>
<Title>Omega Leo's Helper Library - LibGit2Sharp Implementation</Title>
<Authors>Nuno "Omega Leo" Diogo</Authors>
<PackageProjectUrl>https://github.com/omegaleo/HelperLib</PackageProjectUrl>
<RepositoryUrl>https://github.com/omegaleo/HelperLib</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.30.0"/>
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj" />
</ItemGroup>
</Project>