Skip to content

Commit a2f47df

Browse files
committed
code_style: remove warnings reported by JetBrains Rider
Signed-off-by: leo <[email protected]>
1 parent 3f3eaa4 commit a2f47df

Some content is hidden

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

47 files changed

+136
-183
lines changed

src/App.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,10 @@ private void Check4Update(bool manually = false)
608608
try
609609
{
610610
// Fetch latest release information.
611-
using var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) };
612-
var data = await client.GetStringAsync("https://sourcegit-scm.github.io/data/version.json");
611+
using var client = new HttpClient();
612+
client.Timeout = TimeSpan.FromSeconds(5);
613613

614-
// Parse JSON into Models.Version.
614+
var data = await client.GetStringAsync("https://sourcegit-scm.github.io/data/version.json");
615615
var ver = JsonSerializer.Deserialize(data, JsonCodeGen.Default.Version);
616616
if (ver == null)
617617
return;

src/Commands/Command.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ public async Task<bool> ExecAsync()
4848
proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs);
4949
proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs);
5050

51-
Process dummy = null;
52-
var dummyProcLock = new object();
51+
var captured = new CapturedProcess() { Process = proc };
52+
var capturedLock = new object();
5353
try
5454
{
5555
proc.Start();
5656

5757
// Not safe, please only use `CancellationToken` in readonly commands.
5858
if (CancellationToken.CanBeCanceled)
5959
{
60-
dummy = proc;
6160
CancellationToken.Register(() =>
6261
{
63-
lock (dummyProcLock)
62+
lock (capturedLock)
6463
{
65-
if (dummy is { HasExited: false })
66-
dummy.Kill();
64+
if (captured is { Process: { HasExited: false } })
65+
captured.Process.Kill();
6766
}
6867
});
6968
}
@@ -89,12 +88,9 @@ public async Task<bool> ExecAsync()
8988
HandleOutput(e.Message, errs);
9089
}
9190

92-
if (dummy != null)
91+
lock (capturedLock)
9392
{
94-
lock (dummyProcLock)
95-
{
96-
dummy = null;
97-
}
93+
captured.Process = null;
9894
}
9995

10096
Log?.AppendLine(string.Empty);
@@ -116,7 +112,8 @@ public async Task<bool> ExecAsync()
116112

117113
protected Result ReadToEnd()
118114
{
119-
using var proc = new Process() { StartInfo = CreateGitStartInfo(true) };
115+
using var proc = new Process();
116+
proc.StartInfo = CreateGitStartInfo(true);
120117

121118
try
122119
{
@@ -138,7 +135,8 @@ protected Result ReadToEnd()
138135

139136
protected async Task<Result> ReadToEndAsync()
140137
{
141-
using var proc = new Process() { StartInfo = CreateGitStartInfo(true) };
138+
using var proc = new Process();
139+
proc.StartInfo = CreateGitStartInfo(true);
142140

143141
try
144142
{
@@ -245,6 +243,11 @@ private void HandleOutput(string line, List<string> errs)
245243
errs.Add(line);
246244
}
247245

246+
private class CapturedProcess
247+
{
248+
public Process Process { get; set; } = null;
249+
}
250+
248251
[GeneratedRegex(@"\d+%")]
249252
private static partial Regex REG_PROGRESS();
250253
}

src/Commands/Commit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task<bool> RunAsync()
3434
}
3535
}
3636

37-
private readonly string _tmpFile = string.Empty;
38-
private readonly string _message = string.Empty;
37+
private readonly string _tmpFile;
38+
private readonly string _message;
3939
}
4040
}

src/Commands/QueryBranches.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ private Models.Branch ParseLine(string line)
9494
branch.IsLocal = true;
9595
}
9696

97-
ulong committerDate = 0;
98-
ulong.TryParse(parts[1], out committerDate);
97+
ulong.TryParse(parts[1], out var committerDate);
9998

10099
branch.FullName = refName;
101100
branch.CommitterDate = committerDate;

src/Commands/QueryFileContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static async Task<Stream> RunAsync(string repo, string revision, string f
2121
var stream = new MemoryStream();
2222
try
2323
{
24-
using var proc = Process.Start(starter);
24+
using var proc = Process.Start(starter)!;
2525
await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false);
2626
await proc.WaitForExitAsync().ConfigureAwait(false);
2727
}
@@ -49,7 +49,7 @@ public static async Task<Stream> FromLFSAsync(string repo, string oid, long size
4949
var stream = new MemoryStream();
5050
try
5151
{
52-
using var proc = Process.Start(starter);
52+
using var proc = Process.Start(starter)!;
5353
await proc.StandardInput.WriteLineAsync("version https://git-lfs.github.com/spec/v1").ConfigureAwait(false);
5454
await proc.StandardInput.WriteLineAsync($"oid sha256:{oid}").ConfigureAwait(false);
5555
await proc.StandardInput.WriteLineAsync($"size {size}").ConfigureAwait(false);

src/Commands/QueryGitDir.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.IO;
2-
using System.Threading.Tasks;
32

43
namespace SourceGit.Commands
54
{
@@ -16,12 +15,6 @@ public string GetResult()
1615
return Parse(ReadToEnd());
1716
}
1817

19-
public async Task<string> GetResultAsync()
20-
{
21-
var rs = await ReadToEndAsync().ConfigureAwait(false);
22-
return Parse(rs);
23-
}
24-
2518
private string Parse(Result rs)
2619
{
2720
if (!rs.IsSuccess)

src/Commands/QueryTags.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ public QueryTags(string repo)
3434
if (!string.IsNullOrEmpty(message) && message.Equals(name, StringComparison.Ordinal))
3535
message = null;
3636

37-
ulong creactorDate = 0;
38-
ulong.TryParse(subs[5], out creactorDate);
37+
ulong.TryParse(subs[5], out var creatorDate);
3938

4039
tags.Add(new Models.Tag()
4140
{
4241
Name = name,
4342
IsAnnotated = subs[1].Equals("tag", StringComparison.Ordinal),
4443
SHA = string.IsNullOrEmpty(subs[3]) ? subs[2] : subs[3],
4544
Creator = Models.User.FindOrAdd(subs[4]),
46-
CreatorDate = creactorDate,
45+
CreatorDate = creatorDate,
4746
Message = message,
4847
});
4948
}

src/Commands/SaveChangesAsPatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static async Task<bool> ProcessSingleChangeAsync(string repo, Models.Dif
6262

6363
try
6464
{
65-
using var proc = Process.Start(starter);
65+
using var proc = Process.Start(starter)!;
6666
await proc.StandardOutput.BaseStream.CopyToAsync(writer).ConfigureAwait(false);
6767
await proc.WaitForExitAsync().ConfigureAwait(false);
6868
return proc.ExitCode == 0;

src/Commands/SaveRevisionFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class SaveRevisionFile
99
{
1010
public static async Task RunAsync(string repo, string revision, string file, string saveTo)
1111
{
12-
var dir = Path.GetDirectoryName(saveTo);
12+
var dir = Path.GetDirectoryName(saveTo) ?? string.Empty;
1313
if (!Directory.Exists(dir))
1414
Directory.CreateDirectory(dir);
1515

@@ -42,7 +42,7 @@ private static async Task ExecCmdAsync(string repo, string args, string outputFi
4242
{
4343
try
4444
{
45-
using var proc = Process.Start(starter);
45+
using var proc = Process.Start(starter)!;
4646

4747
if (input != null)
4848
{

src/Commands/UnstageChangesForAmend.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public async Task<bool> ExecAsync()
6363

6464
try
6565
{
66-
using var proc = Process.Start(starter);
66+
using var proc = Process.Start(starter)!;
6767
await proc.StandardInput.WriteAsync(_patchBuilder.ToString());
6868
proc.StandardInput.Close();
6969

@@ -83,7 +83,7 @@ public async Task<bool> ExecAsync()
8383
}
8484
}
8585

86-
private string _repo = "";
87-
private StringBuilder _patchBuilder = new StringBuilder();
86+
private readonly string _repo;
87+
private readonly StringBuilder _patchBuilder = new();
8888
}
8989
}

0 commit comments

Comments
 (0)