mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 20:54:59 +00:00
feature: supports searching revision files (#775)
This commit is contained in:
parent
536f225867
commit
894f3e9b03
10 changed files with 350 additions and 15 deletions
|
@ -82,7 +82,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
get;
|
||||
private set;
|
||||
} = new AvaloniaList<string>();
|
||||
} = [];
|
||||
|
||||
public string SearchChangeFilter
|
||||
{
|
||||
|
@ -106,13 +106,68 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
get;
|
||||
private set;
|
||||
} = new AvaloniaList<Models.CommitLink>();
|
||||
} = [];
|
||||
|
||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
||||
{
|
||||
get => _repo.Settings?.IssueTrackerRules;
|
||||
}
|
||||
|
||||
public string RevisionFileSearchFilter
|
||||
{
|
||||
get => _revisionFileSearchFilter;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _revisionFileSearchFilter, value))
|
||||
{
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
if (_revisionFiles.Count == 0)
|
||||
{
|
||||
var sha = Commit.SHA;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var files = new Commands.QueryRevisionFileNames(_repo.FullPath, sha).Result();
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => {
|
||||
if (sha == Commit.SHA)
|
||||
{
|
||||
_revisionFiles.Clear();
|
||||
_revisionFiles.AddRange(files);
|
||||
UpdateRevisionFileSearchSuggestion();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateRevisionFileSearchSuggestion();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsRevisionFileSearchSuggestionOpen = false;
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AvaloniaList<string> RevisionFileSearchSuggestion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
|
||||
public bool IsRevisionFileSearchSuggestionOpen
|
||||
{
|
||||
get => _isRevisionFileSearchSuggestionOpen;
|
||||
set => SetProperty(ref _isRevisionFileSearchSuggestionOpen, value);
|
||||
}
|
||||
|
||||
public CommitDetail(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
|
@ -147,17 +202,23 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = null;
|
||||
_commit = null;
|
||||
|
||||
if (_changes != null)
|
||||
_changes.Clear();
|
||||
if (_visibleChanges != null)
|
||||
_visibleChanges.Clear();
|
||||
if (_selectedChanges != null)
|
||||
_selectedChanges.Clear();
|
||||
|
||||
_signInfo = null;
|
||||
_searchChangeFilter = null;
|
||||
_diffContext = null;
|
||||
_viewRevisionFileContent = null;
|
||||
_cancelToken = null;
|
||||
|
||||
WebLinks.Clear();
|
||||
_revisionFiles.Clear();
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
}
|
||||
|
||||
public void NavigateTo(string commitSHA)
|
||||
|
@ -175,6 +236,11 @@ namespace SourceGit.ViewModels
|
|||
SearchChangeFilter = string.Empty;
|
||||
}
|
||||
|
||||
public void ClearRevisionFileSearchFilter()
|
||||
{
|
||||
RevisionFileSearchFilter = string.Empty;
|
||||
}
|
||||
|
||||
public Models.Commit GetParent(string sha)
|
||||
{
|
||||
return new Commands.QuerySingleCommit(_repo.FullPath, sha).Result();
|
||||
|
@ -543,6 +609,8 @@ namespace SourceGit.ViewModels
|
|||
private void Refresh()
|
||||
{
|
||||
_changes = null;
|
||||
_revisionFiles.Clear();
|
||||
|
||||
FullMessage = string.Empty;
|
||||
SignInfo = null;
|
||||
Changes = [];
|
||||
|
@ -550,6 +618,8 @@ namespace SourceGit.ViewModels
|
|||
SelectedChanges = null;
|
||||
ViewRevisionFileContent = null;
|
||||
Children.Clear();
|
||||
RevisionFileSearchFilter = string.Empty;
|
||||
IsRevisionFileSearchSuggestionOpen = false;
|
||||
|
||||
if (_commit == null)
|
||||
return;
|
||||
|
@ -716,6 +786,24 @@ namespace SourceGit.ViewModels
|
|||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
private void UpdateRevisionFileSearchSuggestion()
|
||||
{
|
||||
var suggestion = new List<string>();
|
||||
foreach (var file in _revisionFiles)
|
||||
{
|
||||
if (file.Contains(_revisionFileSearchFilter, StringComparison.OrdinalIgnoreCase) &&
|
||||
file.Length != _revisionFileSearchFilter.Length)
|
||||
suggestion.Add(file);
|
||||
|
||||
if (suggestion.Count >= 100)
|
||||
break;
|
||||
}
|
||||
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
RevisionFileSearchSuggestion.AddRange(suggestion);
|
||||
IsRevisionFileSearchSuggestionOpen = suggestion.Count > 0;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
|
||||
private static partial Regex REG_LFS_FORMAT();
|
||||
|
||||
|
@ -736,5 +824,8 @@ namespace SourceGit.ViewModels
|
|||
private DiffContext _diffContext = null;
|
||||
private object _viewRevisionFileContent = null;
|
||||
private Commands.Command.CancelToken _cancelToken = null;
|
||||
private List<string> _revisionFiles = [];
|
||||
private string _revisionFileSearchFilter = string.Empty;
|
||||
private bool _isRevisionFileSearchSuggestionOpen = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue