mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
refactor: commit message
- move issue tracker and commit hash links parsing to view models - parsing links async - make sure matched hash is a valid commit oid - disable `CHILDREN` row in submodule info panel Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
5301a368e0
commit
b75676a7f8
17 changed files with 191 additions and 186 deletions
|
@ -5,7 +5,6 @@ using System.IO;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
@ -46,7 +45,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public string FullMessage
|
||||
public Models.CommitFullMessage FullMessage
|
||||
{
|
||||
get => _fullMessage;
|
||||
private set => SetProperty(ref _fullMessage, value);
|
||||
|
@ -85,11 +84,11 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public AvaloniaList<string> Children
|
||||
public List<string> Children
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
get => _children;
|
||||
private set => SetProperty(ref _children, value);
|
||||
}
|
||||
|
||||
public string SearchChangeFilter
|
||||
{
|
||||
|
@ -109,17 +108,12 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _viewRevisionFileContent, value);
|
||||
}
|
||||
|
||||
public AvaloniaList<Models.CommitLink> WebLinks
|
||||
public List<Models.CommitLink> WebLinks
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
|
||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
||||
{
|
||||
get => _repo.Settings?.IssueTrackerRules;
|
||||
}
|
||||
|
||||
public string RevisionFileSearchFilter
|
||||
{
|
||||
get => _revisionFileSearchFilter;
|
||||
|
@ -127,25 +121,23 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
if (SetProperty(ref _revisionFileSearchFilter, value))
|
||||
{
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
if (_revisionFiles.Count == 0)
|
||||
if (_revisionFiles == null)
|
||||
{
|
||||
var sha = Commit.SHA;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var files = new Commands.QueryRevisionFileNames(_repo.FullPath, sha).Result();
|
||||
var filesList = new List<string>();
|
||||
filesList.AddRange(files);
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
if (sha == Commit.SHA)
|
||||
{
|
||||
_revisionFiles.Clear();
|
||||
_revisionFiles.AddRange(files);
|
||||
|
||||
_revisionFiles = filesList;
|
||||
if (!string.IsNullOrEmpty(_revisionFileSearchFilter))
|
||||
UpdateRevisionFileSearchSuggestion();
|
||||
}
|
||||
|
@ -159,23 +151,17 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
else
|
||||
{
|
||||
IsRevisionFileSearchSuggestionOpen = false;
|
||||
RevisionFileSearchSuggestion = null;
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AvaloniaList<string> RevisionFileSearchSuggestion
|
||||
public List<string> RevisionFileSearchSuggestion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
|
||||
public bool IsRevisionFileSearchSuggestionOpen
|
||||
{
|
||||
get => _isRevisionFileSearchSuggestionOpen;
|
||||
set => SetProperty(ref _isRevisionFileSearchSuggestionOpen, value);
|
||||
get => _revisionFileSearchSuggestion;
|
||||
private set => SetProperty(ref _revisionFileSearchSuggestion, value);
|
||||
}
|
||||
|
||||
public CommitDetail(Repository repo)
|
||||
|
@ -212,23 +198,17 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = null;
|
||||
_commit = null;
|
||||
|
||||
if (_changes != null)
|
||||
_changes.Clear();
|
||||
if (_visibleChanges != null)
|
||||
_visibleChanges.Clear();
|
||||
if (_selectedChanges != null)
|
||||
_selectedChanges.Clear();
|
||||
|
||||
_changes = null;
|
||||
_visibleChanges = null;
|
||||
_selectedChanges = null;
|
||||
_signInfo = null;
|
||||
_searchChangeFilter = null;
|
||||
_diffContext = null;
|
||||
_viewRevisionFileContent = null;
|
||||
_cancelToken = null;
|
||||
|
||||
WebLinks.Clear();
|
||||
_revisionFiles.Clear();
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
_revisionFiles = null;
|
||||
_revisionFileSearchSuggestion = null;
|
||||
}
|
||||
|
||||
public void NavigateTo(string commitSHA)
|
||||
|
@ -251,6 +231,11 @@ namespace SourceGit.ViewModels
|
|||
RevisionFileSearchFilter = string.Empty;
|
||||
}
|
||||
|
||||
public void CancelRevisionFileSuggestions()
|
||||
{
|
||||
RevisionFileSearchSuggestion = null;
|
||||
}
|
||||
|
||||
public Models.Commit GetParent(string sha)
|
||||
{
|
||||
return new Commands.QuerySingleCommit(_repo.FullPath, sha).Result();
|
||||
|
@ -322,7 +307,12 @@ namespace SourceGit.ViewModels
|
|||
if (commit != null)
|
||||
{
|
||||
var body = new Commands.QueryCommitFullMessage(submoduleRoot, file.SHA).Result();
|
||||
var submodule = new Models.RevisionSubmodule() { Commit = commit, FullMessage = body };
|
||||
var submodule = new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = commit,
|
||||
FullMessage = new Models.CommitFullMessage { Message = body }
|
||||
};
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = submodule);
|
||||
}
|
||||
else
|
||||
|
@ -332,7 +322,7 @@ namespace SourceGit.ViewModels
|
|||
ViewRevisionFileContent = new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = new Models.Commit() { SHA = file.SHA },
|
||||
FullMessage = string.Empty,
|
||||
FullMessage = null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -622,23 +612,22 @@ namespace SourceGit.ViewModels
|
|||
private void Refresh()
|
||||
{
|
||||
_changes = null;
|
||||
_revisionFiles.Clear();
|
||||
_revisionFiles = null;
|
||||
|
||||
SignInfo = null;
|
||||
ViewRevisionFileContent = null;
|
||||
Children.Clear();
|
||||
Children = null;
|
||||
RevisionFileSearchFilter = string.Empty;
|
||||
IsRevisionFileSearchSuggestionOpen = false;
|
||||
|
||||
GC.Collect();
|
||||
RevisionFileSearchSuggestion = null;
|
||||
|
||||
if (_commit == null)
|
||||
return;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var fullMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
|
||||
Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage);
|
||||
var message = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
|
||||
var links = ParseLinksInMessage(message);
|
||||
Dispatcher.UIThread.Invoke(() => FullMessage = new Models.CommitFullMessage { Message = message, Links = links });
|
||||
});
|
||||
|
||||
Task.Run(() =>
|
||||
|
@ -694,6 +683,49 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
private List<Models.Hyperlink> ParseLinksInMessage(string message)
|
||||
{
|
||||
var links = new List<Models.Hyperlink>();
|
||||
if (_repo.Settings.IssueTrackerRules is { Count: > 0 } rules)
|
||||
{
|
||||
foreach (var rule in rules)
|
||||
rule.Matches(links, message);
|
||||
}
|
||||
|
||||
var shas = REG_SHA_FORMAT().Matches(message);
|
||||
for (int i = 0; i < shas.Count; i++)
|
||||
{
|
||||
var sha = shas[i];
|
||||
if (!sha.Success)
|
||||
continue;
|
||||
|
||||
var hash = sha.Groups[1].Value;
|
||||
var test = new Commands.IsCommitSHA(_repo.FullPath, hash).Result();
|
||||
if (!test)
|
||||
continue;
|
||||
|
||||
var start = sha.Index;
|
||||
var len = sha.Length;
|
||||
var intersect = false;
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (link.Intersect(start, len))
|
||||
{
|
||||
intersect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!intersect)
|
||||
links.Add(new Models.Hyperlink(start, len, hash, true));
|
||||
}
|
||||
|
||||
if (links.Count > 0)
|
||||
links.Sort((l, r) => l.Start - r.Start);
|
||||
|
||||
return links;
|
||||
}
|
||||
|
||||
private void RefreshVisibleChanges()
|
||||
{
|
||||
if (_changes == null)
|
||||
|
@ -813,11 +845,12 @@ namespace SourceGit.ViewModels
|
|||
break;
|
||||
}
|
||||
|
||||
RevisionFileSearchSuggestion.Clear();
|
||||
RevisionFileSearchSuggestion.AddRange(suggestion);
|
||||
IsRevisionFileSearchSuggestionOpen = suggestion.Count > 0;
|
||||
RevisionFileSearchSuggestion = suggestion;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"\b([0-9a-fA-F]{6,40})\b")]
|
||||
private static partial Regex REG_SHA_FORMAT();
|
||||
|
||||
[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();
|
||||
|
||||
|
@ -828,8 +861,9 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private Repository _repo = null;
|
||||
private Models.Commit _commit = null;
|
||||
private string _fullMessage = string.Empty;
|
||||
private Models.CommitFullMessage _fullMessage = null;
|
||||
private Models.CommitSignInfo _signInfo = null;
|
||||
private List<string> _children = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
private List<Models.Change> _visibleChanges = null;
|
||||
private List<Models.Change> _selectedChanges = null;
|
||||
|
@ -837,8 +871,8 @@ namespace SourceGit.ViewModels
|
|||
private DiffContext _diffContext = null;
|
||||
private object _viewRevisionFileContent = null;
|
||||
private Commands.Command.CancelToken _cancelToken = null;
|
||||
private List<string> _revisionFiles = [];
|
||||
private List<string> _revisionFiles = null;
|
||||
private string _revisionFileSearchFilter = string.Empty;
|
||||
private bool _isRevisionFileSearchSuggestionOpen = false;
|
||||
private List<string> _revisionFileSearchSuggestion = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,13 +235,17 @@ namespace SourceGit.ViewModels
|
|||
if (commit != null)
|
||||
{
|
||||
var body = new Commands.QueryCommitFullMessage(repo, sha).Result();
|
||||
return new Models.RevisionSubmodule() { Commit = commit, FullMessage = body };
|
||||
return new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = commit,
|
||||
FullMessage = new Models.CommitFullMessage { Message = body }
|
||||
};
|
||||
}
|
||||
|
||||
return new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = new Models.Commit() { SHA = sha },
|
||||
FullMessage = string.Empty,
|
||||
FullMessage = null,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -123,12 +123,20 @@ namespace SourceGit.ViewModels
|
|||
if (commit != null)
|
||||
{
|
||||
var message = new Commands.QueryCommitFullMessage(submoduleRoot, obj.SHA).Result();
|
||||
var module = new Models.RevisionSubmodule() { Commit = commit, FullMessage = message };
|
||||
var module = new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = commit,
|
||||
FullMessage = new Models.CommitFullMessage { Message = message }
|
||||
};
|
||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
||||
}
|
||||
else
|
||||
{
|
||||
var module = new Models.RevisionSubmodule() { Commit = new Models.Commit() { SHA = obj.SHA }, FullMessage = "" };
|
||||
var module = new Models.RevisionSubmodule()
|
||||
{
|
||||
Commit = new Models.Commit() { SHA = obj.SHA },
|
||||
FullMessage = null
|
||||
};
|
||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var commits = new Commands.QueryCommitsWithFullMessage(repoPath, $"{on.SHA}..HEAD").Result();
|
||||
var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result();
|
||||
var list = new List<InteractiveRebaseItem>();
|
||||
|
||||
foreach (var c in commits)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue