Skip to content

Commit a104694

Browse files
committed
Remove redundant Task.Run in Sure methods
1 parent fd35707 commit a104694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+195
-258
lines changed

src/ViewModels/AddRemote.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,14 @@ public static ValidationResult ValidateSSHKey(string sshkey, ValidationContext c
8787
return ValidationResult.Success;
8888
}
8989

90-
public override Task<bool> Sure()
90+
public override async Task<bool> Sure()
9191
{
9292
_repo.SetWatcherEnabled(false);
9393
ProgressDescription = "Adding remote ...";
9494

9595
var log = _repo.CreateLog("Add Remote");
9696
Use(log);
9797

98-
return Task.Run(async () =>
9998
{
10099
var succ = await new Commands.Remote(_repo.FullPath).Use(log).AddAsync(_name, _url);
101100
if (succ)
@@ -112,7 +111,7 @@ await CallUIThreadAsync(() =>
112111
_repo.SetWatcherEnabled(true);
113112
});
114113
return succ;
115-
});
114+
}
116115
}
117116

118117
private readonly Repository _repo = null;

src/ViewModels/AddSubmodule.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static ValidationResult ValidateURL(string url, ValidationContext ctx)
4040
return ValidationResult.Success;
4141
}
4242

43-
public override Task<bool> Sure()
43+
public override async Task<bool> Sure()
4444
{
4545
_repo.SetWatcherEnabled(false);
4646
ProgressDescription = "Adding submodule...";
@@ -59,14 +59,13 @@ public override Task<bool> Sure()
5959
relativePath = Path.GetFileName(_url);
6060
}
6161

62-
return Task.Run(async () =>
6362
{
6463
var succ = await new Commands.Submodule(_repo.FullPath).Use(log).AddAsync(_url, relativePath, Recursive);
6564
log.Complete();
6665

67-
CallUIThread(() => _repo.SetWatcherEnabled(true));
66+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
6867
return succ;
69-
});
68+
}
7069
}
7170

7271
private readonly Repository _repo = null;

src/ViewModels/AddToIgnore.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ public AddToIgnore(Repository repo, string pattern)
2727
StorageFile = Models.GitIgnoreFile.Supported[0];
2828
}
2929

30-
public override Task<bool> Sure()
30+
public override async Task<bool> Sure()
3131
{
3232
_repo.SetWatcherEnabled(false);
3333
ProgressDescription = "Adding Ignored File(s) ...";
3434

35-
return Task.Run(async () =>
3635
{
3736
var file = StorageFile.GetFullPath(_repo.FullPath, _repo.GitDir);
3837
if (!File.Exists(file))
3938
{
40-
File.WriteAllLines(file, [_pattern]);
39+
await File.WriteAllLinesAsync(file, [_pattern]);
4140
}
4241
else
4342
{
@@ -48,14 +47,14 @@ public override Task<bool> Sure()
4847
await File.AppendAllLinesAsync(file, [_pattern]);
4948
}
5049

51-
CallUIThread(() =>
50+
await CallUIThreadAsync(() =>
5251
{
5352
_repo.MarkWorkingCopyDirtyManually();
5453
_repo.SetWatcherEnabled(true);
5554
});
5655

5756
return true;
58-
});
57+
}
5958
}
6059

6160
private readonly Repository _repo;

src/ViewModels/AddWorktree.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static ValidationResult ValidateWorktreePath(string path, ValidationConte
105105
return ValidationResult.Success;
106106
}
107107

108-
public override Task<bool> Sure()
108+
public override async Task<bool> Sure()
109109
{
110110
_repo.SetWatcherEnabled(false);
111111
ProgressDescription = "Adding worktree ...";
@@ -116,14 +116,13 @@ public override Task<bool> Sure()
116116

117117
Use(log);
118118

119-
return Task.Run(async () =>
120119
{
121120
var succ = await new Commands.Worktree(_repo.FullPath).Use(log).AddAsync(_path, branchName, _createNewBranch, tracking);
122121
log.Complete();
123122

124-
CallUIThread(() => _repo.SetWatcherEnabled(true));
123+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
125124
return succ;
126-
});
125+
}
127126
}
128127

