From 7cda7211f1035a63bf444c57051a308cebbe8d48 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 7 Apr 2025 21:20:59 +0800 Subject: [PATCH] refactor: statistics dialog - use `%aN+%aE` instead of `%aN` to get commit author - show user avatar in statistics dialog Signed-off-by: leo --- src/Commands/Statistics.cs | 2 +- src/Models/Statistics.cs | 16 +++++++++------- src/Views/Statistics.axaml | 16 ++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Commands/Statistics.cs b/src/Commands/Statistics.cs index 1439cedd..41b3889e 100644 --- a/src/Commands/Statistics.cs +++ b/src/Commands/Statistics.cs @@ -8,7 +8,7 @@ namespace SourceGit.Commands { WorkingDirectory = repo; Context = repo; - Args = $"log --date-order --branches --remotes -{max} --format=%ct$%aN"; + Args = $"log --date-order --branches --remotes -{max} --format=%ct$%aN±%aE"; } public Models.Statistics Result() diff --git a/src/Models/Statistics.cs b/src/Models/Statistics.cs index 969d3945..87a6eabd 100644 --- a/src/Models/Statistics.cs +++ b/src/Models/Statistics.cs @@ -18,9 +18,9 @@ namespace SourceGit.Models ThisWeek, } - public class StaticsticsAuthor(string name, int count) + public class StaticsticsAuthor(User user, int count) { - public string Name { get; set; } = name; + public User User { get; set; } = user; public int Count { get; set; } = count; } @@ -73,7 +73,7 @@ namespace SourceGit.Models } } - public void AddCommit(DateTime time, string author) + public void AddCommit(DateTime time, User author) { Total++; @@ -126,7 +126,7 @@ namespace SourceGit.Models } private StaticsticsMode _mode = StaticsticsMode.All; - private Dictionary _mapUsers = new Dictionary(); + private Dictionary _mapUsers = new Dictionary(); private Dictionary _mapSamples = new Dictionary(); } @@ -150,14 +150,16 @@ namespace SourceGit.Models public void AddCommit(string author, double timestamp) { + var user = User.FindOrAdd(author); + var time = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); if (time >= _thisWeekStart) - Week.AddCommit(time, author); + Week.AddCommit(time, user); if (time >= _thisMonthStart) - Month.AddCommit(time, author); + Month.AddCommit(time, user); - All.AddCommit(time, author); + All.AddCommit(time, user); } public void Complete() diff --git a/src/Views/Statistics.axaml b/src/Views/Statistics.axaml index 0c002407..3bbdafbe 100644 --- a/src/Views/Statistics.axaml +++ b/src/Views/Statistics.axaml @@ -136,7 +136,7 @@ - + - - - + + + + - + @@ -177,7 +181,7 @@ - +