code_style: using avalonia's editorconfig and run dotnet format.

This commit is contained in:
leo 2024-03-31 16:54:29 +08:00
parent 3c38f681bd
commit d89a00e559
233 changed files with 1806 additions and 1254 deletions

View file

@ -13,4 +13,4 @@
Arg = a;
}
}
}
}

View file

@ -26,7 +26,8 @@ namespace SourceGit.Models
static AvatarManager()
{
_storePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SourceGit", "avatars");
if (!Directory.Exists(_storePath)) Directory.CreateDirectory(_storePath);
if (!Directory.Exists(_storePath))
Directory.CreateDirectory(_storePath);
Task.Run(() =>
{
@ -83,8 +84,10 @@ namespace SourceGit.Models
Dispatcher.UIThread.InvokeAsync(() =>
{
if (_resources.ContainsKey(md5)) _resources[md5] = img;
else _resources.Add(md5, img);
if (_resources.ContainsKey(md5))
_resources[md5] = img;
else
_resources.Add(md5, img);
NotifyResourceChanged(md5);
});
}
@ -105,16 +108,19 @@ namespace SourceGit.Models
{
if (forceRefetch)
{
if (_resources.ContainsKey(md5)) _resources.Remove(md5);
if (_resources.ContainsKey(md5))
_resources.Remove(md5);
var localFile = Path.Combine(_storePath, md5);
if (File.Exists(localFile)) File.Delete(localFile);
if (File.Exists(localFile))
File.Delete(localFile);
NotifyResourceChanged(md5);
}
else
{
if (_resources.ContainsKey(md5)) return _resources[md5];
if (_resources.TryGetValue(md5, out var value))
return value;
var localFile = Path.Combine(_storePath, md5);
if (File.Exists(localFile))
@ -134,7 +140,8 @@ namespace SourceGit.Models
lock (_synclock)
{
if (!_requesting.Contains(md5)) _requesting.Add(md5);
if (!_requesting.Contains(md5))
_requesting.Add(md5);
}
return null;
@ -154,4 +161,4 @@ namespace SourceGit.Models
private static readonly Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
private static readonly HashSet<string> _requesting = new HashSet<string>();
}
}
}

View file

@ -17,4 +17,4 @@ namespace SourceGit.Models
public string Content { get; set; } = string.Empty;
public bool IsBinary { get; set; } = false;
}
}
}

View file

@ -19,7 +19,8 @@ namespace SourceGit.Models
static Bookmarks()
{
for (int i = 0; i < Brushes.Length; i++) Supported.Add(i);
for (int i = 0; i < Brushes.Length; i++)
Supported.Add(i);
}
}
}
}

View file

@ -11,4 +11,4 @@
public string UpstreamTrackStatus { get; set; }
public string Remote { get; set; }
}
}
}

View file

@ -83,7 +83,8 @@ namespace SourceGit.Models
else
{
var remote = _remotes.Find(x => x.Name == branch.Remote);
if (remote != null) MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}", isFiltered);
if (remote != null)
MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}", isFiltered);
}
}
@ -106,7 +107,8 @@ namespace SourceGit.Models
foreach (var node in nodes)
{
var path = prefix + "/" + node.Name;
if (node.Type != BranchTreeNodeType.Branch && node.IsExpanded) _expanded.Add(path);
if (node.Type != BranchTreeNodeType.Branch && node.IsExpanded)
_expanded.Add(path);
CollectExpandedNodes(node.Children, path);
}
}
@ -134,9 +136,9 @@ namespace SourceGit.Models
for (int i = 0; i < subs.Length - 1; i++)
{
path = string.Concat(path, "/", subs[i]);
if (_maps.ContainsKey(path))
if (_maps.TryGetValue(path, out var value))
{
lastFolder = _maps[path];
lastFolder = value;
}
else if (lastFolder == null)
{
@ -188,7 +190,8 @@ namespace SourceGit.Models
}
});
foreach (var node in nodes) SortNodes(node.Children);
foreach (var node in nodes)
SortNodes(node.Children);
}
private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>();
@ -198,4 +201,4 @@ namespace SourceGit.Models
private readonly Dictionary<string, BranchTreeNode> _maps = new Dictionary<string, BranchTreeNode>();
}
}
}
}

