Skip to content

Commit eb45380

Browse files
committed
code_review: PR #1525
- `OpenForDiffAsync` should not use `await` (we do not need to wait it ends) - Modify `Checkout`, `CheckoutCommit` and `CreateBranch` Signed-off-by: leo <[email protected]>
1 parent 3583527 commit eb45380

File tree

8 files changed

+35
-51
lines changed

8 files changed

+35
-51
lines changed

src/App.axaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ public static void SendNotification(string context, string message)
186186

187187
public static void SetLocale(string localeKey)
188188
{
189-
if (Current is not App app || app.Resources[localeKey] is not ResourceDictionary targetLocale || targetLocale == app._activeLocale)
189+
if (Current is not App app ||
190+
app.Resources[localeKey] is not ResourceDictionary targetLocale ||
191+
targetLocale == app._activeLocale)
190192
return;
191193

192194
if (app._activeLocale != null)

src/ViewModels/BranchCompare.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ public ContextMenu CreateChangeContextMenu()
125125
var diffWithMerger = new MenuItem();
126126
diffWithMerger.Header = App.Text("DiffWithMerger");
127127
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
128-
diffWithMerger.Click += async (_, ev) =>
128+
diffWithMerger.Click += (sender, ev) =>
129129
{
130130
var toolType = Preferences.Instance.ExternalMergeToolType;
131131
var toolPath = Preferences.Instance.ExternalMergeToolPath;
132132
var opt = new Models.DiffOption(_based.Head, _to.Head, change);
133133

134-
await Commands.MergeTool.OpenForDiffAsync(_repo, toolType, toolPath, opt);
134+
_ = Commands.MergeTool.OpenForDiffAsync(_repo, toolType, toolPath, opt);
135135
ev.Handled = true;
136136
};
137137
menu.Items.Add(diffWithMerger);

src/ViewModels/Checkout.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,8 @@ public override async Task<bool> Sure()
5858

5959
var succ = false;
6060
var needPopStash = false;
61-
62-
if (DiscardLocalChanges)
63-
{
64-
succ = await new Commands.Checkout(_repo.FullPath)
65-
.Use(log)
66-
.BranchAsync(Branch, true);
67-
}
68-
else
61+
62+
if (!DiscardLocalChanges)
6963
{
7064
var changes = await new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).GetResultAsync();
7165
if (changes > 0)
@@ -82,11 +76,11 @@ public override async Task<bool> Sure()
8276

8377
needPopStash = true;
8478
}
85-
86-
succ = await new Commands.Checkout(_repo.FullPath)
87-
.Use(log)
88-
.BranchAsync(Branch, false);
8979
}
80+
81+
succ = await new Commands.Checkout(_repo.FullPath)
82+
.Use(log)
83+
.BranchAsync(Branch, DiscardLocalChanges);
9084

9185
if (succ)
9286
{

src/ViewModels/CheckoutAndFastForward.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public override async Task<bool> Sure()
9292
if (IsRecurseSubmoduleVisible && RecurseSubmodules)
9393
{
9494
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath).GetResultAsync();
95-
9695
if (submodules.Count > 0)
9796
await new Commands.Submodule(_repo.FullPath)
9897
.Use(log)

src/ViewModels/CheckoutCommit.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public override async Task<bool> Sure()
4141
var log = _repo.CreateLog("Checkout Commit");
4242
Use(log);
4343

44-
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
45-
bool succ;
46-
var needPop = false;
47-
4844
if (_repo.CurrentBranch is { IsDetachedHead: true })
4945
{
5046
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
@@ -59,14 +55,11 @@ public override async Task<bool> Sure()
5955
}
6056
}
6157
}
58+
59+
var succ = false;
60+
var needPop = false;
6261

63-
if (DiscardLocalChanges)
64-
{
65-
succ = await new Commands.Checkout(_repo.FullPath)
66-
.Use(log)
67-
.CommitAsync(Commit.SHA, true);
68-
}
69-
else
62+
if (!DiscardLocalChanges)
7063
{
7164
var changes = await new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).GetResultAsync();
7265
if (changes > 0)
@@ -83,15 +76,15 @@ public override async Task<bool> Sure()
8376

