From 156bb318313bff403e4ac9343a7d540771155fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Borr=C3=A0s=20Civil?= <70479573+BernatBC@users.noreply.github.com> Date: Sun, 12 Jan 2025 19:41:14 +0100 Subject: [PATCH] Make command for retreiving line count work --- src/Commands/QueryCommitChangedLines.cs | 43 +++++++++++++++++++++++++ src/ViewModels/CommitDetail.cs | 7 ++++ 2 files changed, 50 insertions(+) create mode 100644 src/Commands/QueryCommitChangedLines.cs diff --git a/src/Commands/QueryCommitChangedLines.cs b/src/Commands/QueryCommitChangedLines.cs new file mode 100644 index 00000000..d5605104 --- /dev/null +++ b/src/Commands/QueryCommitChangedLines.cs @@ -0,0 +1,43 @@ +using System.Text.RegularExpressions; + +namespace SourceGit.Commands +{ + public class QueryCommitChangedLines : Command + { + public QueryCommitChangedLines(string repo, string sha) + { + WorkingDirectory = repo; + Context = repo; + Args = $"show --numstat --oneline {sha}"; + } + + public (int, int) Result() + { + _addedLines = 0; + _removedLines = 0; + _firstLine = true; + Exec(); + return (_addedLines, _removedLines); + } + + protected override void OnReadline(string line) + { + if (_firstLine) { + _firstLine = false; + return; + } + + var parts = Regex.Split(line, @"\s+"); + + if (parts.Length >= 2) + { + _addedLines += int.Parse(parts[0]); + _removedLines += int.Parse(parts[1]); + } + } + + private int _addedLines; + private int _removedLines; + private bool _firstLine; + } +} diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index bf9f57c9..455c530d 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -635,6 +635,13 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage); }); + Task.Run(() => + { + var lines = new Commands.QueryCommitChangedLines(_repo.FullPath, _commit.SHA).Result(); + Console.WriteLine(lines); + //Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage); + }); + Task.Run(() => { var signInfo = new Commands.QueryCommitSignInfo(_repo.FullPath, _commit.SHA, !_repo.HasAllowedSignersFile).Result();