fix: auto-filter does not work well (#855)

This commit is contained in:
leo 2025-01-02 19:49:14 +08:00
parent 127315528a
commit 4e06944c9f
No known key found for this signature in database
5 changed files with 31 additions and 28 deletions

View file

@ -65,13 +65,7 @@ namespace SourceGit.ViewModels
{ {
var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch); var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch);
if (b != null && _repo.HistoriesFilterMode == Models.FilterMode.Included) if (b != null && _repo.HistoriesFilterMode == Models.FilterMode.Included)
{ _repo.SetBranchFilterMode(b, Models.FilterMode.Included, true, false);
_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.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);

View file

@ -128,11 +128,11 @@ namespace SourceGit.ViewModels
{ {
if (succ && CheckoutAfterCreated && _repo.HistoriesFilterMode == Models.FilterMode.Included) if (succ && CheckoutAfterCreated && _repo.HistoriesFilterMode == Models.FilterMode.Included)
{ {
_repo.Settings.HistoriesFilters.Clear(); var fake = new Models.Branch() { IsLocal = true, FullName = $"refs/heads/{_name}" };
_repo.Settings.UpdateHistoriesFilter($"refs/heads/{_name}", Models.FilterType.LocalBranch, Models.FilterMode.Included); if (BasedOn is Models.Branch based && !based.IsLocal)
fake.Upstream = based.FullName;
if (BasedOn is Models.Branch b && !b.IsLocal) _repo.SetBranchFilterMode(fake, Models.FilterMode.Included, true, false);
_repo.Settings.UpdateHistoriesFilter(b.FullName, Models.FilterType.LocalBranch, Models.FilterMode.Included);
} }
_repo.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();

View file

@ -768,7 +768,7 @@ namespace SourceGit.ViewModels
exclude.Header = App.Text("Repository.FilterCommits.Exclude"); exclude.Header = App.Text("Repository.FilterCommits.Exclude");
exclude.Click += (_, e) => exclude.Click += (_, e) =>
{ {
_repo.SetBranchFilterMode(branch, Models.FilterMode.Excluded); _repo.SetBranchFilterMode(branch, Models.FilterMode.Excluded, false, true);
e.Handled = true; e.Handled = true;
}; };
@ -780,7 +780,7 @@ namespace SourceGit.ViewModels
include.Header = App.Text("Repository.FilterCommits.Include"); include.Header = App.Text("Repository.FilterCommits.Include");
include.Click += (_, e) => include.Click += (_, e) =>
{ {
_repo.SetBranchFilterMode(branch, Models.FilterMode.Included); _repo.SetBranchFilterMode(branch, Models.FilterMode.Included, false, true);
e.Handled = true; e.Handled = true;
}; };
visibility.Items.Add(include); visibility.Items.Add(include);
@ -792,7 +792,7 @@ namespace SourceGit.ViewModels
unset.Header = App.Text("Repository.FilterCommits.Default"); unset.Header = App.Text("Repository.FilterCommits.Default");
unset.Click += (_, e) => unset.Click += (_, e) =>
{ {
_repo.SetBranchFilterMode(branch, Models.FilterMode.None); _repo.SetBranchFilterMode(branch, Models.FilterMode.None, false, true);
e.Handled = true; e.Handled = true;
}; };
visibility.Items.Add(exclude); visibility.Items.Add(exclude);

View file

@ -770,21 +770,27 @@ namespace SourceGit.ViewModels
{ {
var changed = _settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode); var changed = _settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode);
if (changed) 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); var node = FindBranchNode(branch.IsLocal ? _localBranchTrees : _remoteBranchTrees, branch.FullName);
if (node != null) 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 isLocal = node.Path.StartsWith("refs/heads/", StringComparison.Ordinal);
var tree = isLocal ? _localBranchTrees : _remoteBranchTrees; var tree = isLocal ? _localBranchTrees : _remoteBranchTrees;
if (clearExists)
{
_settings.HistoriesFilters.Clear();
HistoriesFilterMode = Models.FilterMode.None;
}
if (node.Backend is Models.Branch branch) if (node.Backend is Models.Branch branch)
{ {
var type = isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch; var type = isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch;
@ -822,7 +828,7 @@ namespace SourceGit.ViewModels
cur = parent; cur = parent;
} while (true); } while (true);
RefreshHistoriesFilters(); RefreshHistoriesFilters(refresh);
} }
public void StashAll(bool autoStart) public void StashAll(bool autoStart)
@ -2149,18 +2155,21 @@ namespace SourceGit.ViewModels
return visible; 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) if (_settings.HistoriesFilters.Count > 0)
HistoriesFilterMode = _settings.HistoriesFilters[0].Mode; HistoriesFilterMode = _settings.HistoriesFilters[0].Mode;
else else
HistoriesFilterMode = Models.FilterMode.None; HistoriesFilterMode = Models.FilterMode.None;
if (!refresh)
return;
var filters = _settings.CollectHistoriesFilters();
UpdateBranchTreeFilterMode(LocalBranchTrees, filters);
UpdateBranchTreeFilterMode(RemoteBranchTrees, filters);
UpdateTagFilterMode(filters);
Task.Run(RefreshCommits); Task.Run(RefreshCommits);
} }

View file

@ -120,7 +120,7 @@ namespace SourceGit.Views
unset.Header = App.Text("Repository.FilterCommits.Default"); unset.Header = App.Text("Repository.FilterCommits.Default");
unset.Click += (_, ev) => unset.Click += (_, ev) =>
{ {
repo.SetBranchFilterMode(node, Models.FilterMode.None); repo.SetBranchFilterMode(node, Models.FilterMode.None, false, true);
ev.Handled = true; ev.Handled = true;
}; };
@ -134,7 +134,7 @@ namespace SourceGit.Views
include.IsEnabled = mode != Models.FilterMode.Included; include.IsEnabled = mode != Models.FilterMode.Included;
include.Click += (_, ev) => include.Click += (_, ev) =>
{ {
repo.SetBranchFilterMode(node, Models.FilterMode.Included); repo.SetBranchFilterMode(node, Models.FilterMode.Included, false, true);
ev.Handled = true; ev.Handled = true;
}; };
@ -144,7 +144,7 @@ namespace SourceGit.Views
exclude.IsEnabled = mode != Models.FilterMode.Excluded; exclude.IsEnabled = mode != Models.FilterMode.Excluded;
exclude.Click += (_, ev) => exclude.Click += (_, ev) =>
{ {
repo.SetBranchFilterMode(node, Models.FilterMode.Excluded); repo.SetBranchFilterMode(node, Models.FilterMode.Excluded, false, true);
ev.Handled = true; ev.Handled = true;
}; };