8477
needPop = true;
8578
}
86-
87-
succ = await new Commands.Checkout(_repo.FullPath)
88-
.Use(log)
89-
.CommitAsync(Commit.SHA, false);
9079
}
80+
81+
succ = await new Commands.Checkout(_repo.FullPath)
82+
.Use(log)
83+
.CommitAsync(Commit.SHA, DiscardLocalChanges);
9184

9285
if (succ)
9386
{
94-
if (updateSubmodules)
87+
if (IsRecurseSubmoduleVisible && RecurseSubmodules)
9588
{
9689
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath).GetResultAsync();
9790
if (submodules.Count > 0)

src/ViewModels/CommitDetail.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
325325
var diffWithMerger = new MenuItem();
326326
diffWithMerger.Header = App.Text("DiffWithMerger");
327327
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
328-
diffWithMerger.Click += async (_, ev) =>
328+
diffWithMerger.Click += (sender, ev) =>
329329
{
330330
var toolType = Preferences.Instance.ExternalMergeToolType;
331331
var toolPath = Preferences.Instance.ExternalMergeToolPath;
332332
var opt = new Models.DiffOption(_commit, change);
333333

334-
await Commands.MergeTool.OpenForDiffAsync(_repo.FullPath, toolType, toolPath, opt);
334+
_ = Commands.MergeTool.OpenForDiffAsync(_repo.FullPath, toolType, toolPath, opt);
335335
ev.Handled = true;
336336
};
337337

src/ViewModels/CreateBranch.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ public override async Task<bool> Sure()
123123
var log = _repo.CreateLog($"Create Branch '{fixedName}'");
124124
Use(log);
125125

126-
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
127-
bool succ;
128-
129126
if (CheckoutAfterCreated)
130127
{
131128
if (_repo.CurrentBranch is { IsDetachedHead: true } && !_repo.CurrentBranch.Head.Equals(_baseOnRevision, StringComparison.Ordinal))
@@ -143,17 +140,12 @@ public override async Task<bool> Sure()
143140
}
144141
}
145142
}
146-
143+
144+
bool succ;
147145
if (CheckoutAfterCreated && !_repo.IsBare)
148146
{
149147
var needPopStash = false;
150-
if (DiscardLocalChanges)
151-
{
152-
succ = await new Commands.Checkout(_repo.FullPath)
153-
.Use(log)
154-
.BranchAsync(fixedName, _baseOnRevision, true, _allowOverwrite);
155-
}
156-
else
148+
if (!DiscardLocalChanges)
157149
{
158150
var changes = await new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).GetResultAsync();
159151
if (changes > 0)
@@ -170,15 +162,15 @@ public override async Task<bool> Sure()
170162

171163
needPopStash = true;
172164
}
173-
174-
succ = await new Commands.Checkout(_repo.FullPath)
175-
.Use(log)
176-
.BranchAsync(fixedName, _baseOnRevision, false, _allowOverwrite);
177165
}
166+
167+
succ = await new Commands.Checkout(_repo.FullPath)
168+
.Use(log)
169+
.BranchAsync(fixedName, _baseOnRevision, DiscardLocalChanges, _allowOverwrite);
178170

179171
if (succ)
180172
{
181-
if (updateSubmodules)
173+
if (IsRecurseSubmoduleVisible && RecurseSubmodules)
182174
{
183175
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath).GetResultAsync();
184176
if (submodules.Count > 0)

src/ViewModels/Histories.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,11 @@ public ContextMenu MakeContextMenu(DataGrid list)
599599
var parents = new List<Models.Commit>();
600600
foreach (var sha in commit.Parents)
601601
{
602-
var parent = _commits.Find(x => x.SHA == sha) ?? await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();
602+
var parent = _commits.Find(x => x.SHA == sha);
603+
if (parent == null)
604+
parent = await new Commands.QuerySingleCommit(_repo.FullPath, sha)
605+
.GetResultAsync();
606+
603607
if (parent != null)
604608
parents.Add(parent);
605609
}

0 commit comments

Comments
 (0)