Skip to content

Commit 61372e2

Browse files
committed
code_review: PR #1472
Move `Commands.IsCommitSHA` testing from `Commands.QuerySingleCommit` to `ViewModels.Repository.StartSearchCommits`, because we only need test the SHA user typed in Signed-off-by: leo <[email protected]>
1 parent 8602ba2 commit 61372e2

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/Commands/QuerySingleCommit.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@ public class QuerySingleCommit : Command
66
{
77
public QuerySingleCommit(string repo, string sha)
88
{
9-
_repo = repo;
10-
_sha = sha;
11-
129
WorkingDirectory = repo;
1310
Context = repo;
1411
Args = $"show --no-show-signature --decorate=full --format=%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s -s {sha}";
1512
}
1613

1714
public Models.Commit Result()
1815
{
19-
var isCommitSHA = new IsCommitSHA(_repo, _sha).Result();
20-
if (!isCommitSHA)
21-
return null;
22-
2316
var rs = ReadToEnd();
2417
if (rs.IsSuccess && !string.IsNullOrEmpty(rs.StdOut))
2518
{
@@ -44,8 +37,5 @@ public Models.Commit Result()
4437

4538
return null;
4639
}
47-
48-
private readonly string _repo;
49-
private readonly string _sha;
5040
}
5141
}

src/ViewModels/Repository.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,17 @@ public void StartSearchCommits()
871871

872872
Task.Run(() =>
873873
{
874-
List<Models.Commit> visible;
874+
List<Models.Commit> visible = [];
875875
var method = (Models.CommitSearchMethod)_searchCommitFilterType;
876876

877877
if (method == Models.CommitSearchMethod.BySHA)
878878
{
879-
var commit = new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).Result();
880-
visible = commit == null ? [] : [commit];
879+
var isCommitSHA = new Commands.IsCommitSHA(_fullpath, _searchCommitFilter).Result();
880+
if (isCommitSHA)
881+
{
882+
var commit = new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).Result();
883+
visible = [commit];
884+
}
881885
}
882886
else
883887
{

0 commit comments

Comments
 (0)