diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 295bb950..e60331ee 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -57,17 +57,18 @@ namespace SourceGit.Commands if (line.Equals(_endOfBodyToken, StringComparison.Ordinal)) { _nextPartIdx = 0; - _current.Message = _messageReader.ToString().Trim(); - _messageReader.Clear(); - } - else if (!_isSubjectSet) - { - _isSubjectSet = true; - _current.Subject = line; + _current.Body = _bodyReader.ToString().TrimEnd(); + _bodyReader.Clear(); } else { - _messageReader.AppendLine(line); + if (!_isSubjectSet) + { + _isSubjectSet = true; + _current.SubjectLen = line.Length; + } + + _bodyReader.AppendLine(line); } return; } @@ -191,9 +192,9 @@ namespace SourceGit.Commands private List _commits = new List(); private Models.Commit _current = null; private bool _isHeadFounded = false; - private readonly bool _findFirstMerged = true; + private bool _findFirstMerged = true; private int _nextPartIdx = 0; private bool _isSubjectSet = false; - private StringBuilder _messageReader = new StringBuilder(); + private StringBuilder _bodyReader = new StringBuilder(); } } diff --git a/src/Commands/QuerySingleCommit.cs b/src/Commands/QuerySingleCommit.cs index 7d443c4e..a5209908 100644 --- a/src/Commands/QuerySingleCommit.cs +++ b/src/Commands/QuerySingleCommit.cs @@ -32,15 +32,12 @@ namespace SourceGit.Commands commit.AuthorTime = ulong.Parse(lines[4]); commit.Committer = Models.User.FindOrAdd(lines[5]); commit.CommitterTime = ulong.Parse(lines[6]); - commit.Subject = lines[7]; + commit.SubjectLen = lines[7].Length; - if (lines.Length > 8) - { - StringBuilder builder = new StringBuilder(); - for (int i = 8; i < lines.Length; i++) - builder.Append(lines[i]); - commit.Message = builder.ToString(); - } + StringBuilder builder = new StringBuilder(); + for (int i = 7; i < lines.Length; i++) + builder.AppendLine(lines[i]); + commit.Body = builder.ToString().TrimEnd(); return commit; } diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 4a7313f0..81c48b79 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -12,33 +12,22 @@ namespace SourceGit.Models public ulong AuthorTime { get; set; } = 0; public User Committer { get; set; } = User.Invalid; public ulong CommitterTime { get; set; } = 0; - public string Subject { get; set; } = string.Empty; - public string Message { get; set; } = string.Empty; + public int SubjectLen { get; set; } = 0; + public string Body { get; set; } = string.Empty; public List Parents { get; set; } = new List(); public List Decorators { get; set; } = new List(); public bool HasDecorators => Decorators.Count > 0; public bool IsMerged { get; set; } = false; public Thickness Margin { get; set; } = new Thickness(0); + public string Subject => string.IsNullOrWhiteSpace(Body) ? string.Empty : Body.Substring(0, SubjectLen); public string AuthorTimeStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd HH:mm:ss"); public string CommitterTimeStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd HH:mm:ss"); public string AuthorTimeShortStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd"); public string CommitterTimeShortStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd"); - public bool IsCommitterVisible - { - get => Author != Committer || AuthorTime != CommitterTime; - } - - public bool IsCurrentHead - { - get => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null; - } - - public string FullMessage - { - get => string.IsNullOrWhiteSpace(Message) ? Subject : $"{Subject}\n\n{Message}"; - } + public bool IsCommitterVisible => Author != Committer || AuthorTime != CommitterTime; + public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null; private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(); } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 898d40c5..af197759 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -419,8 +419,7 @@ namespace SourceGit.ViewModels foreach (var c in _histories.Commits) { if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Message.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Body.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) || c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) || c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) || c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) diff --git a/src/ViewModels/Reword.cs b/src/ViewModels/Reword.cs index dc67a095..012aab89 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -22,13 +22,13 @@ namespace SourceGit.ViewModels { _repo = repo; Head = head; - Message = head.FullMessage; + Message = head.Body; View = new Views.Reword() { DataContext = this }; } public override Task Sure() { - if (_message == Head.FullMessage) + if (_message == Head.Body) return null; _repo.SetWatcherEnabled(false); diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index bcf6e101..9b9ccd0c 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -27,7 +27,7 @@ namespace SourceGit.ViewModels public Squash(Repository repo, Models.Commit head, Models.Commit parent) { _repo = repo; - _message = parent.FullMessage; + _message = parent.Body; Head = head; Parent = parent; View = new Views.Squash() { DataContext = this }; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 91e07b7f..9decf79c 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -93,7 +93,7 @@ namespace SourceGit.ViewModels } else { - CommitMessage = commits[0].FullMessage; + CommitMessage = commits[0].Body; } } diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index f1a3a0b7..9a43d891 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -104,7 +104,7 @@ - +