mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00: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
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue