Skip to content

Commit 796f889

Browse files
authored
code_style: general cleanup (#1543)
* code_style: general cleanup * feedback fixes
1 parent 666305e commit 796f889

Some content is hidden

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

42 files changed

+127
-166
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ indent_size = 2
292292
# Shell scripts
293293
[*.sh]
294294
end_of_line = lf
295+
295296
[*.{cmd,bat}]
296297
end_of_line = crlf
297298

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ jobs:
66
strategy:
77
matrix:
88
include:
9-
- name : Windows x64
9+
- name: Windows x64
1010
os: windows-2022
1111
runtime: win-x64
12-
- name : Windows ARM64
12+
- name: Windows ARM64
1313
os: windows-2022
1414
runtime: win-arm64
15-
- name : macOS (Intel)
15+
- name: macOS (Intel)
1616
os: macos-13
1717
runtime: osx-x64
18-
- name : macOS (Apple Silicon)
18+
- name: macOS (Apple Silicon)
1919
os: macos-latest
2020
runtime: osx-arm64
21-
- name : Linux
21+
- name: Linux
2222
os: ubuntu-latest
2323
runtime: linux-x64
2424
container: ubuntu:20.04
25-
- name : Linux (arm64)
25+
- name: Linux (arm64)
2626
os: ubuntu-latest
2727
runtime: linux-arm64
2828
container: ubuntu:20.04

.github/workflows/format-check.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: Format Check
22
on:
33
push:
4-
branches: [ develop ]
4+
branches: [develop]
5+
pull_request:
6+
branches: [develop]
57
workflow_dispatch:
68
workflow_call:
79

.github/workflows/localization-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Localization Check
22
on:
33
push:
4-
branches: [ develop ]
4+
branches: [develop]
55
paths:
66
- 'src/Resources/Locales/**'
77
workflow_dispatch:

.github/workflows/package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: windows-2022
1313
strategy:
1414
matrix:
15-
runtime: [ win-x64, win-arm64 ]
15+
runtime: [win-x64, win-arm64]
1616
steps:
1717
- name: Checkout sources
1818
uses: actions/checkout@v4

src/App.axaml.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ public static void SetTheme(string theme, string themeOverridesFile)
221221
try
222222
{
223223
var resDic = new ResourceDictionary();
224-
var overrides = JsonSerializer.Deserialize(File.ReadAllText(themeOverridesFile), JsonCodeGen.Default.ThemeOverrides);
224+
using var stream = File.OpenRead(themeOverridesFile);
225+
var overrides = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.ThemeOverrides);
225226
foreach (var kv in overrides.BasicColors)
226227
{
227228
if (kv.Key.Equals("SystemAccentColor", StringComparison.Ordinal))
@@ -449,31 +450,21 @@ private static bool TryLaunchAsRebaseTodoEditor(string[] args, out int exitCode)
449450
if (!File.Exists(jobsFile))
450451
return true;
451452

452-
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
453+
using var stream = File.OpenRead(jobsFile);
454+
var collection = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.InteractiveRebaseJobCollection);
453455
using var writer = new StreamWriter(file);
454456
foreach (var job in collection.Jobs)
455457
{
456-
switch (job.Action)
458+
var code = job.Action switch
457459
{
458-
case Models.InteractiveRebaseAction.Pick:
459-
writer.WriteLine($"p {job.SHA}");
460-
break;
461-
case Models.InteractiveRebaseAction.Edit:
462-
writer.WriteLine($"e {job.SHA}");
463-
break;
464-
case Models.InteractiveRebaseAction.Reword:
465-
writer.WriteLine($"r {job.SHA}");
466-
break;
467-
case Models.InteractiveRebaseAction.Squash:
468-
writer.WriteLine($"s {job.SHA}");
469-
break;
470-
case Models.InteractiveRebaseAction.Fixup:
471-
writer.WriteLine($"f {job.SHA}");
472-
break;
473-
default:
474-
writer.WriteLine($"d {job.SHA}");
475-
break;
476-
}
460+
Models.InteractiveRebaseAction.Pick => 'p',
461+
Models.InteractiveRebaseAction.Edit => 'e',
462+
Models.InteractiveRebaseAction.Reword => 'r',
463+
Models.InteractiveRebaseAction.Squash => 's',
464+
Models.InteractiveRebaseAction.Fixup => 'f',
465+
_ => 'd'
466+
};
467+
writer.WriteLine($"{code} {job.SHA}");
477468
}
478469

479470
writer.Flush();
@@ -506,7 +497,8 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo
506497

507498
var origHead = File.ReadAllText(origHeadFile).Trim();
508499
var onto = File.ReadAllText(ontoFile).Trim();
509-
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
500+
using var stream = File.OpenRead(jobsFile);
501+
var collection = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.InteractiveRebaseJobCollection);
510502
if (!collection.Onto.Equals(onto) || !collection.OrigHead.Equals(origHead))
511503
return true;
512504

@@ -626,7 +618,8 @@ private void Check4Update(bool manually = false)
626618
try
627619
{
628620
// Fetch latest release information.
629-
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) };
621+
using var client = new HttpClient();
622+
client.Timeout = TimeSpan.FromSeconds(5);
630623
var data = await client.GetStringAsync("https://sourcegit-scm.github.io/data/version.json");
631624

632625
// Parse JSON into Models.Version.

