From b8da3e9afd479264eaed396182c776ffb7a4ab93 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 9 Apr 2024 16:02:42 +0800 Subject: [PATCH] enhance: use `diff` command instead of `show` command to get changes of selected commit. (#56) * for merge commit, it will shows all changes compare to the first parent of the selected commit now. --- src/Commands/QueryCommitChanges.cs | 61 ------------------------------ src/ViewModels/CommitDetail.cs | 4 +- 2 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 src/Commands/QueryCommitChanges.cs diff --git a/src/Commands/QueryCommitChanges.cs b/src/Commands/QueryCommitChanges.cs deleted file mode 100644 index e7481b89..00000000 --- a/src/Commands/QueryCommitChanges.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections.Generic; -using System.Text.RegularExpressions; - -namespace SourceGit.Commands -{ - public partial class QueryCommitChanges : Command - { - [GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")] - private static partial Regex REG_FORMAT(); - - public QueryCommitChanges(string repo, string commitSHA) - { - WorkingDirectory = repo; - Context = repo; - Args = $"show --name-status {commitSHA}"; - } - - public List Result() - { - Exec(); - _changes.Sort((l, r) => l.Path.CompareTo(r.Path)); - return _changes; - } - - protected override void OnReadline(string line) - { - var match = REG_FORMAT().Match(line); - if (!match.Success) - return; - - var change = new Models.Change() { Path = match.Groups[2].Value }; - var status = match.Groups[1].Value; - - switch (status[0]) - { - case 'M': - change.Set(Models.ChangeState.Modified); - _changes.Add(change); - break; - case 'A': - change.Set(Models.ChangeState.Added); - _changes.Add(change); - break; - case 'D': - change.Set(Models.ChangeState.Deleted); - _changes.Add(change); - break; - case 'R': - change.Set(Models.ChangeState.Renamed); - _changes.Add(change); - break; - case 'C': - change.Set(Models.ChangeState.Copied); - _changes.Add(change); - break; - } - } - - private readonly List _changes = new List(); - } -} diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index f290fd4c..6fdcd93c 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -355,7 +355,9 @@ namespace SourceGit.ViewModels _cancelToken.Requested = true; _cancelToken = new Commands.Command.CancelToken(); - var cmdChanges = new Commands.QueryCommitChanges(_repo, _commit.SHA) { Cancel = _cancelToken }; + + var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0]; + var cmdChanges = new Commands.CompareRevisions(_repo, parent, _commit.SHA) { Cancel = _cancelToken }; var cmdRevisionFiles = new Commands.QueryRevisionObjects(_repo, _commit.SHA) { Cancel = _cancelToken }; Task.Run(() =>