code_style: general cleanup (#1415)

* code_style:  general cleanup

* code_style: whitespace cleanup
This commit is contained in:
Nathan Baulch
2025-06-12 11:35:37 +10:00
committed by GitHub
parent 35eda489be
commit ffac71b15f
89 changed files with 161 additions and 243 deletions

View File

@@ -115,7 +115,7 @@ namespace SourceGit.ViewModels
break;
}
}
}
}
}
private void SetBlameData(string commitSHA)
@@ -145,7 +145,7 @@ namespace SourceGit.ViewModels
}
});
}, token);
}
}
Task.Run(() =>
{

View File

@@ -9,7 +9,7 @@ namespace SourceGit.ViewModels
get;
}
public Models.Branch RemoteBrach
public Models.Branch RemoteBranch
{
get;
}
@@ -35,7 +35,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
LocalBranch = localBranch;
RemoteBrach = remoteBranch;
RemoteBranch = remoteBranch;
}
public override Task<bool> Sure()
@@ -54,7 +54,7 @@ namespace SourceGit.ViewModels
if (DiscardLocalChanges)
{
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBrach.Head, true, true);
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, true, true);
}
else
{
@@ -72,7 +72,7 @@ namespace SourceGit.ViewModels
needPopStash = true;
}
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBrach.Head, false, true);
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, false, true);
}
if (succ)

View File

@@ -569,14 +569,14 @@ namespace SourceGit.ViewModels
if (!token.IsCancellationRequested)
Dispatcher.UIThread.Invoke(() => FullMessage = new Models.CommitFullMessage { Message = message, Inlines = inlines });
});
}, token);
Task.Run(() =>
{
var signInfo = new Commands.QueryCommitSignInfo(_repo.FullPath, _commit.SHA, !_repo.HasAllowedSignersFile).Result();
if (!token.IsCancellationRequested)
Dispatcher.UIThread.Invoke(() => SignInfo = signInfo);
});
}, token);
if (Preferences.Instance.ShowChildren)
{
@@ -587,7 +587,7 @@ namespace SourceGit.ViewModels
var children = cmd.Result();
if (!token.IsCancellationRequested)
Dispatcher.UIThread.Post(() => Children = children);
});
}, token);
}
Task.Run(() =>
@@ -617,7 +617,7 @@ namespace SourceGit.ViewModels
SelectedChanges = null;
});
}
});
}, token);
}
private Models.InlineElementCollector ParseInlinesInMessage(string message)

View File

@@ -29,8 +29,7 @@ namespace SourceGit.ViewModels
public ConfigureWorkspace()
{
Workspaces = new AvaloniaList<Workspace>();
Workspaces.AddRange(Preferences.Instance.Workspaces);
Workspaces = new AvaloniaList<Workspace>(Preferences.Instance.Workspaces);
}
public void Add()

View File

