mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-05-01 06:15:41 +08:00
feature: async (#1492)
* Async command methods * Async `Task.Run` where possible * Remove redundant `Task.Run` in `Sure` methods * Remove leftover braces and reformat * Async event handlers as needed
This commit is contained in:
@@ -649,9 +649,9 @@ namespace SourceGit.ViewModels
|
||||
Task.Run(RefreshWorkingCopyChanges);
|
||||
Task.Run(RefreshStashes);
|
||||
|
||||
Task.Run(() =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var config = new Commands.Config(_fullpath).ListAll();
|
||||
var config = await new Commands.Config(_fullpath).ListAllAsync();
|
||||
_hasAllowedSignersFile = config.TryGetValue("gpg.ssh.allowedSignersFile", out var allowedSignersFile) && !string.IsNullOrEmpty(allowedSignersFile);
|
||||
|
||||
if (config.TryGetValue("gitflow.branch.master", out var masterName))
|
||||
@@ -869,26 +869,26 @@ namespace SourceGit.ViewModels
|
||||
SelectedSearchedCommit = null;
|
||||
MatchedFilesForSearching = null;
|
||||
|
||||
Task.Run(() =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var visible = new List<Models.Commit>();
|
||||
var method = (Models.CommitSearchMethod)_searchCommitFilterType;
|
||||
|
||||
if (method == Models.CommitSearchMethod.BySHA)
|
||||
{
|
||||
var isCommitSHA = new Commands.IsCommitSHA(_fullpath, _searchCommitFilter).Result();
|
||||
var isCommitSHA = await new Commands.IsCommitSHA(_fullpath, _searchCommitFilter).ResultAsync();
|
||||
if (isCommitSHA)
|
||||
{
|
||||
var commit = new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).Result();
|
||||
var commit = await new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).ResultAsync();
|
||||
visible.Add(commit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, method, _onlySearchCommitsInCurrentBranch).Result();
|
||||
visible = await new Commands.QueryCommits(_fullpath, _searchCommitFilter, method, _onlySearchCommitsInCurrentBranch).ResultAsync();
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
SearchedCommits = visible;
|
||||
IsSearchLoadingVisible = false;
|
||||
@@ -1102,13 +1102,13 @@ namespace SourceGit.ViewModels
|
||||
SetWatcherEnabled(false);
|
||||
|
||||
var log = CreateLog($"Bisect({subcmd})");
|
||||
Task.Run(() =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var succ = new Commands.Bisect(_fullpath, subcmd).Use(log).Exec();
|
||||
var succ = await new Commands.Bisect(_fullpath, subcmd).Use(log).ExecAsync();
|
||||
log.Complete();
|
||||
|
||||
var head = new Commands.QueryRevisionByRefName(_fullpath, "HEAD").Result();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
var head = await new Commands.QueryRevisionByRefName(_fullpath, "HEAD").ResultAsync();
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
if (!succ)
|
||||
App.RaiseException(_fullpath, log.Content.Substring(log.Content.IndexOf('\n')).Trim());
|
||||
@@ -1722,10 +1722,10 @@ namespace SourceGit.ViewModels
|
||||
var install = new MenuItem();
|
||||
install.Header = App.Text("GitLFS.Install");
|
||||
install.Icon = App.CreateMenuIcon("Icons.Init");
|
||||
install.Click += (_, e) =>
|
||||
install.Click += async (_, e) =>
|
||||
{
|
||||
var log = CreateLog("Install LFS");
|
||||
var succ = new Commands.LFS(_fullpath).Install(log);
|
||||
var succ = await new Commands.LFS(_fullpath).InstallAsync(log);
|
||||
if (succ)
|
||||
App.SendNotification(_fullpath, "LFS enabled successfully!");
|
||||
|
||||
@@ -2020,13 +2020,13 @@ namespace SourceGit.ViewModels
|
||||
var compareWithWorktree = new MenuItem();
|
||||
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
|
||||
compareWithWorktree.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithWorktree.Click += (_, _) =>
|
||||
compareWithWorktree.Click += async (_, _) =>
|
||||
{
|
||||
SelectedSearchedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(_fullpath, branch.Head).Result();
|
||||
var target = await new Commands.QuerySingleCommit(_fullpath, branch.Head).ResultAsync();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(_fullpath, target, null);
|
||||
}
|
||||
@@ -2299,13 +2299,13 @@ namespace SourceGit.ViewModels
|
||||
var compareWithWorktree = new MenuItem();
|
||||
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
|
||||
compareWithWorktree.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithWorktree.Click += (_, _) =>
|
||||
compareWithWorktree.Click += async (_, _) =>
|
||||
{
|
||||
SelectedSearchedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(_fullpath, branch.Head).Result();
|
||||
var target = await new Commands.QuerySingleCommit(_fullpath, branch.Head).ResultAsync();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(_fullpath, target, null);
|
||||
}
|
||||
@@ -2631,11 +2631,11 @@ namespace SourceGit.ViewModels
|
||||
var unlock = new MenuItem();
|
||||
unlock.Header = App.Text("Worktree.Unlock");
|
||||
unlock.Icon = App.CreateMenuIcon("Icons.Unlock");
|
||||
unlock.Click += (_, ev) =>
|
||||
unlock.Click += async (_, ev) =>
|
||||
{
|
||||
SetWatcherEnabled(false);
|
||||
var log = CreateLog("Unlock Worktree");
|
||||
var succ = new Commands.Worktree(_fullpath).Use(log).Unlock(worktree.FullPath);
|
||||
var succ = await new Commands.Worktree(_fullpath).Use(log).UnlockAsync(worktree.FullPath);
|
||||
if (succ)
|
||||
worktree.IsLocked = false;
|
||||
log.Complete();
|
||||
@@ -2649,11 +2649,11 @@ namespace SourceGit.ViewModels
|
||||
var loc = new MenuItem();
|
||||
loc.Header = App.Text("Worktree.Lock");
|
||||
loc.Icon = App.CreateMenuIcon("Icons.Lock");
|
||||
loc.Click += (_, ev) =>
|
||||
loc.Click += async (_, ev) =>
|
||||
{
|
||||
SetWatcherEnabled(false);
|
||||
var log = CreateLog("Lock Worktree");
|
||||
var succ = new Commands.Worktree(_fullpath).Use(log).Lock(worktree.FullPath);
|
||||
var succ = await new Commands.Worktree(_fullpath).Use(log).LockAsync(worktree.FullPath);
|
||||
if (succ)
|
||||
worktree.IsLocked = true;
|
||||
log.Complete();
|
||||
@@ -2910,10 +2910,10 @@ namespace SourceGit.ViewModels
|
||||
|
||||
_requestingWorktreeFiles = true;
|
||||
|
||||
Task.Run(() =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_worktreeFiles = new Commands.QueryRevisionFileNames(_fullpath, "HEAD").Result();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
_worktreeFiles = await new Commands.QueryRevisionFileNames(_fullpath, "HEAD").ResultAsync();
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
if (IsSearchingCommitsByFilePath() && _requestingWorktreeFiles)
|
||||
CalcMatchedFilesForSearching();
|
||||
@@ -2945,7 +2945,7 @@ namespace SourceGit.ViewModels
|
||||
MatchedFilesForSearching = matched;
|
||||
}
|
||||
|
||||
private void AutoFetchImpl(object sender)
|
||||
private async void AutoFetchImpl(object sender)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -2970,7 +2970,7 @@ namespace SourceGit.ViewModels
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
|
||||
foreach (var remote in remotes)
|
||||
new Commands.Fetch(_fullpath, remote, false, false) { RaiseError = false }.Exec();
|
||||
await new Commands.Fetch(_fullpath, remote, false, false) { RaiseError = false }.ExecAsync();
|
||||
_lastFetchTime = DateTime.Now;
|
||||
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user