From 1adcf4dd80c4342701978614e4b4280ab43c46ff Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 30 Oct 2024 10:10:17 +0800 Subject: [PATCH] enhance: do NOT query `gpg.ssh.allowedSignersFile` every time while getting commit's signing status Signed-off-by: leo --- src/Commands/QueryCommitSignInfo.cs | 5 ++--- src/ViewModels/CommitDetail.cs | 2 +- src/ViewModels/Repository.cs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Commands/QueryCommitSignInfo.cs b/src/Commands/QueryCommitSignInfo.cs index 5ce18319..95f6d4d6 100644 --- a/src/Commands/QueryCommitSignInfo.cs +++ b/src/Commands/QueryCommitSignInfo.cs @@ -2,13 +2,12 @@ { public class QueryCommitSignInfo : Command { - public QueryCommitSignInfo(string repo, string sha) + public QueryCommitSignInfo(string repo, string sha, bool useFakeSignersFile) { WorkingDirectory = repo; Context = repo; - var allowedSignersFile = new Config(repo).Get("gpg.ssh.allowedSignersFile"); - if (string.IsNullOrEmpty(allowedSignersFile)) + if (useFakeSignersFile) Args = $"-c gpg.ssh.allowedSignersFile=/dev/null show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}"; else Args = $"show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}"; diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index b533b24a..1600c4cd 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -498,7 +498,7 @@ namespace SourceGit.ViewModels Task.Run(() => { - var signInfo = new Commands.QueryCommitSignInfo(_repo.FullPath, _commit.SHA).Result(); + var signInfo = new Commands.QueryCommitSignInfo(_repo.FullPath, _commit.SHA, !_repo.HasAllowedSignersFile).Result(); Dispatcher.UIThread.Invoke(() => SignInfo = signInfo); }); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 9708f1e2..917833db 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -45,6 +45,11 @@ namespace SourceGit.ViewModels get => _settings; } + public bool HasAllowedSignersFile + { + get => _hasAllowedSignersFile; + } + public int SelectedViewIndex { get => _selectedViewIndex; @@ -444,6 +449,12 @@ namespace SourceGit.ViewModels public void RefreshAll() { + Task.Run(() => + { + var allowedSignersFile = new Commands.Config(_fullpath).Get("gpg.ssh.allowedSignersFile"); + _hasAllowedSignersFile = !string.IsNullOrEmpty(allowedSignersFile); + }); + Task.Run(() => { RefreshBranches(); @@ -2135,6 +2146,7 @@ namespace SourceGit.ViewModels private string _fullpath = string.Empty; private string _gitDir = string.Empty; private Models.RepositorySettings _settings = null; + private bool _hasAllowedSignersFile = false; private Models.Watcher _watcher = null; private Histories _histories = null;