View file

@ -8,7 +8,7 @@ namespace SourceGit.Models
public string Value { get; set; }
public string Desc { get; set; }
public static List<CRLFMode> Supported = new List<CRLFMode>() {
public static readonly List<CRLFMode> Supported = new List<CRLFMode>() {
new CRLFMode("TRUE", "true", "Commit as LF, checkout as CRLF"),
new CRLFMode("INPUT", "input", "Only convert for commit"),
new CRLFMode("FALSE", "false", "Do NOT convert"),
@ -21,4 +21,4 @@ namespace SourceGit.Models
Desc = desc;
}
}
}
}

View file

@ -32,9 +32,12 @@ namespace SourceGit.Models
{
get
{
if (Index == ChangeState.Unmerged || WorkTree == ChangeState.Unmerged) return true;
if (Index == ChangeState.Added && WorkTree == ChangeState.Added) return true;
if (Index == ChangeState.Deleted && WorkTree == ChangeState.Deleted) return true;
if (Index == ChangeState.Unmerged || WorkTree == ChangeState.Unmerged)
return true;
if (Index == ChangeState.Added && WorkTree == ChangeState.Added)
return true;
if (Index == ChangeState.Deleted && WorkTree == ChangeState.Deleted)
return true;
return false;
}
}
@ -63,8 +66,10 @@ namespace SourceGit.Models
}
}
if (Path[0] == '"') Path = Path.Substring(1, Path.Length - 2);
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"') OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2);
if (Path[0] == '"')
Path = Path.Substring(1, Path.Length - 2);
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"')
OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2);
}
}
}
}

View file

@ -38,7 +38,8 @@ namespace SourceGit.Models
public static void ParseUserAndTime(string data, ref User user, ref ulong time)
{
var userEndIdx = data.IndexOf('>', StringComparison.Ordinal);
if (userEndIdx < 0) return;
if (userEndIdx < 0)
return;
var timeEndIdx = data.IndexOf(' ', userEndIdx + 2);
user = User.FindOrAdd(data.Substring(0, userEndIdx));
@ -47,4 +48,4 @@ namespace SourceGit.Models
private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
}
}
}

View file

@ -55,11 +55,13 @@ namespace SourceGit.Models
{
Add(new Point(LastX, LastY));
Add(new Point(x, y - halfHeight));
if (isEnd) Add(new Point(x, y));
if (isEnd)
Add(new Point(x, y));
}
else if (x < LastX)
{
if (y > LastY + halfHeight) Add(new Point(LastX, LastY + halfHeight));
if (y > LastY + halfHeight)
Add(new Point(LastX, LastY + halfHeight));
Add(new Point(x, y));
}
else if (isEnd)
@ -136,7 +138,8 @@ namespace SourceGit.Models
if (commit.Parents.Count > 0)
{
major.Next = commit.Parents[0];
if (!mapUnsolved.ContainsKey(major.Next)) mapUnsolved.Add(major.Next, major);
if (!mapUnsolved.ContainsKey(major.Next))
mapUnsolved.Add(major.Next, major);
}
else
{
@ -155,7 +158,8 @@ namespace SourceGit.Models
}
else
{
if (!mapUnsolved.ContainsKey(l.Next)) mapUnsolved.Add(l.Next, l);
if (!mapUnsolved.ContainsKey(l.Next))
mapUnsolved.Add(l.Next, l);
offsetX += UNIT_WIDTH;
l.Add(offsetX, offsetY, HALF_HEIGHT);
}
@ -188,9 +192,9 @@ namespace SourceGit.Models
for (int j = 1; j < commit.Parents.Count; j++)
{
var parent = commit.Parents[j];
if (mapUnsolved.ContainsKey(parent))
if (mapUnsolved.TryGetValue(parent, out var value))
{
var l = mapUnsolved[parent];
var l = value;
var link = new Link();
link.Start = position;
@ -233,7 +237,8 @@ namespace SourceGit.Models
var path = unsolved[i];
var endY = (commits.Count - 0.5) * UNIT_HEIGHT;
if (path.Path.Points.Count == 1 && path.Path.Points[0].Y == endY) continue;
if (path.Path.Points.Count == 1 && path.Path.Points[0].Y == endY)
continue;
path.Add((i + 0.5) * UNIT_WIDTH, endY + HALF_HEIGHT, HALF_HEIGHT, true);
}
unsolved.Clear();
@ -241,4 +246,4 @@ namespace SourceGit.Models
return temp;
}
}
}
}

