From 751991c8168d833c58ee840dbe69e58ad3620dd8 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 13 Dec 2024 11:00:03 +0800 Subject: [PATCH] refactor: rewrite the way reading full message of commit --- src/Commands/QueryCommitsWithFullMessage.cs | 17 ++++++++++------- src/Views/CommitMessageTextBox.axaml.cs | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Commands/QueryCommitsWithFullMessage.cs b/src/Commands/QueryCommitsWithFullMessage.cs index efa16df9..c15cdbe1 100644 --- a/src/Commands/QueryCommitsWithFullMessage.cs +++ b/src/Commands/QueryCommitsWithFullMessage.cs @@ -52,28 +52,31 @@ namespace SourceGit.Commands _current.Commit.CommitterTime = ulong.Parse(line); break; default: - if (line.Equals(_boundary, StringComparison.Ordinal)) + var boundary = rs.StdOut.IndexOf(_boundary, end + 1); + if (boundary > end) { - nextPartIdx = -1; - _current.Message = _current.Message.Trim(); + _current.Message = rs.StdOut.Substring(start, boundary - start - 1); + end = boundary + _boundary.Length; } else { - _current.Message = _current.Message + "\n" + line; + _current.Message = rs.StdOut.Substring(start); + end = rs.StdOut.Length - 2; } + nextPartIdx = -1; break; } nextPartIdx++; start = end + 1; + if (start >= rs.StdOut.Length - 1) + break; + end = rs.StdOut.IndexOf('\n', start); } - if (_current != null) - _current.Message = _current.Message.Trim(); - return _commits; } diff --git a/src/Views/CommitMessageTextBox.axaml.cs b/src/Views/CommitMessageTextBox.axaml.cs index 91f8c47e..0811d97d 100644 --- a/src/Views/CommitMessageTextBox.axaml.cs +++ b/src/Views/CommitMessageTextBox.axaml.cs @@ -95,7 +95,7 @@ namespace SourceGit.Views if (change.Property == TextProperty && _changingWay == TextChangeWay.None) { _changingWay = TextChangeWay.FromSource; - var normalized = Text.ReplaceLineEndings("\n").Trim(); + var normalized = Text.ReplaceLineEndings("\n"); var subjectEnd = normalized.IndexOf("\n\n", StringComparison.Ordinal); if (subjectEnd == -1) {