code_style: general cleanup (#1428)

This commit is contained in:
Nathan Baulch 2025-06-18 11:29:18 +10:00 committed by GitHub
parent ae46728bbc
commit d404f6dbe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 123 additions and 240 deletions

View file

@ -26,10 +26,7 @@ namespace SourceGit.Models
{
get
{
if (_instance == null)
_instance = new AvatarManager();
return _instance;
return _instance ??= new AvatarManager();
}
}

View file

@ -16,11 +16,10 @@ namespace SourceGit.Models
Deleted,
}
public class TextInlineRange
public class TextInlineRange(int p, int n)
{
public int Start { get; set; }
public int End { get; set; }
public TextInlineRange(int p, int n) { Start = p; End = p + n - 1; }
public int Start { get; set; } = p;
public int End { get; set; } = p + n - 1;
}
public class TextDiffLine
@ -556,7 +555,7 @@ namespace SourceGit.Models
}
else if (test.Type == TextDiffLineType.Added)
{
if (i < start - 1)
if (i < start - 1 || isOldSide)
{
if (revert)
{
@ -566,18 +565,7 @@ namespace SourceGit.Models
}
else
{
if (isOldSide)
{
if (revert)
{
newCount++;
oldCount++;
}
}
else
{
newCount++;
}
newCount++;
}
if (i == end - 1 && tailed)
@ -655,9 +643,7 @@ namespace SourceGit.Models
public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
}
public class NoOrEOLChange
{
}
public class NoOrEOLChange;
public class FileModeDiff
{

View file

@ -107,8 +107,7 @@ namespace SourceGit.Models
// Ignore
}
if (_customPaths == null)
_customPaths = new ExternalToolPaths();
_customPaths ??= new ExternalToolPaths();
}
public void TryAdd(string name, string icon, Func<string> finder, Func<string, string> execArgsGenerator = null)

View file

@ -8,10 +8,7 @@ namespace SourceGit.Models
{
public class IpcChannel : IDisposable
{
public bool IsFirstInstance
{
get => _isFirstInstance;
}
public bool IsFirstInstance { get; }
public event Action<string> MessageReceived;
@ -20,7 +17,7 @@ namespace SourceGit.Models
try
{
_singletonLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_isFirstInstance = true;
IsFirstInstance = true;
_server = new NamedPipeServerStream(
"SourceGitIPCChannel" + Environment.UserName,
PipeDirection.In,
@ -32,7 +29,7 @@ namespace SourceGit.Models
}
catch
{
_isFirstInstance = false;
IsFirstInstance = false;
}
}
@ -97,7 +94,6 @@ namespace SourceGit.Models
}
private FileStream _singletonLock = null;
private bool _isFirstInstance = false;
private NamedPipeServerStream _server = null;
private CancellationTokenSource _cancellationTokenSource = null;
}

View file

@ -1,6 +1,4 @@
namespace SourceGit.Models
{
public class Null
{
}
public class Null;
}

View file

@ -33,9 +33,7 @@ namespace SourceGit.Models
}
}
public class AlreadyUpToDate
{
}
public class AlreadyUpToDate;
public class SelfUpdateFailed
{

View file

@ -102,7 +102,7 @@ namespace SourceGit.Models
private int? Integer()
{
var start = _pos;
while (Peek() is char c && c >= '0' && c <= '9')
while (Peek() is >= '0' and <= '9')
{
_pos++;
}
@ -118,7 +118,7 @@ namespace SourceGit.Models
// text token start
var tok = _pos;
bool esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{
@ -129,7 +129,7 @@ namespace SourceGit.Models
{
case ESCAPE:
// allow to escape only \ and $
if (Peek() is char nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
if (Peek() is { } nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
{
esc = true;
FlushText(tok, _pos - 1);
@ -173,7 +173,7 @@ namespace SourceGit.Models
if (Next() != VARIABLE_START)
return null;
int name_start = _pos;
while (Next() is char c)
while (Next() is { } c)
{
// name character, continue advancing
if (IsNameChar(c))
@ -228,7 +228,7 @@ namespace SourceGit.Models
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{
@ -277,7 +277,7 @@ namespace SourceGit.Models
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
while (Next() is { } c)
{
if (esc)
{

View file

@ -2,27 +2,19 @@
namespace SourceGit.Models
{
public class TextInlineChange
public class TextInlineChange(int dp, int dc, int ap, int ac)
{
public int DeletedStart { get; set; }
public int DeletedCount { get; set; }
public int AddedStart { get; set; }
public int AddedCount { get; set; }
public int DeletedStart { get; set; } = dp;
public int DeletedCount { get; set; } = dc;
public int AddedStart { get; set; } = ap;
public int AddedCount { get; set; } = ac;
private class Chunk
private class Chunk(int hash, int start, int size)
{
public int Hash;
public readonly int Hash = hash;
public readonly int Start = start;
public readonly int Size = size;
public bool Modified;
public int Start;
public int Size;
public Chunk(int hash, int start, int size)
{
Hash = hash;
Modified = false;
Start = start;
Size = size;
}
}
private enum Edit
@ -43,14 +35,6 @@ namespace SourceGit.Models
public int AddEnd;
}
public TextInlineChange(int dp, int dc, int ap, int ac)
{
DeletedStart = dp;
DeletedCount = dc;
AddedStart = ap;
AddedCount = ac;
}
public static List<TextInlineChange> Compare(string oldValue, string newValue)
{
var hashes = new Dictionary<string, int>();