src/Commands/Command.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public async Task<bool> ExecAsync()
5454
{
5555
Log?.AppendLine($"$ git {Args}\n");
5656

57-
var start = CreateGitStartInfo(true);
5857
var errs = new List<string>();
59-
var proc = new Process() { StartInfo = start };
58+
using var proc = new Process();
59+
proc.StartInfo = CreateGitStartInfo(true);
6060

6161
proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs);
6262
proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs);
@@ -67,7 +67,7 @@ public async Task<bool> ExecAsync()
6767
{
6868
proc.Start();
6969

70-
// It not safe, please only use `CancellationToken` in readonly commands.
70+
// Not safe, please only use `CancellationToken` in readonly commands.
7171
if (CancellationToken.CanBeCanceled)
7272
{
7373
dummy = proc;
@@ -110,11 +110,9 @@ public async Task<bool> ExecAsync()
110110
}
111111
}
112112

113-
int exitCode = proc.ExitCode;
114-
proc.Close();
115113
Log?.AppendLine(string.Empty);
116114

117-
if (!CancellationToken.IsCancellationRequested && exitCode != 0)
115+
if (!CancellationToken.IsCancellationRequested && proc.ExitCode != 0)
118116
{
119117
if (RaiseError)
120118
{
@@ -131,8 +129,8 @@ public async Task<bool> ExecAsync()
131129

132130
protected async Task<Result> ReadToEndAsync()
133131
{
134-
var start = CreateGitStartInfo(true);
135-
var proc = new Process() { StartInfo = start };
132+
using var proc = new Process();
133+
proc.StartInfo = CreateGitStartInfo(true);
136134

137135
try
138136
{
@@ -149,7 +147,6 @@ protected async Task<Result> ReadToEndAsync()
149147
await proc.WaitForExitAsync(CancellationToken).ConfigureAwait(false);
150148

151149
rs.IsSuccess = proc.ExitCode == 0;
152-
proc.Close();
153150
return rs;
154151
}
155152

@@ -191,8 +188,8 @@ private ProcessStartInfo CreateGitStartInfo(bool redirect)
191188
// Force using this app as git editor.
192189
start.Arguments += Editor switch
193190
{
194-
EditorType.CoreEditor => $"-c core.editor=\"\\\"{selfExecFile}\\\" --core-editor\" ",
195-
EditorType.RebaseEditor => $"-c core.editor=\"\\\"{selfExecFile}\\\" --rebase-message-editor\" -c sequence.editor=\"\\\"{selfExecFile}\\\" --rebase-todo-editor\" -c rebase.abbreviateCommands=true ",
191+
EditorType.CoreEditor => $"""-c core.editor="\"{selfExecFile}\" --core-editor" """,
192+
EditorType.RebaseEditor => $"""-c core.editor="\"{selfExecFile}\" --rebase-message-editor" -c sequence.editor="\"{selfExecFile}\" --rebase-todo-editor" -c rebase.abbreviateCommands=true """,
196193
_ => "-c core.editor=true ",
197194
};
198195

src/Commands/GenerateCommitMessage.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ await _service.ChatAsync(
6767
});
6868
}
6969

70-
responseBuilder.Append("\n");
71-
summaryBuilder.Append("(file: ");
72-
summaryBuilder.Append(change.Path);
73-
summaryBuilder.Append(")\n");
70+
responseBuilder.AppendLine();
71+
summaryBuilder.Append("(file: ").Append(change.Path).AppendLine(")");
7472
}
7573

7674
if (_cancelToken.IsCancellationRequested)

src/Commands/QueryCommits.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
8080
break;
8181
case 2:
8282
_current.ParseDecorators(line);
83-
if (_current.IsMerged && !_isHeadFounded)
84-
_isHeadFounded = true;
83+
if (_current.IsMerged && !_isHeadFound)
84+
_isHeadFound = true;
8585
break;
8686
case 3:
8787
_current.Author = Models.User.FindOrAdd(line);
@@ -110,7 +110,7 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
110110
if (start < rs.StdOut.Length)
111111
_current.Subject = rs.StdOut.Substring(start);
112112

113-
if (_findFirstMerged && !_isHeadFounded && _commits.Count > 0)
113+
if (_findFirstMerged && !_isHeadFound && _commits.Count > 0)
114114
await MarkFirstMergedAsync().ConfigureAwait(false);
115115

116116
return _commits;
@@ -148,6 +148,6 @@ private async Task MarkFirstMergedAsync()
148148
private List<Models.Commit> _commits = new List<Models.Commit>();
149149
private Models.Commit _current = null;
150150
private bool _findFirstMerged = false;
151-
private bool _isHeadFounded = false;
151+
private bool _isHeadFound = false;
152152
}
153153
}

src/Commands/QueryFileContent.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ public static async Task<Stream> RunAsync(string repo, string revision, string f
2121
var stream = new MemoryStream();
2222
try
2323
{
24-
var proc = new Process() { StartInfo = starter };
25-
proc.Start();
24+
using var proc = Process.Start(starter);
2625
await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false);
2726
await proc.WaitForExitAsync().ConfigureAwait(false);
28-
proc.Close();
2927

3028
stream.Position = 0;
3129
}
@@ -52,14 +50,12 @@ public static async Task<Stream> FromLFSAsync(string repo, string oid, long size
5250
var stream = new MemoryStream();
5351
try
5452
{
55-
var proc = new Process() { StartInfo = starter };
56-
proc.Start();
53+
using var proc = Process.Start(starter);
5754
await proc.StandardInput.WriteLineAsync("version https://git-lfs.github.com/spec/v1").ConfigureAwait(false);
5855
await proc.StandardInput.WriteLineAsync($"oid sha256:{oid}").ConfigureAwait(false);
5956
await proc.StandardInput.WriteLineAsync($"size {size}").ConfigureAwait(false);
6057
await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false);
6158
await proc.WaitForExitAsync().ConfigureAwait(false);
62-
proc.Close();
6359

6460
stream.Position = 0;
6561
}

0 commit comments

Comments
 (0)