Skip to content

refactor: remove redundant field initialization #1512

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 src/App.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Command(Action<object> action)
public bool CanExecute(object parameter) => _action != null;
public void Execute(object parameter) => _action?.Invoke(parameter);

private Action<object> _action = null;
private readonly Action<object> _action;
}

public static bool IsCheckForUpdateCommandVisible
Expand Down
10 changes: 5 additions & 5 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,10 @@ private string FixFontFamilyName(string input)
[GeneratedRegex(@"^[a-z]+\s+([a-fA-F0-9]{4,40})(\s+.*)?$")]
private static partial Regex REG_REBASE_TODO();

private Models.IpcChannel _ipcChannel = null;
private ViewModels.Launcher _launcher = null;
private ResourceDictionary _activeLocale = null;
private ResourceDictionary _themeOverrides = null;
private ResourceDictionary _fontsOverrides = null;
private Models.IpcChannel _ipcChannel;
private ViewModels.Launcher _launcher;
private ResourceDictionary _activeLocale;
private ResourceDictionary _themeOverrides;
private ResourceDictionary _fontsOverrides;
}
}
2 changes: 1 addition & 1 deletion src/Commands/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void ParseLine(string line)
private readonly StringBuilder _content = new StringBuilder();
private readonly string _dateFormat = Models.DateTimeFormat.Active.DateOnly;
private string _lastSHA = string.Empty;
private bool _needUnifyCommitSHA = false;
private bool _needUnifyCommitSHA;
private int _minSHALen = 64;
}
}
6 changes: 3 additions & 3 deletions src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class Command
{
public class Result
{
public bool IsSuccess { get; set; } = false;
public bool IsSuccess { get; set; }
public string StdOut { get; set; } = string.Empty;
public string StdErr { get; set; } = string.Empty;

Expand All @@ -27,15 +27,15 @@ public enum EditorType
}

public string Context { get; set; } = string.Empty;
public string WorkingDirectory { get; set; } = null;
public string WorkingDirectory { get; set; }
public EditorType Editor { get; set; } = EditorType.CoreEditor;
public string SSHKey { get; set; } = string.Empty;
public string Args { get; set; } = string.Empty;

// Only used in `ExecAsync` mode.
public CancellationToken CancellationToken { get; set; } = CancellationToken.None;
public bool RaiseError { get; set; } = true;
public Models.ICommandLog Log { get; set; } = null;
public Models.ICommandLog Log { get; set; }

public void Exec()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public async Task<bool> SetAsync(string key, string value, bool allowEmpty = fal
return await ExecAsync().ConfigureAwait(false);
}

private bool _isLocal = false;
private readonly bool _isLocal;
}
}
6 changes: 3 additions & 3 deletions src/Commands/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ private void ProcessInlineHighlights()
private readonly Models.DiffResult _result = new Models.DiffResult();
private readonly List<Models.TextDiffLine> _deleted = new List<Models.TextDiffLine>();
private readonly List<Models.TextDiffLine> _added = new List<Models.TextDiffLine>();
private Models.TextDiffLine _last = null;
private int _oldLine = 0;
private int _newLine = 0;
private Models.TextDiffLine _last;
private int _oldLine;
private int _newLine;
}
}
8 changes: 4 additions & 4 deletions src/Commands/QueryCommits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ private async Task MarkFirstMergedAsync()
}
}

private List<Models.Commit> _commits = new List<Models.Commit>();
private Models.Commit _current = null;
private bool _findFirstMerged = false;
private bool _isHeadFound = false;
private readonly List<Models.Commit> _commits = new List<Models.Commit>();
private readonly bool _findFirstMerged;
private Models.Commit _current;
private bool _isHeadFound;
}
}
4 changes: 2 additions & 2 deletions src/Commands/QueryCommitsForInteractiveRebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private void ParseParent(string data)
_current.Commit.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
}

private List<Models.InteractiveCommit> _commits = [];
private Models.InteractiveCommit _current = null;
private readonly List<Models.InteractiveCommit> _commits = [];
private readonly string _boundary;
private Models.InteractiveCommit _current;
}
}
10 changes: 5 additions & 5 deletions src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public static AvatarManager Instance
}
}

private static AvatarManager _instance = null;
private static AvatarManager _instance;

[GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@.+\.github\.com$")]
private static partial Regex REG_GITHUB_USER_EMAIL();

private readonly Lock _synclock = new();
private readonly List<IAvatarHost> _avatars = new List<IAvatarHost>();
private readonly Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
private readonly HashSet<string> _requesting = new HashSet<string>();
private readonly HashSet<string> _defaultAvatars = new HashSet<string>();
private string _storePath;
private List<IAvatarHost> _avatars = new List<IAvatarHost>();
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
private HashSet<string> _requesting = new HashSet<string>();
private HashSet<string> _defaultAvatars = new HashSet<string>();

public void Start()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SourceGit.Models
{
public class BlameLineInfo
{
public bool IsFirstInGroup { get; set; } = false;
public bool IsFirstInGroup { get; set; }
public string CommitSHA { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public string Time { get; set; } = string.Empty;
Expand All @@ -15,6 +15,6 @@ public class BlameData
public string File { get; set; } = string.Empty;
public List<BlameLineInfo> LineInfos { get; set; } = new List<BlameLineInfo>();
public string Content { get; set; } = string.Empty;
public bool IsBinary { get; set; } = false;
public bool IsBinary { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Models/Change.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Change
public ChangeState WorkTree { get; set; } = ChangeState.None;
public string Path { get; set; } = "";
public string OriginalPath { get; set; } = "";
public ChangeDataForAmend DataForAmend { get; set; } = null;
public ChangeDataForAmend DataForAmend { get; set; }
public ConflictReason ConflictReason { get; set; } = ConflictReason.None;

public bool IsConflicted => WorkTree == ChangeState.Conflicted;
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static double OpacityForNotMerged

public string SHA { get; set; } = string.Empty;
public User Author { get; set; } = User.Invalid;
public ulong AuthorTime { get; set; } = 0;
public ulong AuthorTime { get; set; }
public User Committer { get; set; } = User.Invalid;
public ulong CommitterTime { get; set; } = 0;
public ulong CommitterTime { get; set; }
public string Subject { get; set; } = string.Empty;
public List<string> Parents { get; set; } = new();
public List<Decorator> Decorators { get; set; } = new();
Expand All @@ -42,11 +42,11 @@ public static double OpacityForNotMerged
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
public string CommitterTimeShortStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);

public bool IsMerged { get; set; } = false;
public bool IsMerged { get; set; }
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;

public int Color { get; set; } = 0;
public int Color { get; set; }
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
public Thickness Margin { get; set; } = new(0);
Expand Down
8 changes: 4 additions & 4 deletions src/Models/CommitGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void Recycle(int idx)
_colorsQueue.Enqueue(idx);
}

private Queue<int> _colorsQueue = new Queue<int>();
private readonly Queue<int> _colorsQueue = new Queue<int>();
}

private class PathHelper
Expand Down Expand Up @@ -372,11 +372,11 @@ private void Add(double x, double y)
}
}

private double _lastY = 0;
private double _endY = 0;
private double _lastY;
private double _endY;
}

