Skip to content

Commit 37bf6de

Browse files
committed
feature: remember --reflog, --first-parent, --topo-order and --date-order toggle states
1 parent ed3e7cb commit 37bf6de

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

src/Commands/QueryCommits.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ namespace SourceGit.Commands
66
{
77
public class QueryCommits : Command
88
{
9-
public QueryCommits(string repo, bool useTopoOrder, string limits, bool needFindHead = true)
9+
public QueryCommits(string repo, string limits, bool needFindHead = true)
1010
{
11-
var order = useTopoOrder ? "--topo-order" : "--date-order";
12-
1311
WorkingDirectory = repo;
1412
Context = repo;
15-
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}";
13+
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}";
1614
_findFirstMerged = needFindHead;
1715
}
1816

src/Models/RepositorySettings.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ public string DefaultRemote
1414
set;
1515
} = string.Empty;
1616

17+
public bool EnableReflog
18+
{
19+
get;
20+
set;
21+
} = false;
22+
23+
public bool EnableFirstParentInHistories
24+
{
25+
get;
26+
set;
27+
} = false;
28+
29+
public bool EnableTopoOrderInHistories
30+
{
31+
get;
32+
set;
33+
} = false;
34+
1735
public bool IncludeUntrackedInLocalChanges
1836
{
1937
get;

src/ViewModels/FileHistories.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public FileHistories(Repository repo, string file, string commit = null)
6565
Task.Run(() =>
6666
{
6767
var based = commit ?? string.Empty;
68-
var commits = new Commands.QueryCommits(_repo.FullPath, false, $"-n 10000 {based} -- \"{file}\"", false).Result();
68+
var commits = new Commands.QueryCommits(_repo.FullPath, $"--date-order -n 10000 {based} -- \"{file}\"", false).Result();
6969
Dispatcher.UIThread.Invoke(() =>
7070
{
7171
IsLoading = false;

src/ViewModels/Repository.cs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,43 @@ public object SelectedView
8888

8989
public bool EnableReflog
9090
{
91-
get => _enableReflog;
91+
get => _settings.EnableReflog;
9292
set
9393
{
94-
if (SetProperty(ref _enableReflog, value))
94+
if (value != _settings.EnableReflog)
95+
{
96+
_settings.EnableReflog = value;
97+
OnPropertyChanged();
9598
Task.Run(RefreshCommits);
99+
}
96100
}
97101
}
98102

99103
public bool EnableFirstParentInHistories
100104
{
101-
get => _enableFirstParentInHistories;
105+
get => _settings.EnableFirstParentInHistories;
102106
set
103107
{
104-
if (SetProperty(ref _enableFirstParentInHistories, value))
108+
if (value != _settings.EnableFirstParentInHistories)
109+
{
110+
_settings.EnableFirstParentInHistories = value;
111+
OnPropertyChanged();
105112
Task.Run(RefreshCommits);
113+
}
106114
}
107115
}
108116

109117
public bool EnableTopoOrderInHistories
110118
{
111-
get => _enableTopoOrderInHistories;
119+
get => _settings.EnableTopoOrderInHistories;
112120
set
113121
{
114-
if (SetProperty(ref _enableTopoOrderInHistories, value))
122+
if (value != _settings.EnableTopoOrderInHistories)
123+
{
124+
_settings.EnableTopoOrderInHistories = value;
125+
OnPropertyChanged();
115126
Task.Run(RefreshCommits);
127+
}
116128
}
117129
}
118130

@@ -251,8 +263,7 @@ public bool OnlySearchCommitsInCurrentBranch
251263
get => _onlySearchCommitsInCurrentBranch;
252264
set
253265
{
254-
if (SetProperty(ref _onlySearchCommitsInCurrentBranch, value) &&
255-
!string.IsNullOrEmpty(_searchCommitFilter))
266+
if (SetProperty(ref _onlySearchCommitsInCurrentBranch, value) && !string.IsNullOrEmpty(_searchCommitFilter))
256267
StartSearchCommits();
257268
}
258269
}
@@ -406,8 +417,8 @@ public Models.Commit SearchResultSelectedCommit
406417

407418
public bool IsAutoFetching
408419
{
409-
get;
410-
private set;
420+
get => _isAutoFetching;
421+
private set => SetProperty(ref _isAutoFetching, value);
411422
}
412423

413424
public void Open()
@@ -883,9 +894,15 @@ public void RefreshCommits()
883894

884895
var builder = new StringBuilder();
885896
builder.Append($"-{Preference.Instance.MaxHistoryCommits} ");
886-
if (_enableReflog)
897+
898+
if (_settings.EnableTopoOrderInHistories)
899+
builder.Append("--topo-order ");
900+
else
901+
builder.Append("--date-order ");
902+
903+
if (_settings.EnableReflog)
887904
builder.Append("--reflog ");
888-
if (_enableFirstParentInHistories)
905+
if (_settings.EnableFirstParentInHistories)
889906
builder.Append("--first-parent ");
890907

891908
var filters = _settings.BuildHistoriesFilter();
@@ -894,8 +911,8 @@ public void RefreshCommits()
894911
else
895912
builder.Append(filters);
896913

897-
var commits = new Commands.QueryCommits(_fullpath, _enableTopoOrderInHistories, builder.ToString()).Result();
898-
var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories);
914+
var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).Result();
915+
var graph = Models.CommitGraph.Parse(commits, _settings.EnableFirstParentInHistories);
899916

900917
Dispatcher.UIThread.Invoke(() =>
901918
{
@@ -2243,7 +2260,7 @@ private void UpdateCurrentRevisionFilesForSearchSuggestion()
22432260

22442261
private void AutoFetchImpl(object sender)
22452262
{
2246-
if (!_settings.EnableAutoFetch || IsAutoFetching)
2263+
if (!_settings.EnableAutoFetch || _isAutoFetching)
22472264
return;
22482265

22492266
var lockFile = Path.Combine(_gitDir, "index.lock");
@@ -2255,12 +2272,10 @@ private void AutoFetchImpl(object sender)
22552272
if (desire > now)
22562273
return;
22572274

2258-
IsAutoFetching = true;
2259-
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));
2275+
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
22602276
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, false, null) { RaiseError = false }.Exec();
22612277
_lastFetchTime = DateTime.Now;
2262-
IsAutoFetching = false;
2263-
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));
2278+
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false);
22642279
}
22652280

