diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 5875301e..80497a90 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -6,11 +6,13 @@ namespace SourceGit.Commands { public class QueryCommits : Command { - public QueryCommits(string repo, string limits, bool needFindHead = true) + public QueryCommits(string repo, bool useTopoOrder, string limits, bool needFindHead = true) { + var order = useTopoOrder ? "--topo-order" : "--date-order"; + WorkingDirectory = repo; Context = repo; - Args = "log --date-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 {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}"; _findFirstMerged = needFindHead; } diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 53b2b3d3..413d2df9 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -79,6 +79,7 @@ M299 811 299 725 384 725 384 811 299 811M469 811 469 725 555 725 555 811 469 811M640 811 640 725 725 725 725 811 640 811M299 640 299 555 384 555 384 640 299 640M469 640 469 555 555 555 555 640 469 640M640 640 640 555 725 555 725 640 640 640M299 469 299 384 384 384 384 469 299 469M469 469 469 384 555 384 555 469 469 469M640 469 640 384 725 384 725 469 640 469M299 299 299 213 384 213 384 299 299 299M469 299 469 213 555 213 555 299 469 299M640 299 640 213 725 213 725 299 640 299Z M64 363l0 204 265 0L329 460c0-11 6-18 14-20C349 437 355 437 362 441c93 60 226 149 226 149 33 22 34 60 0 82 0 0-133 89-226 149-14 9-32-3-32-18l-1-110L64 693l0 117c0 41 34 75 75 75l746 0c41 0 75-34 75-74L960 364c0-0 0-1 0-1L64 363zM64 214l0 75 650 0-33-80c-16-38-62-69-103-69l-440 0C97 139 64 173 64 214z M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z + M841 627A43 43 0 00811 555h-299v85h196l-183 183A43 43 0 00555 896h299v-85h-196l183-183zM299 170H213v512H85l171 171 171-171H299zM725 128h-85c-18 0-34 11-40 28l-117 313h91L606 384h154l32 85h91l-117-313A43 43 0 00725 128zm-88 171 32-85h26l32 85h-90z M640 96c-158 0-288 130-288 288 0 17 3 31 5 46L105 681 96 691V928h224v-96h96v-96h96v-95c38 18 82 31 128 31 158 0 288-130 288-288s-130-288-288-288zm0 64c123 0 224 101 224 224s-101 224-224 224a235 235 0 01-109-28l-8-4H448v96h-96v96H256v96H160v-146l253-254 12-11-3-17C419 417 416 400 416 384c0-123 101-224 224-224zm64 96a64 64 0 100 128 64 64 0 100-128z M544 85c49 0 90 37 95 85h75a96 96 0 0196 89L811 267a32 32 0 01-28 32L779 299a32 32 0 01-32-28L747 267a32 32 0 00-28-32L715 235h-91a96 96 0 01-80 42H395c-33 0-62-17-80-42L224 235a32 32 0 00-32 28L192 267v576c0 16 12 30 28 32l4 0h128a32 32 0 0132 28l0 4a32 32 0 01-32 32h-128a96 96 0 01-96-89L128 843V267a96 96 0 0189-96L224 171h75a96 96 0 0195-85h150zm256 256a96 96 0 0196 89l0 7v405a96 96 0 01-89 96L800 939h-277a96 96 0 01-96-89L427 843v-405a96 96 0 0189-96L523 341h277zm-256-192H395a32 32 0 000 64h150a32 32 0 100-64z m186 532 287 0 0 287c0 11 9 20 20 20s20-9 20-20l0-287 287 0c11 0 20-9 20-20s-9-20-20-20l-287 0 0-287c0-11-9-20-20-20s-20 9-20 20l0 287-287 0c-11 0-20 9-20 20s9 20 20 20z diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 55fb04d8..d742ac78 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -543,6 +543,9 @@ Unset Hide in commit graph Filter in commit graph + Switch Order Mode + By Date (--date-order) + Topologically (--topo-order) LOCAL BRANCHES Navigate to HEAD Enable '--first-parent' Option diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 1ab661be..a1779a36 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -547,6 +547,9 @@ 不指定 在提交列表中隐藏 使用其对提交列表过滤 + 切换排序模式 + 按提交时间 (--date-order) + 按拓扑排序 (--topo-order) 本地分支 定位HEAD 启用 --first-parent 过滤选项 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 5452fef6..c821679b 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -546,6 +546,9 @@ 不指定 在提交清單中隱藏 使用其來篩選提交清單 + 切換排序方式 + 按提交时间排序 (--date-order) + 按拓扑排序 (--topo-order) 本機分支 回到 HEAD 啟用 [--first-parent] 選項 diff --git a/src/ViewModels/FileHistories.cs b/src/ViewModels/FileHistories.cs index 52ed6b01..8384d42e 100644 --- a/src/ViewModels/FileHistories.cs +++ b/src/ViewModels/FileHistories.cs @@ -64,7 +64,8 @@ namespace SourceGit.ViewModels Task.Run(() => { - var commits = new Commands.QueryCommits(_repo.FullPath, $"-n 10000 {commit} -- \"{file}\"", false).Result(); + var based = commit ?? string.Empty; + var commits = new Commands.QueryCommits(_repo.FullPath, false, $"-n 10000 {based} -- \"{file}\"", false).Result(); Dispatcher.UIThread.Invoke(() => { IsLoading = false; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 1847c79a..c87fea6b 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -106,6 +106,16 @@ namespace SourceGit.ViewModels } } + public bool EnableTopoOrderInHistories + { + get => _enableTopoOrderInHistories; + set + { + if (SetProperty(ref _enableTopoOrderInHistories, value)) + Task.Run(RefreshCommits); + } + } + public string Filter { get => _filter; @@ -852,7 +862,7 @@ namespace SourceGit.ViewModels else builder.Append(filters); - var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).Result(); + var commits = new Commands.QueryCommits(_fullpath, _enableTopoOrderInHistories, builder.ToString()).Result(); var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories); Dispatcher.UIThread.Invoke(() => @@ -2228,6 +2238,7 @@ namespace SourceGit.ViewModels 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 List _revisionFiles = new List(); diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index a6c7679b..079af6ab 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -67,7 +67,7 @@ - + + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index dec3d447..3a0e387f 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -395,5 +395,38 @@ namespace SourceGit.Views } e.Handled = true; } + + private void OnSwitchHistoriesOrderClicked(object sender, RoutedEventArgs e) + { + if (sender is Button button && DataContext is ViewModels.Repository repo) + { + var checkIcon = App.CreateMenuIcon("Icons.Check"); + + var dateOrder = new MenuItem(); + dateOrder.Header = App.Text("Repository.HistoriesOrder.ByDate"); + dateOrder.Icon = repo.EnableTopoOrderInHistories ? null : checkIcon; + dateOrder.Click += (_, ev) => + { + repo.EnableTopoOrderInHistories = false; + ev.Handled = true; + }; + + var topoOrder = new MenuItem(); + topoOrder.Header = App.Text("Repository.HistoriesOrder.Topo"); + topoOrder.Icon = repo.EnableTopoOrderInHistories ? checkIcon : null; + topoOrder.Click += (_, ev) => + { + repo.EnableTopoOrderInHistories = true; + ev.Handled = true; + }; + + var menu = new ContextMenu(); + menu.Items.Add(dateOrder); + menu.Items.Add(topoOrder); + menu.Open(button); + } + + e.Handled = true; + } } }