Skip to content

Commit e6de737

Browse files
committed
code_style: general cleanup
1 parent 35eda48 commit e6de737

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+97
-155
lines changed

src/App.axaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public static async Task<string> GetClipboardTextAsync()
301301
return await clipboard.GetTextAsync();
302302
}
303303
}
304-
return default;
304+
return null;
305305
}
306306

307307
public static string Text(string key, params object[] args)
@@ -323,8 +323,7 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
323323
icon.Height = 12;
324324
icon.Stretch = Stretch.Uniform;
325325

326-
var geo = Current?.FindResource(key) as StreamGeometry;
327-
if (geo != null)
326+
if (Current?.FindResource(key) is StreamGeometry geo)
328327
icon.Data = geo;
329328

330329
return icon;
@@ -682,8 +681,7 @@ private string FixFontFamilyName(string input)
682681
}
683682

684683
var name = sb.ToString();
685-
var idx = name.IndexOf('#');
686-
if (idx >= 0)
684+
if (name.Contains('#'))
687685
{
688686
if (!name.Equals("fonts:Inter#Inter", StringComparison.Ordinal) &&
689687
!name.Equals("fonts:SourceGit#JetBrains Mono", StringComparison.Ordinal))

src/Commands/Blame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Models.BlameData Result()
5151

5252
private void ParseLine(string line)
5353
{
54-
if (line.IndexOf('\0', StringComparison.Ordinal) >= 0)
54+
if (line.Contains('\0', StringComparison.Ordinal))
5555
{
5656
_result.IsBinary = true;
5757
_result.LineInfos.Clear();

src/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private ProcessStartInfo CreateGitStartInfo()
194194

195195
private void HandleOutput(string line, List<string> errs)
196196
{
197-
line = line ?? string.Empty;
197+
line ??= string.Empty;
198198
Log?.AppendLine(line);
199199

200200
// Lines to hide in error message.

src/Commands/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public bool Run()
3434
return succ;
3535
}
3636

37-
private string _tmpFile = string.Empty;
37+
private readonly string _tmpFile;
3838
}
3939
}

src/Commands/LFS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial class LFS
1010
[GeneratedRegex(@"^(.+)\s+([\w.]+)\s+\w+:(\d+)$")]
1111
private static partial Regex REG_LOCK();
1212

13-
class SubCmd : Command
13+
private class SubCmd : Command
1414
{
1515
public SubCmd(string repo, string args, Models.ICommandLog log)
1616
{

src/Commands/QueryCommitsForInteractiveRebase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ private void ParseParent(string data)
9090

9191
private List<Models.InteractiveCommit> _commits = [];
9292
private Models.InteractiveCommit _current = null;
93-
private string _boundary = "";
93+
private readonly string _boundary;
9494
}
9595
}

src/Commands/QueryFileSize.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public QueryFileSize(string repo, string file, string revision)
1616

1717
public long Result()
1818
{
19-
if (_result != 0)
20-
return _result;
21-
2219
var rs = ReadToEnd();
2320
if (rs.IsSuccess)
2421
{
@@ -29,7 +26,5 @@ public long Result()
2926

3027
return 0;
3128
}
32-
33-
private readonly long _result = 0;
3429
}
3530
}

src/Commands/UnstageChangesForAmend.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@ public UnstageChangesForAmend(string repo, List<Models.Change> changes)
2323
_patchBuilder.Append(c.DataForAmend.ObjectHash);
2424
_patchBuilder.Append("\t");
2525
_patchBuilder.Append(c.OriginalPath);
26-
_patchBuilder.Append("\n");
2726
}
2827
else if (c.Index == Models.ChangeState.Added)
2928
{
3029
_patchBuilder.Append("0 0000000000000000000000000000000000000000\t");
3130
_patchBuilder.Append(c.Path);
32-
_patchBuilder.Append("\n");
3331
}
3432
else if (c.Index == Models.ChangeState.Deleted)
3533
{
3634
_patchBuilder.Append("100644 ");
3735
_patchBuilder.Append(c.DataForAmend.ObjectHash);
3836
_patchBuilder.Append("\t");
3937
_patchBuilder.Append(c.Path);
40-
_patchBuilder.Append("\n");
4138
}
4239
else
4340
{
@@ -46,8 +43,9 @@ public UnstageChangesForAmend(string repo, List<Models.Change> changes)
4643
_patchBuilder.Append(c.DataForAmend.ObjectHash);
4744
_patchBuilder.Append("\t");
4845
_patchBuilder.Append(c.Path);
49-
_patchBuilder.Append("\n");
5046
}
47+
48+
_patchBuilder.Append("\n");
5149
}
5250
}
5351