View file

@ -24,4 +24,4 @@ namespace SourceGit.Models
new SolidColorBrush(0xFFFFB835),
];
}
}
}

View file

@ -93,11 +93,14 @@ namespace SourceGit.Models
public override string ToString()
{
var builder = new StringBuilder();
if (!string.IsNullOrEmpty(_extra)) builder.Append($"{_extra} ");
foreach (var r in _revisions) builder.Append($"{r} ");
if (!string.IsNullOrEmpty(_extra))
builder.Append($"{_extra} ");
foreach (var r in _revisions)
builder.Append($"{r} ");
builder.Append("-- ");
if (!string.IsNullOrEmpty(_orgPath)) builder.Append($"\"{_orgPath}\" ");
if (!string.IsNullOrEmpty(_orgPath))
builder.Append($"\"{_orgPath}\" ");
builder.Append($"\"{_path}\"");
return builder.ToString();
@ -110,4 +113,4 @@ namespace SourceGit.Models
private readonly string _extra = string.Empty;
private readonly List<string> _revisions = new List<string>();
}
}
}

View file

@ -71,13 +71,15 @@ namespace SourceGit.Models
var builder = new StringBuilder();
builder.Append("diff --git a/").Append(change.Path).Append(" b/").Append(change.Path).Append('\n');
if (!revert && !isTracked) builder.Append("new file mode 100644\n");
if (!revert && !isTracked)
builder.Append("new file mode 100644\n");
builder.Append("index 00000000...").Append(fileGuid).Append('\n');
builder.Append("--- ").Append((revert || isTracked) ? $"a/{change.Path}\n" : "/dev/null\n");
builder.Append("+++ b/").Append(change.Path).Append('\n');
var additions = selection.EndLine - selection.StartLine;
if (selection.StartLine != 1) additions++;
if (selection.StartLine != 1)
additions++;
if (revert)
{
@ -86,7 +88,8 @@ namespace SourceGit.Models
for (int i = 1; i <= totalLines; i++)
{
var line = Lines[i];
if (line.Type != TextDiffLineType.Added) continue;
if (line.Type != TextDiffLineType.Added)
continue;
builder.Append(selection.IsInRange(i) ? "\n+" : "\n ").Append(line.Content);
}
}
@ -96,7 +99,8 @@ namespace SourceGit.Models
for (int i = selection.StartLine - 1; i < selection.EndLine; i++)
{
var line = Lines[i];
if (line.Type != TextDiffLineType.Added) continue;
if (line.Type != TextDiffLineType.Added)
continue;
builder.Append("\n+").Append(line.Content);
}
}
@ -125,7 +129,8 @@ namespace SourceGit.Models
for (int i = selection.EndLine; i < Lines.Count; i++)
{
var line = Lines[i];
if (line.Type == TextDiffLineType.Indicator) break;
if (line.Type == TextDiffLineType.Indicator)
break;
if (revert)
{
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Added)
@ -184,11 +189,13 @@ namespace SourceGit.Models
}
else if (line.Type == TextDiffLineType.Added)
{
if (revert) builder.Append("\n ").Append(line.Content);
if (revert)
builder.Append("\n ").Append(line.Content);
}
else if (line.Type == TextDiffLineType.Deleted)
{
if (!revert) builder.Append("\n ").Append(line.Content);
if (!revert)
builder.Append("\n ").Append(line.Content);
}
else if (line.Type == TextDiffLineType.Normal)
{
@ -247,7 +254,8 @@ namespace SourceGit.Models
for (int i = selection.EndLine; i < Lines.Count; i++)
{
var line = Lines[i];
if (line.Type == TextDiffLineType.Indicator) break;
if (line.Type == TextDiffLineType.Indicator)
break;
if (revert)
{
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Added)
@ -306,11 +314,13 @@ namespace SourceGit.Models
}
else if (line.Type == TextDiffLineType.Added)
{
if (revert) builder.Append("\n ").Append(line.Content);
if (revert)
builder.Append("\n ").Append(line.Content);
}
else if (line.Type == TextDiffLineType.Deleted)
{
if (!revert) builder.Append("\n ").Append(line.Content);
if (!revert)
builder.Append("\n ").Append(line.Content);
}
else if (line.Type == TextDiffLineType.Normal)
{
@ -390,7 +400,8 @@ namespace SourceGit.Models
for (int i = idx + 1; i < end; i++)
{
var test = Lines[i];
if (test.Type == TextDiffLineType.Indicator) break;
if (test.Type == TextDiffLineType.Indicator)
break;
if (test.Type == TextDiffLineType.Normal)
{
@ -441,7 +452,8 @@ namespace SourceGit.Models
}
}
if (oldCount == 0 && newCount == 0) return false;
if (oldCount == 0 && newCount == 0)
return false;
builder.Append($"\n@@ -{oldStart},{oldCount} +{newStart},{newCount} @@");
return true;
@ -457,7 +469,8 @@ namespace SourceGit.Models
for (int i = idx + 1; i < end; i++)
{
var test = Lines[i];
if (test.Type == TextDiffLineType.Indicator) break;
if (test.Type == TextDiffLineType.Indicator)
break;
if (test.Type == TextDiffLineType.Normal)
{
@ -530,7 +543,8 @@ namespace SourceGit.Models
}
}
if (oldCount == 0 && newCount == 0) return false;
if (oldCount == 0 && newCount == 0)
return false;
builder.Append($"\n@@ -{oldStart},{oldCount} +{newStart},{newCount} @@");
return true;
@ -569,4 +583,4 @@ namespace SourceGit.Models
public TextDiff TextDiff { get; set; } = null;
public LFSDiff LFSDiff { get; set; } = null;
}
}
}

