Skip to content

Commit 3583527

Browse files
authored
code_style: general cleanup (#1525)
1 parent b7994a8 commit 3583527

Some content is hidden

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

54 files changed

+225
-400
lines changed

src/App.Commands.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static bool IsCheckForUpdateCommandVisible
4545
public static readonly Command QuitCommand = new Command(_ => Quit(0));
4646
public static readonly Command CopyTextBlockCommand = new Command(async p =>
4747
{
48-
var textBlock = p as TextBlock;
49-
if (textBlock == null)
48+
if (p is not TextBlock textBlock)
5049
return;
5150

5251
if (textBlock.Inlines is { Count: > 0 } inlines)

src/App.axaml.cs

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

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

194192
if (app._activeLocale != null)
@@ -200,8 +198,7 @@ public static void SetLocale(string localeKey)
200198

201199
public static void SetTheme(string theme, string themeOverridesFile)
202200
{
203-
var app = Current as App;
204-
if (app == null)
201+
if (Current is not App app)
205202
return;
206203

207204
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
@@ -254,8 +251,7 @@ public static void SetTheme(string theme, string themeOverridesFile)
254251

255252
public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor)
256253
{
257-
var app = Current as App;
258-
if (app == null)
254+
if (Current is not App app)
259255
return;
260256

261257
if (app._fontsOverrides != null)

src/Commands/Blame.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public Blame(string repo, string file, string revision)
4040
foreach (var line in _result.LineInfos)
4141
{
4242
if (line.CommitSHA.Length > _minSHALen)
43-
{
4443
line.CommitSHA = line.CommitSHA.Substring(0, _minSHALen);
45-
}
4644
}
4745
}
4846

src/Commands/Command.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ protected async Task<Result> ReadToEndAsync()
131131
}
132132

133133
var rs = new Result() { IsSuccess = true };
134-
rs.StdOut = await proc.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
135-
rs.StdErr = await proc.StandardError.ReadToEndAsync().ConfigureAwait(false);
136-
await proc.WaitForExitAsync().ConfigureAwait(false);
134+
rs.StdOut = await proc.StandardOutput.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
135+
rs.StdErr = await proc.StandardError.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
136+
await proc.WaitForExitAsync(CancellationToken).ConfigureAwait(false);
137137

138138
rs.IsSuccess = proc.ExitCode == 0;
139139
proc.Close();

src/Commands/Diff.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,10 @@ private void ProcessInlineHighlights()
249249
foreach (var chunk in chunks)
250250
{
251251
if (chunk.DeletedCount > 0)
252-
{
253252
left.Highlights.Add(new Models.TextInlineRange(chunk.DeletedStart, chunk.DeletedCount));
254-
}
255253

256254
if (chunk.AddedCount > 0)
257-
{
258255
right.Highlights.Add(new Models.TextInlineRange(chunk.AddedStart, chunk.AddedCount));
259-
}
260256
}
261257
}
262258
}

src/Commands/QueryCommits.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private void ParseParent(string data)
121121
if (data.Length < 8)
122122
return;
123123

124-
_current.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
124+
_current.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
125125
}
126126

127127
private async Task MarkFirstMergedAsync()
@@ -133,9 +133,7 @@ private async Task MarkFirstMergedAsync()
133133
if (shas.Length == 0)
134134
return;
135135

136-
var set = new HashSet<string>();
137-
foreach (var sha in shas)
138-
set.Add(sha);
136+
var set = new HashSet<string>(shas);
139137

140138
foreach (var c in _commits)
141139
{

src/Commands/QueryCommitsForInteractiveRebase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void ParseParent(string data)
8686
if (data.Length < 8)
8787
return;
8888

89-
_current.Commit.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
89+
_current.Commit.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
9090
}
9191

9292
private List<Models.InteractiveCommit> _commits = [];

src/Commands/Submodule.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ public async Task<bool> AddAsync(string url, string relativePath, bool recursive
2121
return false;
2222

2323
if (recursive)
24-
{
2524
Args = $"submodule update --init --recursive -- \"{relativePath}\"";
26-
return await ExecAsync().ConfigureAwait(false);
27-
}
2825
else
29-
{
3026
Args = $"submodule update --init -- \"{relativePath}\"";
31-
return await ExecAsync().ConfigureAwait(false);
32-
}
27+
return await ExecAsync().ConfigureAwait(false);
3328
}
3429

3530
public async Task<bool> SetURL(string path, string url)

src/Models/ApplyWhiteSpaceMode.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceGit.Models
22
{
3-
public class ApplyWhiteSpaceMode
3+
public class ApplyWhiteSpaceMode(string n, string d, string a)
44
{
55
public static readonly ApplyWhiteSpaceMode[] Supported =
66
[
@@ -10,15 +10,8 @@ public class ApplyWhiteSpaceMode
1010
new ApplyWhiteSpaceMode("Error All", "Similar to 'error', but shows more", "error-all"),
1111
];
1212

13-
public string Name { get; set; }
14-
public string Desc { get; set; }
15-
public string Arg { get; set; }
16-
17-
public ApplyWhiteSpaceMode(string n, string d, string a)
18-
{
19-
Name = n;
20-
Desc = d;
21-
Arg = a;
22-
}
13+
public string Name { get; set; } = n;
14+
public string Desc { get; set; } = d;
15+
public string Arg { get; set; } = a;
2316
}
2417
}

src/Models/AvatarManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ public void SetFromLocal(string email, string file)
197197

198198
_resources[email] = image;
199199

200-
_requesting.Remove(email);
200+
lock (_synclock)
201+
{
202+
_requesting.Remove(email);
203+
}
201204

202205
var store = Path.Combine(_storePath, GetEmailHash(email));
203206
File.Copy(file, store, true);

0 commit comments

Comments
 (0)