src/Models/AvatarManager.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static AvatarManager Instance
3838
[GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@.+\.github\.com$")]
3939
private static partial Regex REG_GITHUB_USER_EMAIL();
4040

41-
private object _synclock = new object();
41+
private readonly Lock _synclock = new();
4242
private string _storePath;
4343
private List<IAvatarHost> _avatars = new List<IAvatarHost>();
4444
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
@@ -144,8 +144,7 @@ public Bitmap Request(string email, bool forceRefetch)
144144
if (_defaultAvatars.Contains(email))
145145
return null;
146146

147-
if (_resources.ContainsKey(email))
148-
_resources.Remove(email);
147+
_resources.Remove(email);
149148

150149
var localFile = Path.Combine(_storePath, GetEmailHash(email));
151150
if (File.Exists(localFile))
@@ -179,8 +178,7 @@ public Bitmap Request(string email, bool forceRefetch)
179178

180179
lock (_synclock)
181180
{
182-
if (!_requesting.Contains(email))
183-
_requesting.Add(email);
181+
_requesting.Add(email);
184182
}
185183

186184
return null;
@@ -200,10 +198,7 @@ public void SetFromLocal(string email, string file)
200198
if (image == null)
201199
return;
202200

203-
if (_resources.ContainsKey(email))
204-
_resources[email] = image;
205-
else
206-
_resources.Add(email, image);
201+
_resources[email] = image;
207202

208203
_requesting.Remove(email);
209204

src/Models/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum CommitSearchMethod
1919
public class Commit
2020
{
2121
// As retrieved by: git mktree </dev/null
22-
public static readonly string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
22+
public const string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
2323

2424
public static double OpacityForNotMerged
2525
{

src/Models/CommitTemplate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SourceGit.Models
66
{
7-
public partial class CommitTemplate : ObservableObject
7+
public class CommitTemplate : ObservableObject
88
{
99
public string Name
1010
{

src/Models/NumericSort.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Globalization;
32

43
namespace SourceGit.Models
54
{

src/Models/RepositorySettings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,8 @@ public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mo
287287
return false;
288288
}
289289

290-
for (int i = 0; i < HistoriesFilters.Count; i++)
290+
foreach (var filter in HistoriesFilters)
291291
{
292-
var filter = HistoriesFilters[i];
293292
if (filter.Type != type)
294293
continue;
295294

src/Models/TemplateEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private static string GetFilesSliced(Context context, int count)
402402

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

407407
return sb.ToString();
408408
}

src/Models/TextInlineChange.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class TextInlineChange
99
public int AddedStart { get; set; }
1010
public int AddedCount { get; set; }
1111

12-
class Chunk
12+
private class Chunk
1313
{
1414
public int Hash;
1515
public bool Modified;
@@ -25,7 +25,7 @@ public Chunk(int hash, int start, int size)
2525
}
2626
}
2727

28-
enum Edit
28+
private enum Edit
2929
{
3030
None,
3131
DeletedRight,
@@ -34,7 +34,7 @@ enum Edit
3434
AddedLeft,
3535
}
3636

37-
class EditResult
37+
private class EditResult
3838
{
3939
public Edit State;
4040
public int DeleteStart;
@@ -208,7 +208,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
208208
for (int j = -i; j <= i; j += 2)
209209
{
210210
var idx = j + half;
211-
int o, n;
211+
int o;
212212
if (j == -i || (j != i && forward[idx - 1] < forward[idx + 1]))
213213
{
214214
o = forward[idx + 1];
@@ -220,7 +220,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
220220
rs.State = Edit.DeletedRight;
221221
}
222222

223-
n = o - j;
223+
var n = o - j;
224224

225225
var startX = o;
226226
var startY = n;
@@ -258,7 +258,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
258258
for (int j = -i; j <= i; j += 2)
259259
{
260260
var idx = j + half;
261-
int o, n;
261+
int o;
262262
if (j == -i || (j != i && reverse[idx + 1] <= reverse[idx - 1]))
263263
{
264264
o = reverse[idx + 1] - 1;
@@ -270,7 +270,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
270270
rs.State = Edit.AddedLeft;
271271
}
272272

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

275275
var endX = o;
276276
var endY = n;
@@ -312,8 +312,7 @@ private static EditResult CheckModifiedEdit(List<Chunk> chunksOld, int startOld,
312312

313313
private static void AddChunk(List<Chunk> chunks, Dictionary<string, int> hashes, string data, int start)
314314
{
315-
int hash;
316-
if (hashes.TryGetValue(data, out hash))
315+
if (hashes.TryGetValue(data, out var hash))
317316
{
318317
chunks.Add(new Chunk(hash, start, data.Length));
319318
}

src/Models/User.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public User(string data)
2626

2727
public override bool Equals(object obj)
2828
{
29-
if (obj == null || !(obj is User))
30-
return false;
31-
32-
var other = obj as User;
33-
return Name == other.Name && Email == other.Email;
29+
return obj is User other && Name == other.Name && Email == other.Email;
3430
}
3531

3632
public override int GetHashCode()

src/Models/Watcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private void OnWorkingCopyChanged(object o, FileSystemEventArgs e)
246246
private long _updateStashes = 0;
247247
private long _updateTags = 0;
248248

249-
private object _lockSubmodule = new object();
249+
private readonly Lock _lockSubmodule = new();
250250
private List<string> _submodules = new List<string>();
251251
}
252252
}

src/Native/Windows.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public string FindGitExecutable()
128128
Microsoft.Win32.RegistryView.Registry64);
129129

130130
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
131-
if (git != null && git.GetValue("InstallPath") is string installPath)
131+
if (git?.GetValue("InstallPath") is string installPath)
132132
{
133133
return Path.Combine(installPath, "bin", "git.exe");
134134
}
@@ -181,7 +181,7 @@ public string FindTerminal(Models.ShellOrTerminal shell)
181181

182182
break;
183183
case "cmd":
184-
return "C:\\Windows\\System32\\cmd.exe";
184+
return @"C:\Windows\System32\cmd.exe";
185185
case "wt":
186186
var wtFinder = new StringBuilder("wt.exe", 512);
187187
if (PathFindOnPath(wtFinder, null))
@@ -199,8 +199,8 @@ public string FindTerminal(Models.ShellOrTerminal shell)
199199
finder.VSCode(FindVSCode);
200200
finder.VSCodeInsiders(FindVSCodeInsiders);
201201
finder.VSCodium(FindVSCodium);
202-
finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Programs\\Fleet\\Fleet.exe");
203-
finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\JetBrains\\Toolbox");
202+
finder.Fleet(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Programs\Fleet\Fleet.exe");
203+
finder.FindJetBrainsFromToolbox(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\JetBrains\Toolbox");
204204
finder.SublimeText(FindSublimeText);
205205
finder.TryAdd("Visual Studio", "vs", FindVisualStudio, GenerateCommandlineArgsForVisualStudio);
206206
return finder.Founded;

src/ViewModels/CheckoutAndFastForward.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public Models.Branch LocalBranch
99
get;
1010
}
1111

12-
public Models.Branch RemoteBrach
12+
public Models.Branch RemoteBranch
1313
{
1414
get;
1515
}
@@ -35,7 +35,7 @@ public CheckoutAndFastForward(Repository repo, Models.Branch localBranch, Models
3535
{
3636
_repo = repo;
3737
LocalBranch = localBranch;
38-
RemoteBrach = remoteBranch;
38+
RemoteBranch = remoteBranch;
3939
}
4040

4141
public override Task<bool> Sure()
@@ -54,7 +54,7 @@ public override Task<bool> Sure()
5454

5555
if (DiscardLocalChanges)
5656
{
57-
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBrach.Head, true, true);
57+
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, true, true);
5858
}
5959
else
6060
{
@@ -72,7 +72,7 @@ public override Task<bool> Sure()
7272
needPopStash = true;
7373
}
7474

75-
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBrach.Head, false, true);
75+
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, false, true);
7676
}
7777

7878
if (succ)

0 commit comments

Comments
 (0)