From 0ea0cb49097b721eedd263ed5e8325eea784fdbd Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 17 Nov 2024 01:31:25 +0100 Subject: [PATCH] feature: execute children search asynchronously --- src/Commands/QueryCommitChildren.cs | 18 +++++++++--------- src/ViewModels/CommitDetail.cs | 15 +++++++++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Commands/QueryCommitChildren.cs b/src/Commands/QueryCommitChildren.cs index bcf63fa5..2b8fd9f1 100644 --- a/src/Commands/QueryCommitChildren.cs +++ b/src/Commands/QueryCommitChildren.cs @@ -15,19 +15,19 @@ namespace SourceGit.Commands Args = $"rev-list --parents {filters} ^{commit}"; } + protected override void OnReadline(string line) + { + if (line.Contains(_commit)) + _lines.Add(line); + } + public IEnumerable Result() { - var rs = ReadToEnd(); - if (!rs.IsSuccess) - yield break; - - foreach (string s in rs.StdOut.Split('\n', StringSplitOptions.None)) - { - if (s.Contains(_commit)) - yield return s.Substring(0, 40); - } + Exec(); + return _lines; } private string _commit; + private List _lines = new List(); } } diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index f54ae5cb..a816d48a 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -538,16 +538,19 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => SignInfo = signInfo); }); - Task.Run(() => - { - var children = new Commands.QueryCommitChildren(_repo.FullPath, _commit.SHA, _repo.Settings.BuildHistoriesFilter()).Result(); - Dispatcher.UIThread.Invoke(() => Children.AddRange(children)); - }); - if (_cancelToken != null) _cancelToken.Requested = true; _cancelToken = new Commands.Command.CancelToken(); + + Task.Run(() => + { + var cmdChildren = new Commands.QueryCommitChildren(_repo.FullPath, _commit.SHA, _repo.Settings.BuildHistoriesFilter()) { Cancel = _cancelToken }; + var children = cmdChildren.Result(); + if (!cmdChildren.Cancel.Requested) + Dispatcher.UIThread.Post(() => Children.AddRange(children)); + }); + Task.Run(() => { var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0];