fix: running git command in UIThread via context menu entry blocks whole app (#1384)
Some checks failed
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
Localization Check / localization-check (push) Has been cancelled

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-03 23:36:15 +08:00
parent d85f82e171
commit c2187edbe9
No known key found for this signature in database
4 changed files with 37 additions and 24 deletions

View file

@ -47,9 +47,9 @@ namespace SourceGit.ViewModels
RefreshViewContent();
}
public void ResetToSelectedRevision()
public Task<bool> ResetToSelectedRevision()
{
new Commands.Checkout(_repo.FullPath).FileWithRevision(_file, $"{_revision.SHA}");
return Task.Run(() => new Commands.Checkout(_repo.FullPath).FileWithRevision(_file, $"{_revision.SHA}"));
}
private void RefreshViewContent()
@ -84,7 +84,7 @@ namespace SourceGit.ViewModels
var stream = Commands.QueryFileContent.Run(_repo.FullPath, _revision.SHA, _file);
var fileSize = stream.Length;
var bitmap = fileSize > 0 ? new Bitmap(stream) : null;
var imageType = Path.GetExtension(_file).TrimStart('.').ToUpper(CultureInfo.CurrentCulture);
var imageType = Path.GetExtension(_file)!.TrimStart('.').ToUpper(CultureInfo.CurrentCulture);
var image = new Models.RevisionImageFile() { Image = bitmap, FileSize = fileSize, ImageType = imageType };
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, image));
}
@ -103,7 +103,7 @@ namespace SourceGit.ViewModels
var matchLFS = REG_LFS_FORMAT().Match(content);
if (matchLFS.Success)
{
var lfs = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
var lfs = new Models.RevisionLFSObject() { Object = new() };
lfs.Object.Oid = matchLFS.Groups[1].Value;
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, lfs));
@ -156,15 +156,12 @@ namespace SourceGit.ViewModels
[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();
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
{
".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"
};
private static readonly HashSet<string> IMG_EXTS = [".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"];
private Repository _repo = null;
private string _file = null;
private Models.Commit _revision = null;
private bool _isDiffMode = true;
private bool _isDiffMode = false;
private object _viewContent = null;
}
@ -265,7 +262,6 @@ namespace SourceGit.ViewModels
public FileHistories(Repository repo, string file, string commit = null)
{
_repo = repo;
_file = file;
Task.Run(() =>
{
@ -288,10 +284,10 @@ namespace SourceGit.ViewModels
switch (SelectedCommits.Count)
{
case 1:
ViewContent = new FileHistoriesSingleRevision(_repo, _file, SelectedCommits[0], _prevIsDiffMode);
ViewContent = new FileHistoriesSingleRevision(_repo, file, SelectedCommits[0], _prevIsDiffMode);
break;
case 2:
ViewContent = new FileHistoriesCompareRevisions(_repo, _file, SelectedCommits[0], SelectedCommits[1]);
ViewContent = new FileHistoriesCompareRevisions(_repo, file, SelectedCommits[0], SelectedCommits[1]);
break;
default:
ViewContent = SelectedCommits.Count;
@ -317,11 +313,10 @@ namespace SourceGit.ViewModels
}
private readonly Repository _repo = null;
private readonly string _file = null;
private bool _isLoading = true;
private bool _prevIsDiffMode = true;
private List<Models.Commit> _commits = null;
private Dictionary<string, string> _fullCommitMessages = new Dictionary<string, string>();
private Dictionary<string, string> _fullCommitMessages = new();
private object _viewContent = null;
}
}