View file

@ -11,7 +11,7 @@ namespace SourceGit.Models
public string Cmd { get; set; }
public string DiffCmd { get; set; }
public static List<ExternalMergeTools> Supported;
public static readonly List<ExternalMergeTools> Supported;
static ExternalMergeTools()
{
@ -63,4 +63,4 @@ namespace SourceGit.Models
DiffCmd = diffCmd;
}
}
}
}

View file

@ -26,11 +26,15 @@
public GitFlowBranchType GetBranchType(string name)
{
if (!IsEnabled) return GitFlowBranchType.None;
if (name.StartsWith(Feature)) return GitFlowBranchType.Feature;
if (name.StartsWith(Release)) return GitFlowBranchType.Release;
if (name.StartsWith(Hotfix)) return GitFlowBranchType.Hotfix;
if (!IsEnabled)
return GitFlowBranchType.None;
if (name.StartsWith(Feature))
return GitFlowBranchType.Feature;
if (name.StartsWith(Release))
return GitFlowBranchType.Release;
if (name.StartsWith(Hotfix))
return GitFlowBranchType.Hotfix;
return GitFlowBranchType.None;
}
}
}
}

View file

@ -5,4 +5,4 @@
public string Oid { get; set; } = string.Empty;
public long Size { get; set; } = 0;
}
}
}

View file

@ -7,7 +7,7 @@ namespace SourceGit.Models
public string Name { get; set; }
public string Key { get; set; }
public static List<Locale> Supported = new List<Locale>() {
public static readonly List<Locale> Supported = new List<Locale>() {
new Locale("English", "en_US"),
new Locale("简体中文", "zh_CN"),
};
@ -18,4 +18,4 @@ namespace SourceGit.Models
Key = key;
}
}
}
}

View file