129128
private Repository _repo = null;

src/ViewModels/Apply.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,19 @@ public static ValidationResult ValidatePatchFile(string file, ValidationContext
4141
return new ValidationResult($"File '{file}' can NOT be found!!!");
4242
}
4343

44-
public override Task<bool> Sure()
44+
public override async Task<bool> Sure()
4545
{
4646
_repo.SetWatcherEnabled(false);
4747
ProgressDescription = "Apply patch...";
4848

4949
var log = _repo.CreateLog("Apply Patch");
50-
return Task.Run(async () =>
5150
{
5251
var succ = await new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, null).Use(log).ExecAsync();
5352
log.Complete();
5453

55-
CallUIThread(() => _repo.SetWatcherEnabled(true));
54+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
5655
return succ;
57-
});
56+
}
5857
}
5958

6059
private readonly Repository _repo = null;

src/ViewModels/ApplyStash.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ public ApplyStash(Repository repo, Models.Stash stash)
2828
Stash = stash;
2929
}
3030

31-
public override Task<bool> Sure()
31+
public override async Task<bool> Sure()
3232
{
3333
ProgressDescription = $"Applying stash: {Stash.Name}";
3434

3535
var log = _repo.CreateLog("Apply Stash");
36-
return Task.Run(async () =>
3736
{
3837
var succ = await new Commands.Stash(_repo.FullPath).Use(log).ApplyAsync(Stash.Name, RestoreIndex);
3938
if (succ && DropAfterApply)
4039
await new Commands.Stash(_repo.FullPath).Use(log).DropAsync(Stash.Name);
4140

4241
log.Complete();
4342
return true;
44-
});
43+
}
4544
}
4645

4746
private readonly Repository _repo;

src/ViewModels/Archive.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,27 @@ public Archive(Repository repo, Models.Tag tag)
4444
BasedOn = tag;
4545
}
4646

47-
public override Task<bool> Sure()
47+
public override async Task<bool> Sure()
4848
{
4949
_repo.SetWatcherEnabled(false);
5050
ProgressDescription = "Archiving ...";
5151

5252
var log = _repo.CreateLog("Archive");
5353
Use(log);
5454

55-
return Task.Run(async () =>
5655
{
5756
var succ = await new Commands.Archive(_repo.FullPath, _revision, _saveFile).Use(log).ExecAsync();
5857
log.Complete();
5958

60-
CallUIThread(() =>
59+
await CallUIThreadAsync(() =>
6160
{
6261
_repo.SetWatcherEnabled(true);
6362
if (succ)
6463
App.SendNotification(_repo.FullPath, $"Save archive to : {_saveFile}");
6564
});
6665

6766
return succ;
68-
});
67+
}
6968
}
7069

7170
private readonly Repository _repo = null;

src/ViewModels/Checkout.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Checkout(Repository repo, string branch)
3333
DiscardLocalChanges = false;
3434
}
3535

