feature: remember --reflog, --first-parent, --topo-order and --date-order toggle states

This commit is contained in:
leo 2024-12-18 19:49:08 +08:00
parent ed3e7cbfaf
commit 37bf6dec5e
No known key found for this signature in database
4 changed files with 57 additions and 28 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -88,33 +88,45 @@ 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);
}
}
}
public string Filter
{
@ -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<Models.Commit> _searchedCommits = new List<Models.Commit>();
private Models.Commit _searchResultSelectedCommit = null;
private List<string> _revisionFiles = new List<string>();
private string _filter = string.Empty;
@ -2303,7 +2316,7 @@ namespace SourceGit.ViewModels
private List<Models.Submodule> _submodules = new List<Models.Submodule>();
private List<Models.Submodule> _visibleSubmodules = new List<Models.Submodule>();
private Models.Commit _searchResultSelectedCommit = null;
private bool _isAutoFetching = false;
private Timer _autoFetchTimer = null;
private DateTime _lastFetchTime = DateTime.MinValue;
}