@ -10,4 +10,4 @@
{
void OnReceiveNotification(string ctx, Notification notice);
}
}
}

View file

@ -15,4 +15,4 @@
public ObjectType Type { get; set; }
public string Path { get; set; }
}
}
}

View file

@ -24,11 +24,13 @@ namespace SourceGit.Models
public static bool IsSSH(string url)
{
if (string.IsNullOrWhiteSpace(url)) return false;
if (string.IsNullOrWhiteSpace(url))
return false;
for (int i = 1; i < URL_FORMATS.Length; i++)
{
if (URL_FORMATS[i].IsMatch(url)) return true;
if (URL_FORMATS[i].IsMatch(url))
return true;
}
return false;
@ -38,9 +40,10 @@ namespace SourceGit.Models
{
foreach (var fmt in URL_FORMATS)
{
if (fmt.IsMatch(url)) return true;
if (fmt.IsMatch(url))
return true;
}
return false;
}
}
}
}

View file

@ -27,4 +27,4 @@ namespace SourceGit.Models
{
public string SHA { get; set; }
}
}
}

View file

@ -14,4 +14,4 @@ namespace SourceGit.Models
public string TimeStr => UTC_START.AddSeconds(Time).ToString("yyyy/MM/dd HH:mm:ss");
}
}
}

View file

@ -20,9 +20,9 @@ namespace SourceGit.Models
Total++;
Samples[index].Count++;
if (_mapByCommitter.ContainsKey(committer))
if (_mapByCommitter.TryGetValue(committer, out var value))
{
_mapByCommitter[committer].Count++;
value.Count++;
}
else
{
@ -141,4 +141,4 @@ namespace SourceGit.Models
private readonly DateTime _thisWeekStart;
private readonly DateTime _thisWeekEnd;
}
}
}

View file

@ -6,4 +6,4 @@
public string SHA { get; set; }
public bool IsFiltered { get; set; }
}
}
}

View file

@ -79,10 +79,13 @@ namespace SourceGit.Models
var beginNew = posNew;
var countOld = 0;
var countNew = 0;
for (; posOld < sizeOld && chunksOld[posOld].Modified; posOld++) countOld += chunksOld[posOld].Size;
for (; posNew < sizeNew && chunksNew[posNew].Modified; posNew++) countNew += chunksNew[posNew].Size;
for (; posOld < sizeOld && chunksOld[posOld].Modified; posOld++)
countOld += chunksOld[posOld].Size;
for (; posNew < sizeNew && chunksNew[posNew].Modified; posNew++)
countNew += chunksNew[posNew].Size;
if (countOld + countNew == 0) continue;
if (countOld + countNew == 0)
continue;
var diff = new TextInlineChange(
countOld > 0 ? chunksOld[beginOld].Start : 0,
@ -120,13 +123,15 @@ namespace SourceGit.Models
var ch = text[i];
if (delims.Contains(ch))
{
if (start != i) AddChunk(chunks, hashes, text.Substring(start, i - start), start);
if (start != i)
AddChunk(chunks, hashes, text.Substring(start, i - start), start);
AddChunk(chunks, hashes, text.Substring(i, 1), i);
start = i + 1;
}
}
if (start < size) AddChunk(chunks, hashes, text.Substring(start), start);
if (start < size)
AddChunk(chunks, hashes, text.Substring(start), start);
return chunks;
}
@ -149,7 +154,8 @@ namespace SourceGit.Models
if (lenOld > 0 && lenNew > 0)
{
var rs = CheckModifiedEdit(chunksOld, startOld, endOld, chunksNew, startNew, endNew, forward, reverse);
if (rs.State == Edit.None) return;
if (rs.State == Edit.None)
return;
if (rs.State == Edit.DeletedRight && rs.DeleteStart - 1 > startOld)
{
@ -173,11 +179,13 @@ namespace SourceGit.Models
}
else if (lenOld > 0)
{
for (int i = startOld; i < endOld; i++) chunksOld[i].Modified = true;
for (int i = startOld; i < endOld; i++)
chunksOld[i].Modified = true;
}
else if (lenNew > 0)
{
for (int i = startNew; i < endNew; i++) chunksNew[i].Modified = true;
for (int i = startNew; i < endNew; i++)
chunksNew[i].Modified = true;
}
}
@ -317,4 +325,4 @@ namespace SourceGit.Models
}
}
}
}
}

