diff --git a/src/ViewModels/Checkout.cs b/src/ViewModels/Checkout.cs index 71b01bcb..fd84682a 100644 --- a/src/ViewModels/Checkout.cs +++ b/src/ViewModels/Checkout.cs @@ -65,13 +65,7 @@ namespace SourceGit.ViewModels { var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch); if (b != null && _repo.HistoriesFilterMode == Models.FilterMode.Included) - { - _repo.Settings.HistoriesFilters.Clear(); - _repo.Settings.UpdateHistoriesFilter(b.FullName, Models.FilterType.LocalBranch, Models.FilterMode.Included); - - if (!string.IsNullOrEmpty(b.Upstream)) - _repo.Settings.UpdateHistoriesFilter(b.Upstream, Models.FilterType.LocalBranch, Models.FilterMode.Included); - } + _repo.SetBranchFilterMode(b, Models.FilterMode.Included, true, false); _repo.MarkBranchesDirtyManually(); _repo.SetWatcherEnabled(true); diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index 62d785f3..3560ea8d 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -128,11 +128,11 @@ namespace SourceGit.ViewModels { if (succ && CheckoutAfterCreated && _repo.HistoriesFilterMode == Models.FilterMode.Included) { - _repo.Settings.HistoriesFilters.Clear(); - _repo.Settings.UpdateHistoriesFilter($"refs/heads/{_name}", Models.FilterType.LocalBranch, Models.FilterMode.Included); + var fake = new Models.Branch() { IsLocal = true, FullName = $"refs/heads/{_name}" }; + if (BasedOn is Models.Branch based && !based.IsLocal) + fake.Upstream = based.FullName; - if (BasedOn is Models.Branch b && !b.IsLocal) - _repo.Settings.UpdateHistoriesFilter(b.FullName, Models.FilterType.LocalBranch, Models.FilterMode.Included); + _repo.SetBranchFilterMode(fake, Models.FilterMode.Included, true, false); } _repo.MarkBranchesDirtyManually(); diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 59f420eb..c5cb23e9 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -768,7 +768,7 @@ namespace SourceGit.ViewModels exclude.Header = App.Text("Repository.FilterCommits.Exclude"); exclude.Click += (_, e) => { - _repo.SetBranchFilterMode(branch, Models.FilterMode.Excluded); + _repo.SetBranchFilterMode(branch, Models.FilterMode.Excluded, false, true); e.Handled = true; }; @@ -780,7 +780,7 @@ namespace SourceGit.ViewModels include.Header = App.Text("Repository.FilterCommits.Include"); include.Click += (_, e) => { - _repo.SetBranchFilterMode(branch, Models.FilterMode.Included); + _repo.SetBranchFilterMode(branch, Models.FilterMode.Included, false, true); e.Handled = true; }; visibility.Items.Add(include); @@ -792,7 +792,7 @@ namespace SourceGit.ViewModels unset.Header = App.Text("Repository.FilterCommits.Default"); unset.Click += (_, e) => { - _repo.SetBranchFilterMode(branch, Models.FilterMode.None); + _repo.SetBranchFilterMode(branch, Models.FilterMode.None, false, true); e.Handled = true; }; visibility.Items.Add(exclude); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 82197bdf..bc86147e 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -770,21 +770,27 @@ namespace SourceGit.ViewModels { var changed = _settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode); if (changed) - RefreshHistoriesFilters(); + RefreshHistoriesFilters(true); } - public void SetBranchFilterMode(Models.Branch branch, Models.FilterMode mode) + public void SetBranchFilterMode(Models.Branch branch, Models.FilterMode mode, bool clearExists, bool refresh) { var node = FindBranchNode(branch.IsLocal ? _localBranchTrees : _remoteBranchTrees, branch.FullName); if (node != null) - SetBranchFilterMode(node, mode); + SetBranchFilterMode(node, mode, clearExists, refresh); } - public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode) + public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode, bool clearExists, bool refresh) { var isLocal = node.Path.StartsWith("refs/heads/", StringComparison.Ordinal); var tree = isLocal ? _localBranchTrees : _remoteBranchTrees; + if (clearExists) + { + _settings.HistoriesFilters.Clear(); + HistoriesFilterMode = Models.FilterMode.None; + } + if (node.Backend is Models.Branch branch) { var type = isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch; @@ -822,7 +828,7 @@ namespace SourceGit.ViewModels cur = parent; } while (true); - RefreshHistoriesFilters(); + RefreshHistoriesFilters(refresh); } public void StashAll(bool autoStart) @@ -2149,18 +2155,21 @@ namespace SourceGit.ViewModels return visible; } - private void RefreshHistoriesFilters() + private void RefreshHistoriesFilters(bool refresh) { - var filters = _settings.CollectHistoriesFilters(); - UpdateBranchTreeFilterMode(LocalBranchTrees, filters); - UpdateBranchTreeFilterMode(RemoteBranchTrees, filters); - UpdateTagFilterMode(filters); - if (_settings.HistoriesFilters.Count > 0) HistoriesFilterMode = _settings.HistoriesFilters[0].Mode; else HistoriesFilterMode = Models.FilterMode.None; + if (!refresh) + return; + + var filters = _settings.CollectHistoriesFilters(); + UpdateBranchTreeFilterMode(LocalBranchTrees, filters); + UpdateBranchTreeFilterMode(RemoteBranchTrees, filters); + UpdateTagFilterMode(filters); + Task.Run(RefreshCommits); } diff --git a/src/Views/FilterModeSwitchButton.axaml.cs b/src/Views/FilterModeSwitchButton.axaml.cs index f68e9166..1d1ae30c 100644 --- a/src/Views/FilterModeSwitchButton.axaml.cs +++ b/src/Views/FilterModeSwitchButton.axaml.cs @@ -120,7 +120,7 @@ namespace SourceGit.Views unset.Header = App.Text("Repository.FilterCommits.Default"); unset.Click += (_, ev) => { - repo.SetBranchFilterMode(node, Models.FilterMode.None); + repo.SetBranchFilterMode(node, Models.FilterMode.None, false, true); ev.Handled = true; }; @@ -134,7 +134,7 @@ namespace SourceGit.Views include.IsEnabled = mode != Models.FilterMode.Included; include.Click += (_, ev) => { - repo.SetBranchFilterMode(node, Models.FilterMode.Included); + repo.SetBranchFilterMode(node, Models.FilterMode.Included, false, true); ev.Handled = true; }; @@ -144,7 +144,7 @@ namespace SourceGit.Views exclude.IsEnabled = mode != Models.FilterMode.Excluded; exclude.Click += (_, ev) => { - repo.SetBranchFilterMode(node, Models.FilterMode.Excluded); + repo.SetBranchFilterMode(node, Models.FilterMode.Excluded, false, true); ev.Handled = true; };