private static int s_penCount = 0;
private static int s_penCount;
private static readonly List<Color> s_defaultPenColors = [
Colors.Orange,
Colors.ForestGreen,
Expand Down
4 changes: 2 additions & 2 deletions src/Models/CommitLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace SourceGit.Models
{
public class CommitLink
{
public string Name { get; set; } = null;
public string URLPrefix { get; set; } = null;
public string Name { get; set; }
public string URLPrefix { get; set; }

public CommitLink(string name, string prefix)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Count.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SourceGit.Models
{
public class Count : IDisposable
{
public int Value { get; set; } = 0;
public int Value { get; set; }

public Count(int value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool BoolValue
private string _label = string.Empty;
private string _description = string.Empty;
private string _stringValue = string.Empty;
private bool _boolValue = false;
private bool _boolValue;
}

public class CustomAction : ObservableObject
Expand Down
2 changes: 1 addition & 1 deletion src/Models/DateTimeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static int ActiveIndex
{
get;
set;
} = 0;
}

public static DateTimeFormat Active
{
Expand Down
4 changes: 2 additions & 2 deletions src/Models/DiffOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public override string ToString()
return builder.ToString();
}

private readonly Change _workingCopyChange = null;
private readonly bool _isUnstaged = false;
private readonly Change _workingCopyChange;
private readonly bool _isUnstaged;
private readonly string _path;
private readonly string _orgPath = string.Empty;
private readonly string _extra = string.Empty;
Expand Down
46 changes: 23 additions & 23 deletions src/Models/DiffResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class TextDiffLine
{
public TextDiffLineType Type { get; set; } = TextDiffLineType.None;
public string Content { get; set; } = "";
public int OldLineNumber { get; set; } = 0;
public int NewLineNumber { get; set; } = 0;
public int OldLineNumber { get; set; }
public int NewLineNumber { get; set; }
public List<TextInlineRange> Highlights { get; set; } = new List<TextInlineRange>();
public bool NoNewLineEndOfFile { get; set; } = false;
public bool NoNewLineEndOfFile { get; set; }

public string OldLine => OldLineNumber == 0 ? string.Empty : OldLineNumber.ToString();
public string NewLine => NewLineNumber == 0 ? string.Empty : NewLineNumber.ToString();
Expand All @@ -46,12 +46,12 @@ public TextDiffLine(TextDiffLineType type, string content, int oldLine, int newL

public class TextDiffSelection
{
public int StartLine { get; set; } = 0;
public int EndLine { get; set; } = 0;
public bool HasChanges { get; set; } = false;
public bool HasLeftChanges { get; set; } = false;
public int IgnoredAdds { get; set; } = 0;
public int IgnoredDeletes { get; set; } = 0;
public int StartLine { get; set; }
public int EndLine { get; set; }
public bool HasChanges { get; set; }
public bool HasLeftChanges { get; set; }
public int IgnoredAdds { get; set; }
public int IgnoredDeletes { get; set; }

public bool IsInRange(int idx)
{
Expand All @@ -66,8 +66,8 @@ public partial class TextDiff
public Vector ScrollOffset { get; set; } = Vector.Zero;
public int MaxLineNumber = 0;

public string Repo { get; set; } = null;
public DiffOption Option { get; set; } = null;
public string Repo { get; set; }
public DiffOption Option { get; set; }

public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide)
{
Expand Down Expand Up @@ -612,17 +612,17 @@ public class LFSDiff

public class BinaryDiff
{
public long OldSize { get; set; } = 0;
public long NewSize { get; set; } = 0;
public long OldSize { get; set; }
public long NewSize { get; set; }
}

public class ImageDiff
{
public Bitmap Old { get; set; } = null;
public Bitmap New { get; set; } = null;
public Bitmap Old { get; set; }
public Bitmap New { get; set; }

public long OldFileSize { get; set; } = 0;
public long NewFileSize { get; set; } = 0;
public long OldFileSize { get; set; }
public long NewFileSize { get; set; }

public string OldImageSize => Old != null ? $"{Old.PixelSize.Width} x {Old.PixelSize.Height}" : "0 x 0";
public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
Expand All @@ -632,20 +632,20 @@ public class NoOrEOLChange;

public class SubmoduleDiff
{
public RevisionSubmodule Old { get; set; } = null;
public RevisionSubmodule New { get; set; } = null;
public RevisionSubmodule Old { get; set; }
public RevisionSubmodule New { get; set; }
}

public class DiffResult
{
public bool IsBinary { get; set; } = false;
public bool IsLFS { get; set; } = false;
public bool IsBinary { get; set; }
public bool IsLFS { get; set; }
public string OldHash { get; set; } = string.Empty;
public string NewHash { get; set; } = string.Empty;
public string OldMode { get; set; } = string.Empty;
public string NewMode { get; set; } = string.Empty;
public TextDiff TextDiff { get; set; } = null;
public LFSDiff LFSDiff { get; set; } = null;
public TextDiff TextDiff { get; set; }
public LFSDiff LFSDiff { get; set; }

public string FileModeChange
{
Expand Down
10 changes: 5 additions & 5 deletions src/Models/ExternalTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SourceGit.Models
public class ExternalTool
{
public string Name { get; private set; }
public Bitmap IconImage { get; private set; } = null;
public Bitmap IconImage { get; private set; }

public ExternalTool(string name, string icon, string execFile, Func<string, string> execArgsGenerator = null)
{
Expand Down Expand Up @@ -44,14 +44,14 @@ public void Open(string repo)
});
}

private string _execFile = string.Empty;
private Func<string, string> _execArgsGenerator = null;
private readonly string _execFile = string.Empty;
private readonly Func<string, string> _execArgsGenerator;
}

public class JetBrainsState
{
[JsonPropertyName("version")]
public int Version { get; set; } = 0;
public int Version { get; set; }
[JsonPropertyName("appVersion")]
public string AppVersion { get; set; } = string.Empty;
[JsonPropertyName("tools")]
Expand Down Expand Up @@ -184,6 +184,6 @@ public void FindJetBrainsFromToolbox(Func<string> platformFinder)
}
}

private ExternalToolPaths _customPaths = null;
private readonly ExternalToolPaths _customPaths;
}
}
6 changes: 3 additions & 3 deletions src/Models/IpcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ private async void StartServer()
}
}

private FileStream _singletonLock = null;
private NamedPipeServerStream _server = null;
private CancellationTokenSource _cancellationTokenSource = null;
private readonly FileStream _singletonLock;
private readonly NamedPipeServerStream _server;
private readonly CancellationTokenSource _cancellationTokenSource;
}
}
Loading