View file

@ -26,7 +26,8 @@ namespace SourceGit.Models
public static void SetThemeByApp(TextMate.Installation installation)
{
if (installation == null) return;
if (installation == null)
return;
var reg = installation.RegistryOptions as RegistryOptions;
if (App.Current?.ActualThemeVariant == ThemeVariant.Dark)
@ -41,7 +42,8 @@ namespace SourceGit.Models
public static void SetGrammarByFileName(TextMate.Installation installation, string filePath)
{
if (installation == null) return;
if (installation == null)
return;
var ext = Path.GetExtension(filePath);
if (ext == ".h")
@ -58,4 +60,4 @@ namespace SourceGit.Models
GC.Collect();
}
}
}
}

View file

@ -4,15 +4,15 @@ namespace SourceGit.Models
{
public class User
{
public static User Invalid = new User();
public static Dictionary<string, User> Caches = new Dictionary<string, User>();
public static readonly User Invalid = new User();
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public override bool Equals(object obj)
{
if (obj == null || !(obj is User)) return false;
if (obj == null || !(obj is User))
return false;
var other = obj as User;
return Name == other.Name && Email == other.Email;
@ -25,9 +25,9 @@ namespace SourceGit.Models
public static User FindOrAdd(string data)
{
if (Caches.ContainsKey(data))
if (_caches.TryGetValue(data, out var value))
{
return Caches[data];
return value;
}
else
{
@ -36,9 +36,11 @@ namespace SourceGit.Models
var email = data.Substring(nameEndIdx + 1);
User user = new User() { Name = name, Email = email };
Caches.Add(data, user);
_caches.Add(data, user);
return user;
}
}
private static Dictionary<string, User> _caches = new Dictionary<string, User>();
}
}
}

View file

@ -23,7 +23,8 @@ namespace SourceGit.Models
get
{
var match = REG_VERSION_TAG().Match(TagName);
if (!match.Success) return false;
if (!match.Success)
return false;
var major = int.Parse(match.Groups[1].Value);
var minor = int.Parse(match.Groups[2].Value);
@ -34,4 +35,4 @@ namespace SourceGit.Models
}
public class AlreadyUpToDate { }
}
}

View file

@ -53,7 +53,8 @@ namespace SourceGit.Models
{
if (enabled)
{
if (_lockCount > 0) _lockCount--;
if (_lockCount > 0)
_lockCount--;
}
else
{
@ -95,7 +96,8 @@ namespace SourceGit.Models
private void Tick(object sender)
{
if (_lockCount > 0) return;
if (_lockCount > 0)
return;
var now = DateTime.Now.ToFileTime();
if (_updateBranch > 0 && now > _updateBranch)
@ -153,7 +155,8 @@ namespace SourceGit.Models
private void OnRepositoryChanged(object o, FileSystemEventArgs e)
{
if (string.IsNullOrEmpty(e.Name)) return;
if (string.IsNullOrEmpty(e.Name))
return;
var name = e.Name.Replace("\\", "/");
if (name.StartsWith("modules", StringComparison.Ordinal))
@ -183,10 +186,12 @@ namespace SourceGit.Models
private void OnWorkingCopyChanged(object o, FileSystemEventArgs e)
{
if (string.IsNullOrEmpty(e.Name)) return;
if (string.IsNullOrEmpty(e.Name))
return;
var name = e.Name.Replace("\\", "/");
if (name == ".git" || name.StartsWith(".git/", StringComparison.Ordinal)) return;
if (name == ".git" || name.StartsWith(".git/", StringComparison.Ordinal))
return;
_updateWC = DateTime.Now.AddSeconds(1).ToFileTime();
}
@ -201,4 +206,4 @@ namespace SourceGit.Models
private long _updateStashes = 0;
private long _updateTags = 0;
}
}
}