diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 80497a90..6318f331 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -6,13 +6,11 @@ namespace SourceGit.Commands { public class QueryCommits : Command { - public QueryCommits(string repo, bool useTopoOrder, string limits, bool needFindHead = true) + public QueryCommits(string repo, string limits, bool needFindHead = true) { - var order = useTopoOrder ? "--topo-order" : "--date-order"; - WorkingDirectory = repo; Context = repo; - Args = $"log {order} --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s {limits}"; + Args = $"log --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s {limits}"; _findFirstMerged = needFindHead; } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 930b31a3..4673f66a 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -14,6 +14,24 @@ namespace SourceGit.Models set; } = string.Empty; + public bool EnableReflog + { + get; + set; + } = false; + + public bool EnableFirstParentInHistories + { + get; + set; + } = false; + + public bool EnableTopoOrderInHistories + { + get; + set; + } = false; + public bool IncludeUntrackedInLocalChanges { get; diff --git a/src/ViewModels/FileHistories.cs b/src/ViewModels/FileHistories.cs index 8384d42e..ede73cd1 100644 --- a/src/ViewModels/FileHistories.cs +++ b/src/ViewModels/FileHistories.cs @@ -65,7 +65,7 @@ namespace SourceGit.ViewModels Task.Run(() => { var based = commit ?? string.Empty; - var commits = new Commands.QueryCommits(_repo.FullPath, false, $"-n 10000 {based} -- \"{file}\"", false).Result(); + var commits = new Commands.QueryCommits(_repo.FullPath, $"--date-order -n 10000 {based} -- \"{file}\"", false).Result(); Dispatcher.UIThread.Invoke(() => { IsLoading = false; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 66b308b4..993597a5 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -88,31 +88,43 @@ namespace SourceGit.ViewModels public bool EnableReflog { - get => _enableReflog; + get => _settings.EnableReflog; set { - if (SetProperty(ref _enableReflog, value)) + if (value != _settings.EnableReflog) + { + _settings.EnableReflog = value; + OnPropertyChanged(); Task.Run(RefreshCommits); + } } } public bool EnableFirstParentInHistories { - get => _enableFirstParentInHistories; + get => _settings.EnableFirstParentInHistories; set { - if (SetProperty(ref _enableFirstParentInHistories, value)) + if (value != _settings.EnableFirstParentInHistories) + { + _settings.EnableFirstParentInHistories = value; + OnPropertyChanged(); Task.Run(RefreshCommits); + } } } public bool EnableTopoOrderInHistories { - get => _enableTopoOrderInHistories; + get => _settings.EnableTopoOrderInHistories; set { - if (SetProperty(ref _enableTopoOrderInHistories, value)) + if (value != _settings.EnableTopoOrderInHistories) + { + _settings.EnableTopoOrderInHistories = value; + OnPropertyChanged(); Task.Run(RefreshCommits); + } } } @@ -251,8 +263,7 @@ namespace SourceGit.ViewModels get => _onlySearchCommitsInCurrentBranch; set { - if (SetProperty(ref _onlySearchCommitsInCurrentBranch, value) && - !string.IsNullOrEmpty(_searchCommitFilter)) + if (SetProperty(ref _onlySearchCommitsInCurrentBranch, value) && !string.IsNullOrEmpty(_searchCommitFilter)) StartSearchCommits(); } } @@ -406,8 +417,8 @@ namespace SourceGit.ViewModels public bool IsAutoFetching { - get; - private set; + get => _isAutoFetching; + private set => SetProperty(ref _isAutoFetching, value); } public void Open() @@ -883,9 +894,15 @@ namespace SourceGit.ViewModels var builder = new StringBuilder(); builder.Append($"-{Preference.Instance.MaxHistoryCommits} "); - if (_enableReflog) + + if (_settings.EnableTopoOrderInHistories) + builder.Append("--topo-order "); + else + builder.Append("--date-order "); + + if (_settings.EnableReflog) builder.Append("--reflog "); - if (_enableFirstParentInHistories) + if (_settings.EnableFirstParentInHistories) builder.Append("--first-parent "); var filters = _settings.BuildHistoriesFilter(); @@ -894,8 +911,8 @@ namespace SourceGit.ViewModels else builder.Append(filters); - var commits = new Commands.QueryCommits(_fullpath, _enableTopoOrderInHistories, builder.ToString()).Result(); - var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories); + var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).Result(); + var graph = Models.CommitGraph.Parse(commits, _settings.EnableFirstParentInHistories); Dispatcher.UIThread.Invoke(() => { @@ -2243,7 +2260,7 @@ namespace SourceGit.ViewModels private void AutoFetchImpl(object sender) { - if (!_settings.EnableAutoFetch || IsAutoFetching) + if (!_settings.EnableAutoFetch || _isAutoFetching) return; var lockFile = Path.Combine(_gitDir, "index.lock"); @@ -2255,12 +2272,10 @@ namespace SourceGit.ViewModels if (desire > now) return; - IsAutoFetching = true; - Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching))); + Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, false, null) { RaiseError = false }.Exec(); _lastFetchTime = DateTime.Now; - IsAutoFetching = false; - Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching))); + Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); } private string _fullpath = string.Empty; @@ -2284,11 +2299,9 @@ namespace SourceGit.ViewModels private bool _isSearchCommitSuggestionOpen = false; private int _searchCommitFilterType = 2; private bool _onlySearchCommitsInCurrentBranch = false; - private bool _enableReflog = false; - private bool _enableFirstParentInHistories = false; - private bool _enableTopoOrderInHistories = false; private string _searchCommitFilter = string.Empty; private List _searchedCommits = new List(); + private Models.Commit _searchResultSelectedCommit = null; private List _revisionFiles = new List(); private string _filter = string.Empty; @@ -2303,7 +2316,7 @@ namespace SourceGit.ViewModels private List _submodules = new List(); private List _visibleSubmodules = new List(); - private Models.Commit _searchResultSelectedCommit = null; + private bool _isAutoFetching = false; private Timer _autoFetchTimer = null; private DateTime _lastFetchTime = DateTime.MinValue; }