code_style: general cleanup (#1415)

* code_style:  general cleanup

* code_style: whitespace cleanup
This commit is contained in:
Nathan Baulch 2025-06-12 11:35:37 +10:00 committed by GitHub
parent 35eda489be
commit ffac71b15f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
89 changed files with 161 additions and 243 deletions

View file

@ -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<IAvatarHost> _avatars = new List<IAvatarHost>();
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
@ -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);

View file

@ -19,7 +19,7 @@ namespace SourceGit.Models
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
{

View file

@ -4,7 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.Models
{
public partial class CommitTemplate : ObservableObject
public class CommitTemplate : ObservableObject
{
public string Name
{

View file

@ -1,5 +1,4 @@
using System;
using System.Globalization;
namespace SourceGit.Models
{

View file

@ -287,9 +287,8 @@ namespace SourceGit.Models
return false;
}
for (int i = 0; i < HistoriesFilters.Count; i++)
foreach (var filter in HistoriesFilters)
{
var filter = HistoriesFilters[i];
if (filter.Type != type)
continue;

View file

@ -402,7 +402,7 @@ namespace SourceGit.Models
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();
}

View file

@ -9,7 +9,7 @@ namespace SourceGit.Models
public int AddedStart { get; set; }
public int AddedCount { get; set; }
class Chunk
private class Chunk
{
public int Hash;
public bool Modified;
@ -25,7 +25,7 @@ namespace SourceGit.Models
}
}
enum Edit
private enum Edit
{
None,
DeletedRight,
@ -34,7 +34,7 @@ namespace SourceGit.Models
AddedLeft,
}
class EditResult
private class EditResult
{
public Edit State;
public int DeleteStart;
@ -204,11 +204,10 @@ namespace SourceGit.Models
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];
@ -220,7 +219,7 @@ namespace SourceGit.Models
rs.State = Edit.DeletedRight;
}
n = o - j;
var n = o - j;
var startX = o;
var startY = n;
@ -258,7 +257,7 @@ namespace SourceGit.Models
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;
@ -270,7 +269,7 @@ namespace SourceGit.Models
rs.State = Edit.AddedLeft;
}
n = o - (j + delta);
var n = o - (j + delta);
var endX = o;
var endY = n;
@ -312,8 +311,7 @@ namespace SourceGit.Models
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));
}

View file

@ -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()

View file

@ -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<string> _submodules = new List<string>();
}
}