diff --git a/.editorconfig b/.editorconfig index 22c741b9..56725e7b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -100,7 +100,7 @@ dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case # use accessibility modifiers dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion diff --git a/src/App.axaml.cs b/src/App.axaml.cs index b5868ca1..94bcb7ef 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -301,7 +301,7 @@ namespace SourceGit return await clipboard.GetTextAsync(); } } - return default; + return null; } public static string Text(string key, params object[] args) @@ -323,8 +323,7 @@ namespace SourceGit icon.Height = 12; icon.Stretch = Stretch.Uniform; - var geo = Current?.FindResource(key) as StreamGeometry; - if (geo != null) + if (Current?.FindResource(key) is StreamGeometry geo) icon.Data = geo; return icon; @@ -682,8 +681,7 @@ namespace SourceGit } var name = sb.ToString(); - var idx = name.IndexOf('#'); - if (idx >= 0) + if (name.Contains('#')) { if (!name.Equals("fonts:Inter#Inter", StringComparison.Ordinal) && !name.Equals("fonts:SourceGit#JetBrains Mono", StringComparison.Ordinal)) diff --git a/src/Commands/Blame.cs b/src/Commands/Blame.cs index 4fa8b317..1fc51fa4 100644 --- a/src/Commands/Blame.cs +++ b/src/Commands/Blame.cs @@ -51,7 +51,7 @@ namespace SourceGit.Commands private void ParseLine(string line) { - if (line.IndexOf('\0', StringComparison.Ordinal) >= 0) + if (line.Contains('\0', StringComparison.Ordinal)) { _result.IsBinary = true; _result.LineInfos.Clear(); diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 9bfa1c15..975922fc 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -194,7 +194,7 @@ namespace SourceGit.Commands private void HandleOutput(string line, List errs) { - line = line ?? string.Empty; + line ??= string.Empty; Log?.AppendLine(line); // Lines to hide in error message. diff --git a/src/Commands/Commit.cs b/src/Commands/Commit.cs index 17410bc9..1585e7e3 100644 --- a/src/Commands/Commit.cs +++ b/src/Commands/Commit.cs @@ -34,6 +34,6 @@ namespace SourceGit.Commands return succ; } - private string _tmpFile = string.Empty; + private readonly string _tmpFile; } } diff --git a/src/Commands/LFS.cs b/src/Commands/LFS.cs index e621ed7d..18d2ba93 100644 --- a/src/Commands/LFS.cs +++ b/src/Commands/LFS.cs @@ -10,7 +10,7 @@ namespace SourceGit.Commands [GeneratedRegex(@"^(.+)\s+([\w.]+)\s+\w+:(\d+)$")] private static partial Regex REG_LOCK(); - class SubCmd : Command + private class SubCmd : Command { public SubCmd(string repo, string args, Models.ICommandLog log) { diff --git a/src/Commands/QueryCommitsForInteractiveRebase.cs b/src/Commands/QueryCommitsForInteractiveRebase.cs index 615060a5..9f238319 100644 --- a/src/Commands/QueryCommitsForInteractiveRebase.cs +++ b/src/Commands/QueryCommitsForInteractiveRebase.cs @@ -90,6 +90,6 @@ namespace SourceGit.Commands private List _commits = []; private Models.InteractiveCommit _current = null; - private string _boundary = ""; + private readonly string _boundary; } } diff --git a/src/Commands/QueryFileSize.cs b/src/Commands/QueryFileSize.cs index 9016d826..30af7715 100644 --- a/src/Commands/QueryFileSize.cs +++ b/src/Commands/QueryFileSize.cs @@ -16,9 +16,6 @@ namespace SourceGit.Commands public long Result() { - if (_result != 0) - return _result; - var rs = ReadToEnd(); if (rs.IsSuccess) { @@ -29,7 +26,5 @@ namespace SourceGit.Commands return 0; } - - private readonly long _result = 0; } } diff --git a/src/Commands/UnstageChangesForAmend.cs b/src/Commands/UnstageChangesForAmend.cs index c930f136..19def067 100644 --- a/src/Commands/UnstageChangesForAmend.cs +++ b/src/Commands/UnstageChangesForAmend.cs @@ -23,13 +23,11 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.OriginalPath); - _patchBuilder.Append("\n"); } else if (c.Index == Models.ChangeState.Added) { _patchBuilder.Append("0 0000000000000000000000000000000000000000\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } else if (c.Index == Models.ChangeState.Deleted) { @@ -37,7 +35,6 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } else { @@ -46,8 +43,9 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } + + _patchBuilder.Append("\n"); } } diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index 2edcb619..fa07975d 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -38,7 +38,7 @@ namespace SourceGit.Models [GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@.+\.github\.com$")] private static partial Regex REG_GITHUB_USER_EMAIL(); - private object _synclock = new object(); + private readonly Lock _synclock = new(); private string _storePath; private List _avatars = new List(); private Dictionary _resources = new Dictionary(); @@ -144,8 +144,7 @@ namespace SourceGit.Models if (_defaultAvatars.Contains(email)) return null; - if (_resources.ContainsKey(email)) - _resources.Remove(email); + _resources.Remove(email); var localFile = Path.Combine(_storePath, GetEmailHash(email)); if (File.Exists(localFile)) @@ -179,8 +178,7 @@ namespace SourceGit.Models lock (_synclock) { - if (!_requesting.Contains(email)) - _requesting.Add(email); + _requesting.Add(email); } return null; @@ -200,10 +198,7 @@ namespace SourceGit.Models if (image == null) return; - if (_resources.ContainsKey(email)) - _resources[email] = image; - else - _resources.Add(email, image); + _resources[email] = image; _requesting.Remove(email); diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 9a7933c8..f0f4b39b 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -19,7 +19,7 @@ namespace SourceGit.Models public class Commit { // As retrieved by: git mktree chunks, Dictionary hashes, string data, int start) { - int hash; - if (hashes.TryGetValue(data, out hash)) + if (hashes.TryGetValue(data, out var hash)) { chunks.Add(new Chunk(hash, start, data.Length)); } diff --git a/src/Models/User.cs b/src/Models/User.cs index 066ab747..0b4816fe 100644 --- a/src/Models/User.cs +++ b/src/Models/User.cs @@ -26,11 +26,7 @@ namespace SourceGit.Models public override bool Equals(object obj) { - if (obj == null || !(obj is User)) - return false; - - var other = obj as User; - return Name == other.Name && Email == other.Email; + return obj is User other && Name == other.Name && Email == other.Email; } public override int GetHashCode() diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index ccdc645f..a3cfc329 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -246,7 +246,7 @@ namespace SourceGit.Models private long _updateStashes = 0; private long _updateTags = 0; - private object _lockSubmodule = new object(); + private readonly Lock _lockSubmodule = new(); private List _submodules = new List(); } } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index adca05f3..8042ac47 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -128,7 +128,7 @@ namespace SourceGit.Native Microsoft.Win32.RegistryView.Registry64); var git = reg.OpenSubKey("SOFTWARE\\GitForWindows"); - if (git != null && git.GetValue("InstallPath") is string installPath) + if (git?.GetValue("InstallPath") is string installPath) { return Path.Combine(installPath, "bin", "git.exe"); } @@ -181,7 +181,7 @@ namespace SourceGit.Native break; case "cmd": - return "C:\\Windows\\System32\\cmd.exe"; + return @"C:\Windows\System32\cmd.exe"; case "wt": var wtFinder = new StringBuilder("wt.exe", 512); if (PathFindOnPath(wtFinder, null)) @@ -199,8 +199,8 @@ namespace SourceGit.Native finder.VSCode(FindVSCode); finder.VSCodeInsiders(FindVSCodeInsiders); finder.VSCodium(FindVSCodium); - finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Programs\\Fleet\\Fleet.exe"); - finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\JetBrains\\Toolbox"); + finder.Fleet(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Programs\Fleet\Fleet.exe"); + finder.FindJetBrainsFromToolbox(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\JetBrains\Toolbox"); finder.SublimeText(FindSublimeText); finder.TryAdd("Visual Studio", "vs", FindVisualStudio, GenerateCommandlineArgsForVisualStudio); return finder.Founded; diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 42d9dc3e..15704775 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -16,7 +16,7 @@ 12 - + @@ -38,7 +38,7 @@ - + @@ -206,7 +206,7 @@ - + - + - + - + - + @@ -737,7 +737,7 @@ - + @@ -956,7 +956,7 @@ - + - + - +