mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
fix<Histroies>: remove invalid filters to fix issue #I5RZC9
This commit is contained in:
parent
a19f81a708
commit
814637946d
5 changed files with 81 additions and 29 deletions
|
@ -29,11 +29,6 @@ namespace SourceGit.Commands {
|
|||
Args = $"tag --delete {name}";
|
||||
if (!Exec()) return false;
|
||||
|
||||
var repo = Models.Preference.Instance.FindRepository(Cwd);
|
||||
if (repo != null && repo.Filters.Contains(name)) {
|
||||
repo.Filters.Remove(name);
|
||||
}
|
||||
|
||||
if (push) {
|
||||
var remotes = new Remotes(Cwd).Result();
|
||||
foreach (var r in remotes) {
|
||||
|
|
|
@ -3,6 +3,20 @@ using System.IO;
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
/// <summary>
|
||||
/// 用于更新过滤器的参数
|
||||
/// </summary>
|
||||
public class FilterUpdateParam {
|
||||
/// <summary>
|
||||
/// 是否是添加过滤的操作,false代表删除
|
||||
/// </summary>
|
||||
public bool IsAdd = false;
|
||||
|
||||
/// <summary>
|
||||
/// 过滤内容
|
||||
/// </summary>
|
||||
public string Name = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仓库
|
||||
|
@ -26,6 +40,10 @@ namespace SourceGit.Models {
|
|||
[JsonIgnore] public GitFlow GitFlow = new GitFlow();
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 记录历史输入的提交信息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public void PushCommitMessage(string message) {
|
||||
if (string.IsNullOrEmpty(message)) return;
|
||||
|
||||
|
@ -42,10 +60,65 @@ namespace SourceGit.Models {
|
|||
CommitMessages.Insert(0, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断一个文件是否在GitDir中
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public bool ExistsInGitDir(string file) {
|
||||
if (string.IsNullOrEmpty(file)) return false;
|
||||
string fullpath = System.IO.Path.Combine(GitDir, file);
|
||||
return Directory.Exists(fullpath) || File.Exists(fullpath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新提交记录过滤器
|
||||
/// </summary>
|
||||
/// <param name="param">更新参数</param>
|
||||
/// <returns>是否发生了变化</returns>
|
||||
public bool UpdateFilters(FilterUpdateParam param = null) {
|
||||
lock (updateFilterLock) {
|
||||
bool changed = false;
|
||||
|
||||
// 填写了参数就仅增删
|
||||
if (param != null) {
|
||||
if (param.IsAdd) {
|
||||
if (!Filters.Contains(param.Name)) {
|
||||
Filters.Add(param.Name);
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if (Filters.Contains(param.Name)) {
|
||||
Filters.Remove(param.Name);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
// 未填写参数就检测,去掉无效的过滤
|
||||
if (Filters.Count > 0) {
|
||||
var invalidFilters = new List<string>();
|
||||
var tags = new Commands.Tags(Path).Result();
|
||||
foreach (var filter in Filters) {
|
||||
if (filter.StartsWith("refs/")) {
|
||||
if (!ExistsInGitDir(filter)) invalidFilters.Add(filter);
|
||||
} else {
|
||||
if (tags.FindIndex(t => t.Name == filter) < 0) invalidFilters.Add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
if (invalidFilters.Count > 0) {
|
||||
foreach (var filter in invalidFilters) Filters.Remove(filter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly object updateFilterLock = new object();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,6 @@ namespace SourceGit.Views.Popups {
|
|||
full = $"refs/remotes/{remote}/{branch}";
|
||||
new Commands.Push(repo, remote, branch).Exec();
|
||||
}
|
||||
|
||||
var exists = Models.Preference.Instance.FindRepository(repo);
|
||||
if (exists != null && exists.Filters.Contains(full)) {
|
||||
exists.Filters.Remove(full);
|
||||
}
|
||||
|
||||
finishHandler?.Invoke();
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
|
|
|
@ -271,7 +271,7 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
Task.Run(() => {
|
||||
var tags = new Commands.Tags(repo.Path).Result();
|
||||
foreach (var t in tags) t.IsFiltered = repo.Filters.Contains(t.Name);
|
||||
foreach (var tag in tags) tag.IsFiltered = repo.Filters.Contains(tag.Name);
|
||||
Dispatcher.Invoke(() => {
|
||||
txtTagCount.Text = $"({tags.Count})";
|
||||
tagList.ItemsSource = tags;
|
||||
|
@ -1100,30 +1100,17 @@ namespace SourceGit.Views.Widgets {
|
|||
var toggle = sender as ToggleButton;
|
||||
if (toggle == null) return;
|
||||
|
||||
var filter = "";
|
||||
var changed = false;
|
||||
|
||||
var filter = new Models.FilterUpdateParam();
|
||||
filter.IsAdd = (toggle.IsChecked == true);
|
||||
if (toggle.DataContext is BranchNode) {
|
||||
var branch = (toggle.DataContext as BranchNode).Data as Models.Branch;
|
||||
if (branch == null) return;
|
||||
filter = branch.FullName;
|
||||
filter.Name = branch.FullName;
|
||||
} else if (toggle.DataContext is Models.Tag) {
|
||||
filter = (toggle.DataContext as Models.Tag).Name;
|
||||
filter.Name = (toggle.DataContext as Models.Tag).Name;
|
||||
}
|
||||
|
||||
if (toggle.IsChecked == true) {
|
||||
if (!repo.Filters.Contains(filter)) {
|
||||
repo.Filters.Add(filter);
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if (repo.Filters.Contains(filter)) {
|
||||
repo.Filters.Remove(filter);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) (pages.Get("histories") as Histories).UpdateCommits();
|
||||
if (repo.UpdateFilters(filter)) (pages.Get("histories") as Histories).UpdateCommits();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
Task.Run(() => {
|
||||
var limits = "-20000 ";
|
||||
|
||||
repo.UpdateFilters();
|
||||
if (repo.Filters.Count > 0) {
|
||||
limits += string.Join(" ", repo.Filters);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue