Skip to content

Commit 3b9ac37

Browse files
committed
optimize: only navigate to new commit if it is necessary
Signed-off-by: leo <longshuang@msn.cn>
1 parent dcfaae0 commit 3b9ac37

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

src/ViewModels/Fetch.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public override async Task<bool> Sure()
6868
{
6969
using var lockWatcher = _repo.LockWatcher();
7070

71+
var navigateToUpstreamHEAD = _repo.SelectedView is Histories { AutoSelectedCommit: { IsCurrentHead: true } };
7172
var notags = _repo.Settings.FetchWithoutTags;
7273
var force = _repo.Settings.EnableForceOnFetch;
7374
var log = _repo.CreateLog("Fetch");
@@ -89,11 +90,14 @@ public override async Task<bool> Sure()
8990

9091
log.Complete();
9192

92-
var upstream = _repo.CurrentBranch?.Upstream;
93-
if (!string.IsNullOrEmpty(upstream))
93+
if (navigateToUpstreamHEAD)
9494
{
95-
var upstreamHead = await new Commands.QueryRevisionByRefName(_repo.FullPath, upstream.Substring(13)).GetResultAsync();
96-
_repo.NavigateToCommit(upstreamHead, true);
95+
var upstream = _repo.CurrentBranch?.Upstream;
96+
if (!string.IsNullOrEmpty(upstream))
97+
{
98+
var upstreamHead = await new Commands.QueryRevisionByRefName(_repo.FullPath, upstream.Substring(13)).GetResultAsync();
99+
_repo.NavigateToCommit(upstreamHead, true);
100+
}
97101
}
98102

99103
_repo.MarkFetched();

src/ViewModels/FetchInto.cs

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

3636
log.Complete();
3737

38-
var newHead = await new Commands.QueryRevisionByRefName(_repo.FullPath, Local.Name).GetResultAsync();
39-
_repo.NavigateToCommit(newHead, true);
38+
if (_repo.SelectedViewIndex == 0)
39+
{
40+
var newHead = await new Commands.QueryRevisionByRefName(_repo.FullPath, Local.Name).GetResultAsync();
41+
_repo.NavigateToCommit(newHead, true);
42+
}
43+
4044
return true;
4145
}
4246

src/ViewModels/Merge.cs

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

7272
log.Complete();
7373

74-
var head = await new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").GetResultAsync();
75-
_repo.NavigateToCommit(head, true);
74+
if (_repo.SelectedViewIndex == 0)
75+
{
76+
var head = await new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").GetResultAsync();
77+
_repo.NavigateToCommit(head, true);
78+
}
79+
7680
return true;
7781
}
7882

src/ViewModels/Pull.cs

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

161161
log.Complete();
162162

163-
var head = await new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").GetResultAsync();
164-
_repo.NavigateToCommit(head, true);
163+
if (_repo.SelectedViewIndex == 0)
164+
{
165+
var head = await new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").GetResultAsync();
166+
_repo.NavigateToCommit(head, true);
167+
}
168+
165169
return rs;
166170
}
167171

src/ViewModels/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ public void NavigateToCommit(string sha, bool isDelayMode = false)
985985
{
986986
_navigateToCommitDelayed = sha;
987987
}
988-
else if (_histories != null)
988+
else
989989
{
990990
SelectedViewIndex = 0;
991-
_histories.NavigateTo(sha);
991+
_histories?.NavigateTo(sha);
992992
}
993993
}
994994

0 commit comments

Comments
 (0)