From 7ba35e197342d5d1e569e8d778e630613e839ab2 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 10 Nov 2024 02:07:15 +0100 Subject: [PATCH 1/3] feature: add children list to the commit base info view Useful for navigation between the commits. --- src/Commands/QueryCommits.cs | 8 +++++++ src/Models/Commit.cs | 1 + src/Resources/Locales/en_US.axaml | 1 + src/Views/CommitBaseInfo.axaml | 36 +++++++++++++++++++++++++------ src/Views/CommitBaseInfo.axaml.cs | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 5875301ec..1e401a0a7 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -104,6 +104,14 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method if (_findFirstMerged && !_isHeadFounded && _commits.Count > 0) MarkFirstMerged(); + foreach (var commit in _commits) + { + foreach (var parent in _commits.FindAll(c => commit.Parents.Contains(c.SHA))) + { + parent.Children.Add(commit.SHA); + } + } + return _commits; } diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 534cf5bb7..69283e093 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -28,6 +28,7 @@ public static double OpacityForNotMerged public ulong CommitterTime { get; set; } = 0; public string Subject { get; set; } = string.Empty; public List Parents { get; set; } = new List(); + public List Children { get; set; } = new List(); public List Decorators { get; set; } = new List(); public bool HasDecorators => Decorators.Count > 0; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 166ad3abc..38b2de159 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 diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index a16143ae4..70fb21662 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -51,7 +51,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -117,14 +117,36 @@ TextDecorations="Underline" Cursor="Hand" Margin="0,0,16,0" - PointerPressed="OnParentSHAPressed"/> + PointerPressed="OnSHAPressed"/> + + + + + + + + + + + + + + + + - - + + - - + Date: Sun, 10 Nov 2024 17:30:08 +0100 Subject: [PATCH 2/3] Revert "feature: add children list to the commit base info view" This reverts commit 7ba35e197342d5d1e569e8d778e630613e839ab2. --- src/Commands/QueryCommits.cs | 8 ------- src/Models/Commit.cs | 1 - src/Resources/Locales/en_US.axaml | 1 - src/Views/CommitBaseInfo.axaml | 36 ++++++------------------------- src/Views/CommitBaseInfo.axaml.cs | 2 +- 5 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 1e401a0a7..5875301ec 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -104,14 +104,6 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method if (_findFirstMerged && !_isHeadFounded && _commits.Count > 0) MarkFirstMerged(); - foreach (var commit in _commits) - { - foreach (var parent in _commits.FindAll(c => commit.Parents.Contains(c.SHA))) - { - parent.Children.Add(commit.SHA); - } - } - return _commits; } diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 69283e093..534cf5bb7 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -28,7 +28,6 @@ public static double OpacityForNotMerged public ulong CommitterTime { get; set; } = 0; public string Subject { get; set; } = string.Empty; public List Parents { get; set; } = new List(); - public List Children { get; set; } = new List(); public List Decorators { get; set; } = new List(); public bool HasDecorators => Decorators.Count > 0; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 38b2de159..166ad3abc 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -125,7 +125,6 @@ INFORMATION AUTHOR CHANGED - CHILDREN COMMITTER Check refs that contains this commit COMMIT IS CONTAINED BY diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index 70fb21662..a16143ae4 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -51,7 +51,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -117,36 +117,14 @@ TextDecorations="Underline" Cursor="Hand" Margin="0,0,16,0" - PointerPressed="OnSHAPressed"/> - - - - - - - - - - - - - - - - + PointerPressed="OnParentSHAPressed"/> - - + + - - + Date: Sun, 10 Nov 2024 17:45:26 +0100 Subject: [PATCH 3/3] feature: add children list to the commit base info view Useful for navigation between the commits. --- src/Commands/QueryCommitChildren.cs | 34 +++++++++++++++++++++++++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/fr_FR.axaml | 1 + src/ViewModels/CommitDetail.cs | 13 +++++++++++ src/Views/CommitBaseInfo.axaml | 34 ++++++++++++++++++++++++----- src/Views/CommitBaseInfo.axaml.cs | 11 +++++++++- src/Views/CommitDetail.axaml | 1 + 7 files changed, 88 insertions(+), 7 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 000000000..22a445636 --- /dev/null +++ b/src/Commands/QueryCommitChildren.cs @@ -0,0 +1,34 @@ +namespace SourceGit.Commands +{ + public class QueryCommitChildren : Command + { + public QueryCommitChildren(string repo, string sha) + { + WorkingDirectory = repo; + Context = repo; + _sha = sha; + Args = $"rev-list --children --all {sha}^.."; + } + + public string[] Result() + { + var rs = ReadToEnd(); + if (!rs.IsSuccess) + return []; + + int start = rs.StdOut.IndexOf($"\n{_sha}"); + if (start != -1) + { + int end = rs.StdOut.IndexOf('\n', start + 1); + if (end == -1) + end = rs.StdOut.Length; + start = rs.StdOut.IndexOf(' ', start); + if (start != -1 && start < end) + return rs.StdOut.Substring(start + 1, end - start - 1).Split(' ', System.StringSplitOptions.RemoveEmptyEntries); + } + return []; + } + + private string _sha; + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 166ad3abc..38b2de159 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 diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index f50b8f34b..cb3adb16b 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -118,6 +118,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 1600c4cd2..e0870675f 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -78,6 +78,12 @@ public List SelectedChanges } } + public AvaloniaList Children + { + get; + private set; + } = new AvaloniaList(); + public string SearchChangeFilter { get => _searchChangeFilter; @@ -486,6 +492,7 @@ private void Refresh() VisibleChanges = null; SelectedChanges = null; ViewRevisionFileContent = null; + Children.Clear(); if (_commit == null) return; @@ -502,6 +509,12 @@ private void Refresh() Dispatcher.UIThread.Invoke(() => SignInfo = signInfo); }); + Task.Run(() => + { + var children = new Commands.QueryCommitChildren(_repo.FullPath, _commit.SHA).Result(); + Dispatcher.UIThread.Invoke(() => Children.AddRange(children)); + }); + if (_cancelToken != null) _cancelToken.Requested = true; diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index a16143ae4..a886cd9ed 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -51,7 +51,7 @@ - + @@ -117,14 +117,36 @@ TextDecorations="Underline" Cursor="Hand" Margin="0,0,16,0" - PointerPressed="OnParentSHAPressed"/> + PointerPressed="OnSHAPressed"/> + + + + + + + + + + + + + + + + - - + + - - + IssueTrackerRules set => 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(); @@ -113,7 +122,7 @@ private void OnOpenContainsIn(object sender, RoutedEventArgs e) e.Handled = true; } - private void OnParentSHAPressed(object sender, PointerPressedEventArgs e) + private void OnSHAPressed(object sender, PointerPressedEventArgs e) { if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha }) { diff --git a/src/Views/CommitDetail.axaml b/src/Views/CommitDetail.axaml index cb99b3d90..4c6fd5dc1 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}"/>