feat: add git commit count to assembly info/show in dev bar

This commit is contained in:
goat 2023-03-19 17:08:42 +01:00
parent d7c6172817
commit c8a7c69ee0
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 39 additions and 3 deletions

View file

@ -125,6 +125,17 @@
<TempVerFile>$(OutputPath)TEMP_gitver.txt</TempVerFile>
</PropertyGroup>
<Target Name="GetGitCommitCount" BeforeTargets="WriteGitHash" Condition="'$(CommitCount)'==''">
<Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; rev-list --count HEAD" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="DalamudGitCommitCount" />
</Exec>
<!-- Set the BuildHash property to contain the GitVersion, if it wasn't already set.-->
<PropertyGroup>
<CommitCount>$([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitCommitCount), @"\t|\n|\r", ""))</CommitCount>
</PropertyGroup>
</Target>
<Target Name="GetGitHash" BeforeTargets="WriteGitHash" Condition="'$(BuildHash)'=='' And '$(Configuration)'=='Release'">
<!-- write the hash to the temp file.-->
<Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; describe --long --always --dirty" ConsoleToMSBuild="true">
@ -171,6 +182,10 @@
<_Parameter1>GitHash</_Parameter1>
<_Parameter2>$(BuildHash)</_Parameter2>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyMetadata">
<_Parameter1>GitCommitCount</_Parameter1>
<_Parameter2>$(CommitCount)</_Parameter2>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyMetadata">
<_Parameter1>GitHashClientStructs</_Parameter1>
<_Parameter2>$(BuildHashClientStructs)</_Parameter2>

View file

@ -706,7 +706,7 @@ internal class DalamudInterface : IDisposable, IServiceType
{
this.OpenProfiler();
}
if (ImGui.MenuItem("Open Hitch Settings"))
{
this.OpenHitchSettings();
@ -768,7 +768,7 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.MenuItem(Util.AssemblyVersion, false);
ImGui.MenuItem(startInfo.GameVersion?.ToString() ?? "Unknown version", false);
ImGui.MenuItem($"D: {Util.GetGitHash()} CS: {Util.GetGitHashClientStructs()} [{FFXIVClientStructs.Interop.Resolver.Version}]", false);
ImGui.MenuItem($"D: {Util.GetGitHash()}[{Util.GetGitCommitCount()}] CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.Interop.Resolver.Version}]", false);
ImGui.MenuItem($"CLR: {Environment.Version}", false);
ImGui.EndMenu();
@ -944,7 +944,7 @@ internal class DalamudInterface : IDisposable, IServiceType
{
ImGui.PushFont(InterfaceManager.MonoFont);
ImGui.BeginMenu(Util.GetGitHash(), false);
ImGui.BeginMenu($"{Util.GetGitHash()}({Util.GetGitCommitCount()})", false);
ImGui.BeginMenu(this.FrameCount.ToString("000000"), false);
ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false);
ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false);

View file

@ -28,6 +28,7 @@ namespace Dalamud.Utility;
public static class Util
{
private static string? gitHashInternal;
private static int? gitCommitCountInternal;
private static string? gitHashClientStructsInternal;
private static ulong moduleStartAddr;
@ -114,6 +115,26 @@ public static class Util
return gitHashInternal;
}
/// <summary>
/// Gets the amount of commits in the current branch, or null if undetermined.
/// </summary>
/// <returns>The amount of commits in the current branch.</returns>
public static int? GetGitCommitCount()
{
if (gitCommitCountInternal != null)
return gitCommitCountInternal.Value;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
var value = attrs.First(a => a.Key == "GitCommitCount").Value;
if (value == null)
return null;
gitCommitCountInternal = int.Parse(value);
return gitCommitCountInternal.Value;
}
/// <summary>
/// Gets the git hash value from the assembly
/// or null if it cannot be found.