From cc5bb5f6d4ff97d3db62fbea79194274426249b9 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Wed, 20 Nov 2024 01:17:36 +0000 Subject: [PATCH] Show the list of children in the commit details (#710) * feature: add children list to the commit base info view Useful for navigation between the commits. * feature: use repository filters to limit children search * feature: execute children search asynchronously * feature: respect global commit limit for a good measure * fix: input lines may contain several commits The first commit is always the immediate child, so take only 40 initial characters of the line * fix: hide children behind the preference * feature: make parents and children scrollable --- src/Commands/QueryCommitChildren.cs | 34 ++++++++ src/Resources/Locales/en_US.axaml | 2 + src/Resources/Locales/fr_FR.axaml | 1 + src/ViewModels/CommitDetail.cs | 19 ++++ src/ViewModels/Preference.cs | 8 ++ src/Views/CommitBaseInfo.axaml | 131 +++++++++++++++++++--------- src/Views/CommitBaseInfo.axaml.cs | 9 ++ src/Views/CommitDetail.axaml | 1 + src/Views/Preference.axaml | 9 +- 9 files changed, 170 insertions(+), 44 deletions(-) create mode 100644 src/Commands/QueryCommitChildren.cs diff --git a/src/Commands/QueryCommitChildren.cs b/src/Commands/QueryCommitChildren.cs new file mode 100644 index 00000000..c110ef94 --- /dev/null +++ b/src/Commands/QueryCommitChildren.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using SourceGit.ViewModels; + +namespace SourceGit.Commands +{ + public class QueryCommitChildren : Command + { + public QueryCommitChildren(string repo, string commit, string filters) + { + WorkingDirectory = repo; + Context = repo; + _commit = commit; + if (string.IsNullOrEmpty(filters)) + filters = "--all"; + Args = $"rev-list -{Preference.Instance.MaxHistoryCommits} --parents {filters} ^{commit}"; + } + + protected override void OnReadline(string line) + { + if (line.Contains(_commit)) + _lines.Add(line.Substring(0, 40)); + } + + public IEnumerable Result() + { + Exec(); + return _lines; + } + + private string _commit; + private List _lines = new List(); + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ed4f1baf..462cdf90 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -125,6 +125,7 @@ INFORMATION AUTHOR CHANGED + CHILDREN COMMITTER Check refs that contains this commit COMMIT IS CONTAINED BY @@ -451,6 +452,7 @@ Language History Commits Show author time intead of commit time in graph + Show children in the comment details Subject Guide Length GIT Enable Auto CRLF diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 75cd4d58..5a1a8e7b 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -126,6 +126,7 @@ INFORMATIONS AUTEUR CHANGÉ + ENFANTS COMMITTER Vérifier les références contenant ce commit LE COMMIT EST CONTENU PAR diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 7ef8ce85..6d819300 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -78,6 +78,12 @@ namespace SourceGit.ViewModels } } + public AvaloniaList Children + { + get; + private set; + } = new AvaloniaList(); + public string SearchChangeFilter { get => _searchChangeFilter; @@ -515,6 +521,7 @@ namespace SourceGit.ViewModels VisibleChanges = null; SelectedChanges = null; ViewRevisionFileContent = null; + Children.Clear(); if (_commit == null) return; @@ -535,6 +542,18 @@ namespace SourceGit.ViewModels _cancelToken.Requested = true; _cancelToken = new Commands.Command.CancelToken(); + + if (Preference.Instance.ShowChildren) + { + 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]; diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 68065df1..9d3de526 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -294,6 +294,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _statisticsSampleColor, value); } + public bool ShowChildren + { + get => _showChildren; + set => SetProperty(ref _showChildren, value); + } + public List RepositoryNodes { get; @@ -617,5 +623,7 @@ namespace SourceGit.ViewModels private string _externalMergeToolPath = string.Empty; private uint _statisticsSampleColor = 0xFF00FF00; + + private bool _showChildren = false; } } diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index d8b77a18..d3d3bb0e 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -51,7 +51,7 @@ - + @@ -102,50 +102,97 @@ - - - - - - + + + + + + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + SetValue(IssueTrackerRulesProperty, value); } + public static readonly StyledProperty> ChildrenProperty = + AvaloniaProperty.Register>(nameof(Children)); + + public AvaloniaList Children + { + get => GetValue(ChildrenProperty); + set => SetValue(ChildrenProperty, value); + } + public CommitBaseInfo() { InitializeComponent(); diff --git a/src/Views/CommitDetail.axaml b/src/Views/CommitDetail.axaml index cb99b3d9..4c6fd5dc 100644 --- a/src/Views/CommitDetail.axaml +++ b/src/Views/CommitDetail.axaml @@ -24,6 +24,7 @@ SignInfo="{Binding SignInfo}" SupportsContainsIn="True" WebLinks="{Binding WebLinks}" + Children="{Binding Children}" IssueTrackerRules="{Binding IssueTrackerRules}"/> diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 9b84604a..0c7986ab 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -45,7 +45,7 @@ - + + + @@ -188,7 +193,7 @@ - +