@@ -65,8 +65,7 @@ namespace SourceGit.ViewModels
public static ValidationResult ValidateTagName(string name, ValidationContext ctx)
{
var creator = ctx.ObjectInstance as CreateTag;
if (creator != null)
if (ctx.ObjectInstance is CreateTag creator)
{
var found = creator._repo.Tags.Find(x => x.Name == name);
if (found != null)

View File

@@ -244,7 +244,7 @@ namespace SourceGit.ViewModels
return;
}
}
if (firstRemoteBranch == null)
firstRemoteBranch = remoteBranch;
}
@@ -347,7 +347,7 @@ namespace SourceGit.ViewModels
log = _repo.CreateLog("Save as Patch");
var folder = picker[0];
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder.Path.ToString();
var succ = false;
for (var i = 0; i < selected.Count; i++)
{
@@ -707,7 +707,7 @@ namespace SourceGit.ViewModels
log = _repo.CreateLog("Save as Patch");
var folder = selected[0];
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString();
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder.Path.ToString();
var saveTo = GetPatchFileName(folderPath, commit);
var succ = await Task.Run(() => new Commands.FormatPatch(_repo.FullPath, commit.SHA, saveTo).Use(log).Exec());
if (succ)

View File

@@ -4,7 +4,7 @@ namespace SourceGit.ViewModels
{
public abstract class InProgressContext
{
public InProgressContext(string repo, string cmd)
protected InProgressContext(string repo, string cmd)
{
_repo = repo;
_cmd = cmd;

View File

@@ -106,7 +106,7 @@ namespace SourceGit.ViewModels
set
{
if (SetProperty(ref _selectedItem, value))
DetailContext.Commit = value != null ? value.Commit : null;
DetailContext.Commit = value?.Commit;
}
}

View File

@@ -298,15 +298,10 @@ namespace SourceGit.ViewModels
if (removeIdx == activeIdx)
{
ActivePage = Pages[removeIdx > 0 ? removeIdx - 1 : removeIdx + 1];
CloseRepositoryInTab(page);
Pages.RemoveAt(removeIdx);
}
else
{
CloseRepositoryInTab(page);
Pages.RemoveAt(removeIdx);
}
CloseRepositoryInTab(page);
Pages.RemoveAt(removeIdx);
GC.Collect();
}

View File

@@ -71,12 +71,10 @@ namespace SourceGit.ViewModels
}
else if (t is Models.Commit commit)
{
var d = commit.Decorators.Find(x =>
{
return x.Type == Models.DecoratorType.LocalBranchHead ||
x.Type == Models.DecoratorType.RemoteBranchHead ||
x.Type == Models.DecoratorType.Tag;
});
var d = commit.Decorators.Find(x => x.Type is
Models.DecoratorType.LocalBranchHead or
Models.DecoratorType.RemoteBranchHead or
Models.DecoratorType.Tag);
if (d != null)
ret.Add(d.Name);

View File

@@ -736,11 +736,8 @@ namespace SourceGit.ViewModels
{
menu.Items.Add(new MenuItem() { Header = "-" });
foreach (var url in urls)
foreach (var (name, addr) in urls)
{
var name = url.Key;
var addr = url.Value;
var item = new MenuItem();
item.Header = App.Text("Repository.Visit", name);
item.Icon = App.CreateMenuIcon("Icons.Remotes");
@@ -1342,7 +1339,7 @@ namespace SourceGit.ViewModels
{
foreach (var b in _branches)
{
if (b.IsLocal &&
if (b.IsLocal &&
b.Upstream.Equals(branch.FullName, StringComparison.Ordinal) &&
b.TrackStatus.Ahead.Count == 0)
{
@@ -2468,7 +2465,7 @@ namespace SourceGit.ViewModels
public ContextMenu CreateContextMenuForTagSortMode()
{
var mode = _settings.TagSortMode;
var changeMode = new Action<Models.TagSortMode>((m) =>
var changeMode = new Action<Models.TagSortMode>(m =>
{
if (_settings.TagSortMode != m)
{
@@ -2746,10 +2743,7 @@ namespace SourceGit.ViewModels
{
foreach (var node in nodes)
{
if (filters.TryGetValue(node.Path, out var value))
node.FilterMode = value;
else
node.FilterMode = Models.FilterMode.None;
node.FilterMode = filters.GetValueOrDefault(node.Path, Models.FilterMode.None);
if (!node.IsBranch)
UpdateBranchTreeFilterMode(node.Children, filters);
@@ -2760,10 +2754,7 @@ namespace SourceGit.ViewModels
{
foreach (var tag in _tags)
{
if (filters.TryGetValue(tag.Name, out var value))
tag.FilterMode = value;
else
tag.FilterMode = Models.FilterMode.None;
tag.FilterMode = filters.GetValueOrDefault(tag.Name, Models.FilterMode.None);
}
}
@@ -2952,7 +2943,7 @@ namespace SourceGit.ViewModels
private List<string> _matchedFilesForSearching = null;
private string _filter = string.Empty;
private object _lockRemotes = new object();
private readonly Lock _lockRemotes = new();
private List<Models.Remote> _remotes = new List<Models.Remote>();
private List<Models.Branch> _branches = new List<Models.Branch>();
private Models.Branch _currentBranch = null;

View File

@@ -156,7 +156,7 @@ namespace SourceGit.ViewModels
foreach (var service in Preferences.Instance.OpenAIServices)
AvailableOpenAIServices.Add(service.Name);
if (AvailableOpenAIServices.IndexOf(PreferredOpenAIService) == -1)
if (!AvailableOpenAIServices.Contains(PreferredOpenAIService))
PreferredOpenAIService = "---";
_cached = new Commands.Config(repo.FullPath).ListAll();

View File

@@ -128,14 +128,14 @@ namespace SourceGit.ViewModels
private RepositoryNode FindOrCreateGroupRecursive(List<RepositoryNode> collection, string path)
{
var idx = path.IndexOf('/');
if (idx < 0)
return FindOrCreateGroup(collection, path);
RepositoryNode node = null;
foreach (var name in path.Split('/'))
{
node = FindOrCreateGroup(collection, name);
collection = node.SubNodes;
}
var name = path.Substring(0, idx);
var tail = path.Substring(idx + 1);
var parent = FindOrCreateGroup(collection, name);
return FindOrCreateGroupRecursive(parent.SubNodes, tail);
return node;
}
private RepositoryNode FindOrCreateGroup(List<RepositoryNode> collection, string name)