diff --git a/src/Commands/QueryCommitFullMessage.cs b/src/Commands/QueryCommitFullMessage.cs new file mode 100644 index 00000000..f4be9bc5 --- /dev/null +++ b/src/Commands/QueryCommitFullMessage.cs @@ -0,0 +1,19 @@ +namespace SourceGit.Commands +{ + public class QueryCommitFullMessage : Command + { + public QueryCommitFullMessage(string repo, string sha) + { + WorkingDirectory = repo; + Context = repo; + Args = $"show --no-show-signature --pretty=format:%B -s {sha}"; + } + + public string Result() + { + var rs = ReadToEnd(); + if (rs.IsSuccess) return rs.StdOut.TrimEnd(); + return string.Empty; + } + } +} diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 17e8b09b..af7cb959 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -7,11 +7,9 @@ namespace SourceGit.Commands { public QueryCommits(string repo, string limits, bool needFindHead = true) { - _endOfBodyToken = $"----- END OF BODY {Guid.NewGuid()} -----"; - 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%B%n{_endOfBodyToken}\" " + limits; + 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; _findFirstMerged = needFindHead; } @@ -24,7 +22,6 @@ namespace SourceGit.Commands var nextPartIdx = 0; var start = 0; var end = rs.StdOut.IndexOf('\n', start); - var max = rs.StdOut.Length; while (end > 0) { var line = rs.StdOut.Substring(start, end - start); @@ -51,24 +48,17 @@ namespace SourceGit.Commands break; case 6: _current.CommitterTime = ulong.Parse(line); - start = end + 1; - end = rs.StdOut.IndexOf(_endOfBodyToken, start, StringComparison.Ordinal); - if (end > 0) - { - if (end > start) - _current.Body = rs.StdOut.Substring(start, end - start).TrimEnd(); - - start = end + _endOfBodyToken.Length + 1; - end = start >= max ? -1 : rs.StdOut.IndexOf('\n', start); - } - - nextPartIdx = 0; - continue; + break; + case 7: + _current.Subject = line; + break; default: break; } nextPartIdx++; + if (nextPartIdx == 8) nextPartIdx = 0; + start = end + 1; end = rs.StdOut.IndexOf('\n', start); } @@ -157,7 +147,7 @@ namespace SourceGit.Commands if (l.Type != r.Type) return (int)l.Type - (int)r.Type; else - return l.Name.CompareTo(r.Name); + return string.Compare(l.Name, r.Name, StringComparison.Ordinal); }); if (_current.IsMerged && !_isHeadFounded) @@ -187,7 +177,6 @@ namespace SourceGit.Commands } } - private string _endOfBodyToken = string.Empty; private List _commits = new List(); private Models.Commit _current = null; private bool _findFirstMerged = false; diff --git a/src/Commands/QuerySingleCommit.cs b/src/Commands/QuerySingleCommit.cs index 8d2087ab..4a553817 100644 --- a/src/Commands/QuerySingleCommit.cs +++ b/src/Commands/QuerySingleCommit.cs @@ -10,7 +10,7 @@ namespace SourceGit.Commands { WorkingDirectory = repo; Context = repo; - Args = $"show --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%B -s {sha}"; + Args = $"show --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s -s {sha}"; } public Models.Commit Result() @@ -32,11 +32,7 @@ namespace SourceGit.Commands commit.AuthorTime = ulong.Parse(lines[4]); commit.Committer = Models.User.FindOrAdd(lines[5]); commit.CommitterTime = ulong.Parse(lines[6]); - - StringBuilder builder = new StringBuilder(); - for (int i = 7; i < lines.Length; i++) - builder.AppendLine(lines[i]); - commit.Body = builder.ToString().TrimEnd(); + commit.Subject = lines[7]; return commit; } @@ -105,7 +101,7 @@ namespace SourceGit.Commands if (l.Type != r.Type) return (int)l.Type - (int)r.Type; else - return l.Name.CompareTo(r.Name); + return string.Compare(l.Name, r.Name, StringComparison.Ordinal); }); return isHeadOfCurrent; diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 6cf764a5..363b4b08 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -12,31 +12,13 @@ namespace SourceGit.Models public ulong AuthorTime { get; set; } = 0; public User Committer { get; set; } = User.Invalid; public ulong CommitterTime { get; set; } = 0; - public string Body { get; set; } = string.Empty; + public string Subject { 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 - { - get - { - var end = Body.IndexOf("\r\n\r\n", StringComparison.Ordinal); - if (end == -1) - { - end = Body.IndexOf("\n\n", StringComparison.Ordinal); - if (end > 0) - return Body.Substring(0, end).Replace("\n", "", StringComparison.Ordinal); - - return Body.Replace("\n", " ", StringComparison.Ordinal); - } - - return Body.Substring(0, end).Replace("\r\n", " ", StringComparison.Ordinal); - } - } - 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"); diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index c521ce5b..27a13836 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -36,6 +36,12 @@ namespace SourceGit.ViewModels } } + public string FullMessage + { + get => _fullMessage; + private set => SetProperty(ref _fullMessage, value); + } + public List Changes { get => _changes; @@ -376,6 +382,7 @@ namespace SourceGit.ViewModels private void Refresh() { _changes = null; + FullMessage = string.Empty; VisibleChanges = null; SelectedChanges = null; @@ -389,6 +396,7 @@ namespace SourceGit.ViewModels Task.Run(() => { + var fullMessage = new Commands.QueryCommitFullMessage(_repo, _commit.SHA).Result(); var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0]; var cmdChanges = new Commands.CompareRevisions(_repo, parent, _commit.SHA) { Cancel = _cancelToken }; var changes = cmdChanges.Result(); @@ -407,6 +415,7 @@ namespace SourceGit.ViewModels { Dispatcher.UIThread.Post(() => { + FullMessage = fullMessage; Changes = changes; VisibleChanges = visible; }); @@ -444,6 +453,7 @@ namespace SourceGit.ViewModels private string _repo = string.Empty; private int _activePageIndex = 0; private Models.Commit _commit = null; + private string _fullMessage = string.Empty; private List _changes = null; private List _visibleChanges = null; private List _selectedChanges = null; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 24853daf..bbb0d6be 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -429,7 +429,7 @@ namespace SourceGit.ViewModels foreach (var c in _histories.Commits) { if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Body.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Subject.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 012aab89..7c5ad88a 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace SourceGit.ViewModels @@ -21,14 +22,16 @@ namespace SourceGit.ViewModels public Reword(Repository repo, Models.Commit head) { _repo = repo; + _oldMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result(); + _message = _oldMessage; + Head = head; - Message = head.Body; View = new Views.Reword() { DataContext = this }; } public override Task Sure() { - if (_message == Head.Body) + if (string.Compare(_message, _oldMessage, StringComparison.Ordinal) == 0) return null; _repo.SetWatcherEnabled(false); @@ -44,5 +47,6 @@ namespace SourceGit.ViewModels private readonly Repository _repo = null; private string _message = string.Empty; + private string _oldMessage = string.Empty; } } diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index 9b9ccd0c..6ada9318 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -27,7 +27,8 @@ namespace SourceGit.ViewModels public Squash(Repository repo, Models.Commit head, Models.Commit parent) { _repo = repo; - _message = parent.Body; + _message = new Commands.QueryCommitFullMessage(_repo.FullPath, parent.SHA).Result(); + Head = head; Parent = parent; View = new Views.Squash() { DataContext = this }; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index ffd82bb1..16dab612 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -93,16 +93,7 @@ namespace SourceGit.ViewModels return; } - var head = new Commands.QuerySingleCommit(_repo.FullPath, currentBranch.Head).Result(); - if (head == null) - { - App.RaiseException(_repo.FullPath, "No commits to amend!!!"); - _useAmend = false; - OnPropertyChanged(); - return; - } - - CommitMessage = head.Body; + CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, currentBranch.Head).Result(); } OnPropertyChanged(nameof(IsCommitWithPushVisible)); diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index 9a43d891..9b683948 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -7,14 +7,15 @@ xmlns:v="using:SourceGit.Views" xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="SourceGit.Views.CommitBaseInfo"> + x:Class="SourceGit.Views.CommitBaseInfo" + x:Name="ThisControl"> - + @@ -30,7 +31,7 @@ - + @@ -104,7 +105,7 @@ - + diff --git a/src/Views/CommitBaseInfo.axaml.cs b/src/Views/CommitBaseInfo.axaml.cs index d835895b..eea7921c 100644 --- a/src/Views/CommitBaseInfo.axaml.cs +++ b/src/Views/CommitBaseInfo.axaml.cs @@ -14,6 +14,15 @@ namespace SourceGit.Views get => GetValue(CanNavigateProperty); set => SetValue(CanNavigateProperty, value); } + + public static readonly StyledProperty MessageProperty = + AvaloniaProperty.Register(nameof(Message), string.Empty); + + public string Message + { + get => GetValue(MessageProperty); + set => SetValue(MessageProperty, value); + } public CommitBaseInfo() { diff --git a/src/Views/CommitDetail.axaml b/src/Views/CommitDetail.axaml index 70618e8f..a46d5e54 100644 --- a/src/Views/CommitDetail.axaml +++ b/src/Views/CommitDetail.axaml @@ -19,7 +19,7 @@ - +