36-
public override Task<bool> Sure()
36+
public override async Task<bool> Sure()
3737
{
3838
_repo.SetWatcherEnabled(false);
3939
ProgressDescription = $"Checkout '{Branch}' ...";
@@ -42,14 +42,13 @@ public override Task<bool> Sure()
4242
Use(log);
4343

4444
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
45-
return Task.Run(async () =>
4645
{
4746
bool succ;
4847
var needPopStash = false;
4948

5049
if (!_repo.ConfirmCheckoutBranch())
5150
{
52-
CallUIThread(() => _repo.SetWatcherEnabled(true));
51+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
5352
return true;
5453
}
5554

@@ -66,7 +65,7 @@ public override Task<bool> Sure()
6665
if (!succ)
6766
{
6867
log.Complete();
69-
CallUIThread(() => _repo.SetWatcherEnabled(true));
68+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
7069
return false;
7170
}
7271

@@ -91,7 +90,7 @@ public override Task<bool> Sure()
9190

9291
log.Complete();
9392

94-
CallUIThread(() =>
93+
await CallUIThreadAsync(() =>
9594
{
9695
ProgressDescription = "Waiting for branch updated...";
9796

@@ -105,7 +104,7 @@ public override Task<bool> Sure()
105104

106105
Task.Delay(400).Wait();
107106
return succ;
108-
});
107+
}
109108
}
110109

111110
private readonly Repository _repo = null;

src/ViewModels/CheckoutAndFastForward.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public CheckoutAndFastForward(Repository repo, Models.Branch localBranch, Models
3838
RemoteBranch = remoteBranch;
3939
}
4040

41-
public override Task<bool> Sure()
41+
public override async Task<bool> Sure()
4242
{
4343
_repo.SetWatcherEnabled(false);
4444
ProgressDescription = $"Checkout and Fast-Forward '{LocalBranch.Name}' ...";
@@ -47,14 +47,13 @@ public override Task<bool> Sure()
4747
Use(log);
4848

4949
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
50-
return Task.Run(async () =>
5150
{
5251
var succ = false;
5352
var needPopStash = false;
5453

5554
if (!_repo.ConfirmCheckoutBranch())
5655
{
57-
CallUIThread(() => _repo.SetWatcherEnabled(true));
56+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
5857
return true;
5958
}
6059

@@ -71,7 +70,7 @@ public override Task<bool> Sure()
7170
if (!succ)
7271
{
7372
log.Complete();
74-
CallUIThread(() => _repo.SetWatcherEnabled(true));
73+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
7574
return false;
7675
}
7776

@@ -96,7 +95,7 @@ public override Task<bool> Sure()
9695

9796
log.Complete();
9897

99-
CallUIThread(() =>
98+
await CallUIThreadAsync(() =>
10099
{
101100
ProgressDescription = "Waiting for branch updated...";
102101

@@ -109,7 +108,7 @@ public override Task<bool> Sure()
109108

110109
Task.Delay(400).Wait();
111110
return succ;
112-
});
111+
}
113112
}
114113

115114
private Repository _repo;

src/ViewModels/CheckoutCommit.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public CheckoutCommit(Repository repo, Models.Commit commit)
3333
DiscardLocalChanges = false;
3434
}
3535

36-
public override Task<bool> Sure()
36+
public override async Task<bool> Sure()
3737
{
3838
_repo.SetWatcherEnabled(false);
3939
ProgressDescription = $"Checkout Commit '{Commit.SHA}' ...";
@@ -42,14 +42,13 @@ public override Task<bool> Sure()
4242
Use(log);
4343

4444
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
45-
return Task.Run(async () =>
4645
{
4746
bool succ;
4847
var needPop = false;
4948

5049
if (!_repo.ConfirmCheckoutBranch())
5150
{
52-
CallUIThread(() => _repo.SetWatcherEnabled(true));
51+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
5352
return true;
5453
}
5554

@@ -66,7 +65,7 @@ public override Task<bool> Sure()
6665
if (!succ)
6766
{
6867
log.Complete();
69-
CallUIThread(() => _repo.SetWatcherEnabled(true));
68+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
7069
return false;
7170
}
7271

@@ -90,9 +89,9 @@ public override Task<bool> Sure()
9089
}
9190

9291
log.Complete();
93-
CallUIThread(() => _repo.SetWatcherEnabled(true));
92+
await CallUIThreadAsync(() => _repo.SetWatcherEnabled(true));
9493
return succ;
95-
});
94+
}
9695
}
9796

9897
private readonly Repository _repo = null;

0 commit comments

Comments
 (0)