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 @@ -713,10 +713,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 @@ -92,7 +92,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;
}
}
2 changes: 1 addition & 1 deletion 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 Down
2 changes: 1 addition & 1 deletion src/Commands/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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 @@ -275,8 +275,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 @@ -147,9 +147,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 _isHeadFounded = false;
private readonly List<Models.Commit> _commits = new List<Models.Commit>();
private readonly bool _findFirstMerged;
private Models.Commit _current;
private bool _isHeadFounded;
}
}
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(separator: ' ', options: 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
2 changes: 1 addition & 1 deletion src/Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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;

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
4 changes: 2 additions & 2 deletions src/Models/DiffOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,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
16 changes: 8 additions & 8 deletions src/Models/DiffResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ 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;

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 Down
8 changes: 4 additions & 4 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,8 +44,8 @@ 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
Expand Down Expand Up @@ -175,6 +175,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;
}
}
2 changes: 1 addition & 1 deletion src/Models/IssueTrackerRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ public void Matches(InlineElementCollector outs, string message)
private string _name;
private string _regexString;
private string _urlTemplate;
private Regex _regex = null;
private Regex _regex;
}
}
2 changes: 1 addition & 1 deletion src/Models/LFSObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class LFSObject
private static partial Regex REG_FORMAT();

public string Oid { get; set; } = string.Empty;
public long Size { get; set; } = 0;
public long Size { get; set; }

public static LFSObject Parse(string content)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Models/OpenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ private void OnReceive(string text)
[GeneratedRegex(@"<(think|thought|thinking|thought_chain)>.*?</\1>", RegexOptions.Singleline)]
private static partial Regex REG_COT();

private Action<string> _onUpdate = null;
private StringBuilder _thinkTail = new StringBuilder();
private HashSet<string> _thinkTags = ["think", "thought", "thinking", "thought_chain"];
private bool _hasTrimmedStart = false;
private readonly Action<string> _onUpdate;
private readonly StringBuilder _thinkTail = new StringBuilder();
private readonly HashSet<string> _thinkTags = ["think", "thought", "thinking", "thought_chain"];
private bool _hasTrimmedStart;
}

public class OpenAIService : ObservableObject
Expand Down
12 changes: 6 additions & 6 deletions src/Models/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class StatisticsAuthor(User user, int count)

public class StatisticsReport
{
public int Total { get; set; } = 0;
public int Total { get; set; }
public List<StatisticsAuthor> Authors { get; set; } = new();
public List<ISeries> Series { get; set; } = new();
public List<Axis> XAxes { get; set; } = new();
Expand Down Expand Up @@ -171,11 +171,11 @@ public void ChangeAuthor(StatisticsAuthor author)
}

private static readonly string[] WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
private StatisticsMode _mode;
private Dictionary<User, int> _mapUsers = new();
private Dictionary<DateTime, int> _mapSamples = new();
private Dictionary<User, Dictionary<DateTime, int>> _mapUserSamples = new();
private StatisticsAuthor _selectedAuthor = null;
private readonly StatisticsMode _mode;
private readonly Dictionary<User, int> _mapUsers = new();
private readonly Dictionary<DateTime, int> _mapSamples = new();
private readonly Dictionary<User, Dictionary<DateTime, int>> _mapUserSamples = new();
private StatisticsAuthor _selectedAuthor;
private uint _fillColor = 255;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/TemplateEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private static string EvalVariable(Context context, RegexVariable variable)
return variable.regex.Replace(str, variable.replacement);
}

private int _pos = 0;
private int _pos;
private char[] _chars = [];
private readonly List<object> _tokens = [];

Expand Down
20 changes: 10 additions & 10 deletions src/Models/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ private void HandleWorkingCopyFileChanged(string name)
_updateWC = DateTime.Now.AddSeconds(1).ToFileTime();
}

private readonly IRepository _repo = null;
private List<FileSystemWatcher> _watchers = [];
private Timer _timer = null;
private int _lockCount = 0;
private long _updateWC = 0;
private long _updateBranch = 0;
private long _updateSubmodules = 0;
private long _updateStashes = 0;
private long _updateTags = 0;
private readonly IRepository _repo;
private readonly List<FileSystemWatcher> _watchers = [];
private Timer _timer;
private int _lockCount;
private long _updateWC;
private long _updateBranch;
private long _updateSubmodules;
private long _updateStashes;
private long _updateTags;

private readonly Lock _lockSubmodule = new();
private List<string> _submodules = new List<string>();
private readonly List<string> _submodules = new List<string>();
}
}
2 changes: 1 addition & 1 deletion src/Models/Worktree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public string Name
}
}

private bool _isLocked = false;
private bool _isLocked;
}
}
4 changes: 2 additions & 2 deletions src/Native/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ private static void UpdateGitVersion()
[GeneratedRegex(@"^git version[\s\w]*(\d+)\.(\d+)[\.\-](\d+).*$")]
private static partial Regex REG_GIT_VERSION();

private static IBackend _backend = null;
private static readonly IBackend _backend;
private static string _gitExecutable = string.Empty;
private static bool _enableSystemWindowFrame = false;
private static bool _enableSystemWindowFrame;
}
}
12 changes: 6 additions & 6 deletions src/ViewModels/AIAssistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ private void Gen()
}, _cancel.Token);
}

private readonly Repository _repo = null;
private Models.OpenAIService _service = null;
private List<Models.Change> _changes = null;
private Action<string> _onApply = null;
private CancellationTokenSource _cancel = null;
private bool _isGenerating = false;
private readonly Repository _repo;
private readonly Models.OpenAIService _service;
private readonly List<Models.Change> _changes;
private readonly Action<string> _onApply;
private CancellationTokenSource _cancel;
private bool _isGenerating;
private string _text = string.Empty;
}
}
4 changes: 2 additions & 2 deletions src/ViewModels/AddRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public override async Task<bool> Sure()
return succ;
}

private readonly Repository _repo = null;
private readonly Repository _repo;
private string _name = string.Empty;
private string _url = string.Empty;
private bool _useSSH = false;
private bool _useSSH;
private string _sshkey = string.Empty;
}
}
Loading