Skip to content

code_style: general cleanup #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static async Task<string> GetClipboardTextAsync()
return await clipboard.GetTextAsync();
}
}
return default;
return null;
}

public static string Text(string key, params object[] args)
Expand All @@ -323,8 +323,7 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
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;
Expand Down Expand Up @@ -682,8 +681,7 @@ private string FixFontFamilyName(string input)
}

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))
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Models.BlameData Result()

private void ParseLine(string line)
{
if (line.IndexOf('\0', StringComparison.Ordinal) >= 0)
if (line.Contains('\0', StringComparison.Ordinal))
{
_result.IsBinary = true;
_result.LineInfos.Clear();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private ProcessStartInfo CreateGitStartInfo()

private void HandleOutput(string line, List<string> errs)
{
line = line ?? string.Empty;
line ??= string.Empty;
Log?.AppendLine(line);

// Lines to hide in error message.
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public bool Run()
return succ;
}

private string _tmpFile = string.Empty;
private readonly string _tmpFile;
}
}
2 changes: 1 addition & 1 deletion src/Commands/LFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class LFS
[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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/QueryCommitsForInteractiveRebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ private void ParseParent(string data)

private List<Models.InteractiveCommit> _commits = [];
private Models.InteractiveCommit _current = null;
private string _boundary = "";
private readonly string _boundary;
}
}
5 changes: 0 additions & 5 deletions src/Commands/QueryFileSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public QueryFileSize(string repo, string file, string revision)

public long Result()
{
if (_result != 0)
return _result;

var rs = ReadToEnd();
if (rs.IsSuccess)
{
Expand All @@ -29,7 +26,5 @@ public long Result()

return 0;
}

private readonly long _result = 0;
}
}
6 changes: 2 additions & 4 deletions src/Commands/UnstageChangesForAmend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@ public UnstageChangesForAmend(string repo, List<Models.Change> changes)
_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)
{
_patchBuilder.Append("100644 ");
_patchBuilder.Append(c.DataForAmend.ObjectHash);
_patchBuilder.Append("\t");
_patchBuilder.Append(c.Path);
_patchBuilder.Append("\n");
}
else
{
Expand All @@ -46,8 +43,9 @@ public UnstageChangesForAmend(string repo, List<Models.Change> changes)
_patchBuilder.Append(c.DataForAmend.ObjectHash);
_patchBuilder.Append("\t");
_patchBuilder.Append(c.Path);
_patchBuilder.Append("\n");
}

_patchBuilder.Append("\n");
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static AvatarManager Instance
[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<IAvatarHost> _avatars = new List<IAvatarHost>();
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
Expand Down Expand Up @@ -144,8 +144,7 @@ public Bitmap Request(string email, bool forceRefetch)
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))
Expand Down Expand Up @@ -179,8 +178,7 @@ public Bitmap Request(string email, bool forceRefetch)

lock (_synclock)
{
if (!_requesting.Contains(email))
_requesting.Add(email);
_requesting.Add(email);
}

return null;
Expand All @@ -200,10 +198,7 @@ public void SetFromLocal(string email, string file)
if (image == null)
return;

if (_resources.ContainsKey(email))
_resources[email] = image;
else
_resources.Add(email, image);
_resources[email] = image;

_requesting.Remove(email);

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum CommitSearchMethod
public class Commit
{
// As retrieved by: git mktree </dev/null
public static readonly string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
public const string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";

public static double OpacityForNotMerged
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CommitTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SourceGit.Models
{
public partial class CommitTemplate : ObservableObject
public class CommitTemplate : ObservableObject
{
public string Name
{
Expand Down
1 change: 0 additions & 1 deletion src/Models/NumericSort.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;

namespace SourceGit.Models
{
Expand Down
3 changes: 1 addition & 2 deletions src/Models/RepositorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mo
return false;
}

for (int i = 0; i < HistoriesFilters.Count; i++)
foreach (var filter in HistoriesFilters)
{
var filter = HistoriesFilters[i];
if (filter.Type != type)
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/Models/TemplateEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private static string GetFilesSliced(Context context, int count)

sb.AppendJoin(", ", paths);
if (max < context.changes.Count)
sb.AppendFormat(" and {0} other files", context.changes.Count - max);
sb.Append($" and {context.changes.Count - max} other files");

return sb.ToString();
}
Expand Down
18 changes: 8 additions & 10 deletions src/Models/TextInlineChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TextInlineChange
public int AddedStart { get; set; }
public int AddedCount { get; set; }

class Chunk
private class Chunk
{
public int Hash;
public bool Modified;
Expand All @@ -25,7 +25,7 @@ public Chunk(int hash, int start, int size)
}
}

enum Edit
private enum Edit
{
None,
DeletedRight,
Expand All @@ -34,7 +34,7 @@ enum Edit
AddedLeft,
}

class EditResult
private class EditResult
{
public Edit State;
public int DeleteStart;
Expand Down Expand Up @@ -204,11 +204,10 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,

for (int i = 0; i <= half; i++)
{

for (int j = -i; j <= i; j += 2)
{
var idx = j + half;
int o, n;
int o;
if (j == -i || (j != i && forward[idx - 1] < forward[idx + 1]))
{
o = forward[idx + 1];
Expand All @@ -220,7 +219,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
rs.State = Edit.DeletedRight;
}

n = o - j;
var n = o - j;

var startX = o;
var startY = n;
Expand Down Expand Up @@ -258,7 +257,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
for (int j = -i; j <= i; j += 2)
{
var idx = j + half;
int o, n;
int o;
if (j == -i || (j != i && reverse[idx + 1] <= reverse[idx - 1]))
{
o = reverse[idx + 1] - 1;
Expand All @@ -270,7 +269,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
rs.State = Edit.AddedLeft;
}

n = o - (j + delta);
var n = o - (j + delta);

var endX = o;
var endY = n;
Expand Down Expand Up @@ -312,8 +311,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,

private static void AddChunk(List<Chunk> chunks, Dictionary<string, int> 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));
}
Expand Down
6 changes: 1 addition & 5 deletions src/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public User(string data)

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()
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void OnWorkingCopyChanged(object o, FileSystemEventArgs e)
private long _updateStashes = 0;
private long _updateTags = 0;

private object _lockSubmodule = new object();
private readonly Lock _lockSubmodule = new();
private List<string> _submodules = new List<string>();
}
}
8 changes: 4 additions & 4 deletions src/Native/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public string FindGitExecutable()
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");
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public string FindTerminal(Models.ShellOrTerminal shell)

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))
Expand All @@ -199,8 +199,8 @@ public string FindTerminal(Models.ShellOrTerminal shell)
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;
Expand Down
Loading
Loading