22662281
private string _fullpath = string.Empty;
@@ -2284,11 +2299,9 @@ private void AutoFetchImpl(object sender)
22842299
private bool _isSearchCommitSuggestionOpen = false;
22852300
private int _searchCommitFilterType = 2;
22862301
private bool _onlySearchCommitsInCurrentBranch = false;
2287-
private bool _enableReflog = false;
2288-
private bool _enableFirstParentInHistories = false;
2289-
private bool _enableTopoOrderInHistories = false;
22902302
private string _searchCommitFilter = string.Empty;
22912303
private List<Models.Commit> _searchedCommits = new List<Models.Commit>();
2304+
private Models.Commit _searchResultSelectedCommit = null;
22922305
private List<string> _revisionFiles = new List<string>();
22932306

22942307
private string _filter = string.Empty;
@@ -2303,7 +2316,7 @@ private void AutoFetchImpl(object sender)
23032316
private List<Models.Submodule> _submodules = new List<Models.Submodule>();
23042317
private List<Models.Submodule> _visibleSubmodules = new List<Models.Submodule>();
23052318

2306-
private Models.Commit _searchResultSelectedCommit = null;
2319+
private bool _isAutoFetching = false;
23072320
private Timer _autoFetchTimer = null;
23082321
private DateTime _lastFetchTime = DateTime.MinValue;
23092322
}

0 commit comments

Comments
 (0)