Skip to content

Commit ec17ea9

Browse files
authored
code_style: general cleanup (#1497)
1 parent baeef2d commit ec17ea9

Some content is hidden

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

58 files changed

+134
-236
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
container: ${{ matrix.container || '' }}
3232
steps:
3333
- name: Install common CLI tools
34-
if: ${{ startsWith(matrix.runtime, 'linux-') }}
34+
if: startsWith(matrix.runtime, 'linux-')
3535
run: |
3636
export DEBIAN_FRONTEND=noninteractive
3737
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
@@ -45,7 +45,7 @@ jobs:
4545
with:
4646
dotnet-version: 9.0.x
4747
- name: Configure arm64 packages
48-
if: ${{ matrix.runtime == 'linux-arm64' }}
48+
if: matrix.runtime == 'linux-arm64'
4949
run: |
5050
sudo dpkg --add-architecture arm64
5151
echo 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal main restricted
@@ -55,7 +55,7 @@ jobs:
5555
sudo sed -i -e 's/^deb http/deb [arch=amd64] http/g' /etc/apt/sources.list
5656
sudo sed -i -e 's/^deb mirror/deb [arch=amd64] mirror/g' /etc/apt/sources.list
5757
- name: Install cross-compiling dependencies
58-
if: ${{ matrix.runtime == 'linux-arm64' }}
58+
if: matrix.runtime == 'linux-arm64'
5959
run: |
6060
sudo apt-get update
6161
sudo apt-get install -y llvm gcc-aarch64-linux-gnu
@@ -64,10 +64,10 @@ jobs:
6464
- name: Publish
6565
run: dotnet publish src/SourceGit.csproj -c Release -o publish -r ${{ matrix.runtime }}
6666
- name: Rename executable file
67-
if: ${{ startsWith(matrix.runtime, 'linux-') }}
67+
if: startsWith(matrix.runtime, 'linux-')
6868
run: mv publish/SourceGit publish/sourcegit
6969
- name: Tar artifact
70-
if: ${{ startsWith(matrix.runtime, 'linux-') || startsWith(matrix.runtime, 'osx-') }}
70+
if: startsWith(matrix.runtime, 'linux-') || startsWith(matrix.runtime, 'osx-')
7171
run: |
7272
tar -cvf "sourcegit.${{ matrix.runtime }}.tar" -C publish .
7373
rm -r publish/*

src/App.axaml.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,21 @@ public static void ShowWindow(object data, bool showAsDialog)
148148

149149
public static void RaiseException(string context, string message)
150150
{
151-
if (Current is App app && app._launcher != null)
151+
if (Current is App { _launcher: not null } app)
152152
app._launcher.DispatchNotification(context, message, true);
153153
}
154154

155155
public static void SendNotification(string context, string message)
156156
{
157-
if (Current is App app && app._launcher != null)
157+
if (Current is App { _launcher: not null } app)
158158
app._launcher.DispatchNotification(context, message, false);
159159
}
160160

161161
public static void SetLocale(string localeKey)
162162
{
163163
var app = Current as App;
164-
if (app == null)
165-
return;
166164

167-
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
165+
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
168166
if (targetLocale == null || targetLocale == app._activeLocale)
169167
return;
170168

@@ -286,22 +284,14 @@ public static void SetFonts(string defaultFont, string monospaceFont, bool onlyU
286284

287285
public static async void CopyText(string data)
288286
{
289-
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
290-
{
291-
if (desktop.MainWindow?.Clipboard is { } clipboard)
292-
await clipboard.SetTextAsync(data ?? "");
293-
}
287+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow.Clipboard: { } clipboard })
288+
await clipboard.SetTextAsync(data ?? "");
294289
}
295290

296291
public static async Task<string> GetClipboardTextAsync()
297292
{
298-
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
299-
{
300-
if (desktop.MainWindow?.Clipboard is { } clipboard)
301-
{
302-
return await clipboard.GetTextAsync();
303-
}
304-
}
293+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow.Clipboard: { } clipboard })
294+
return await clipboard.GetTextAsync();
305295
return null;
306296
}
307297

@@ -562,7 +552,7 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
562552
Models.AvatarManager.Instance.Start();
563553

564554
string startupRepo = null;
565-
if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]))
555+
if (desktop.Args is { Length: 1 } && Directory.Exists(desktop.Args[0]))
566556
startupRepo = desktop.Args[0];
567557

568558
var pref = ViewModels.Preferences.Instance;

src/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public bool Exec()
4343
proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs);
4444
proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs);
4545

46-
var dummy = null as Process;
46+
Process dummy = null;
4747
var dummyProcLock = new object();
4848
try
4949
{

src/Commands/QueryCommits.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ private void MarkFirstMerged()
132132
if (shas.Length == 0)
133133
return;
134134

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

139137
foreach (var c in _commits)
140138
{

src/Commands/QueryRevisionFileNames.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ public List<string> Result()
1818
return [];
1919

2020
var lines = rs.StdOut.Split('\0', System.StringSplitOptions.RemoveEmptyEntries);
21-
var outs = new List<string>();
22-
foreach (var line in lines)
23-
outs.Add(line);
24-
return outs;
21+
return [.. lines];
2522
}
2623
}
2724
}

src/Commands/Worktree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Worktree(string repo)
1818

1919
var rs = ReadToEnd();
2020
var worktrees = new List<Models.Worktree>();
21-
var last = null as Models.Worktree;
21+
Models.Worktree last = null;
2222
if (rs.IsSuccess)
2323
{
2424
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);

src/Models/AvatarManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void Start()
5555
{
5656
while (true)
5757
{
58-
var email = null as string;
58+
string email = null;
5959

6060
lock (_synclock)
6161
{
@@ -79,7 +79,7 @@ public void Start()
7979
$"https://www.gravatar.com/avatar/{md5}?d=404";
8080

8181
var localFile = Path.Combine(_storePath, md5);
82-
var img = null as Bitmap;
82+
Bitmap img = null;
8383
try
8484
{
8585
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(2) };
@@ -113,7 +113,7 @@ public void Start()
113113
_requesting.Remove(email);
114114
}
115115

116-
Dispatcher.UIThread.InvokeAsync(() =>
116+
Dispatcher.UIThread.Post(() =>
117117
{
118118
_resources[email] = img;
119119
NotifyResourceChanged(email, img);

src/Models/CommitGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
8282

8383
foreach (var commit in commits)
8484
{
85-
var major = null as PathHelper;
85+
PathHelper major = null;
8686
var isMerged = commit.IsMerged;
8787

8888
// Update current y offset

src/Models/CommitLink.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public static List<CommitLink> Get(List<Remote> remotes)
2727
trimmedUrl = url.AsSpan(0, url.Length - 4);
2828

2929
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
30-
outs.Add(new($"Github ({trimmedUrl.Slice(19)})", $"{url}/commit/"));
30+
outs.Add(new($"Github ({trimmedUrl[19..]})", $"{url}/commit/"));
3131
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
32-
outs.Add(new($"GitLab ({trimmedUrl.Slice(trimmedUrl.Slice(15).IndexOf('/') + 16)})", $"{url}/-/commit/"));
32+
outs.Add(new($"GitLab ({trimmedUrl[(trimmedUrl[15..].IndexOf('/') + 16)..]})", $"{url}/-/commit/"));
3333
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
34-
outs.Add(new($"Gitee ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
34+
outs.Add(new($"Gitee ({trimmedUrl[18..]})", $"{url}/commit/"));
3535
else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal))
36-
outs.Add(new($"BitBucket ({trimmedUrl.Slice(22)})", $"{url}/commits/"));
36+
outs.Add(new($"BitBucket ({trimmedUrl[22..]})", $"{url}/commits/"));
3737
else if (url.StartsWith("https://codeberg.org/", StringComparison.Ordinal))
38-
outs.Add(new($"Codeberg ({trimmedUrl.Slice(21)})", $"{url}/commit/"));
38+
outs.Add(new($"Codeberg ({trimmedUrl[21..]})", $"{url}/commit/"));
3939
else if (url.StartsWith("https://gitea.org/", StringComparison.Ordinal))
40-
outs.Add(new($"Gitea ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
40+
outs.Add(new($"Gitea ({trimmedUrl[18..]})", $"{url}/commit/"));
4141
else if (url.StartsWith("https://git.sr.ht/", StringComparison.Ordinal))
42-
outs.Add(new($"sourcehut ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
42+
outs.Add(new($"sourcehut ({trimmedUrl[18..]})", $"{url}/commit/"));
4343
}
4444
}
4545

src/Models/DealWithChangesAfterStashing.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@
22

33
namespace SourceGit.Models
44
{
5-
public class DealWithChangesAfterStashing
5+
public class DealWithChangesAfterStashing(string label, string desc)
66
{
7-
public string Label { get; set; }
8-
public string Desc { get; set; }
7+
public string Label { get; set; } = label;
8+
public string Desc { get; set; } = desc;
99

1010
public static readonly List<DealWithChangesAfterStashing> Supported = [
1111
new ("Discard", "All (or selected) changes will be discarded"),
1212
new ("Keep Index", "Staged changes are left intact"),
1313
new ("Keep All", "All (or selected) changes are left intact"),
1414
];
15-
16-
public DealWithChangesAfterStashing(string label, string desc)
17-
{
18-
Label = label;
19-
Desc = desc;
20-
}
2115
}
2216
}

0 commit comments

Comments
 (0)