refactor: commits only hold the end position of subject in body

This commit is contained in:
leo 2024-06-06 20:59:09 +08:00
parent 064d04fccc
commit b4e01a8b93
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
8 changed files with 27 additions and 41 deletions

View file

@ -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<Models.Commit> _commits = new List<Models.Commit>();
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();
}
}

View file

@ -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;
}

View file

@ -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<string> Parents { get; set; } = new List<string>();
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
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();
}

View file

@ -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)

View file

@ -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<bool> Sure()
{
if (_message == Head.FullMessage)
if (_message == Head.Body)
return null;
_repo.SetWatcherEnabled(false);

View file

@ -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 };

View file

@ -93,7 +93,7 @@ namespace SourceGit.ViewModels
}
else
{
CommitMessage = commits[0].FullMessage;
CommitMessage = commits[0].Body;
}
}

View file

@ -104,7 +104,7 @@
<!-- Messages -->
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.Message}" VerticalAlignment="Top" Margin="0,4,0,0" />
<ScrollViewer Grid.Row="3" Grid.Column="1" Margin="12,5,8,0" MaxHeight="64" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<SelectableTextBlock Text="{Binding FullMessage}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" TextWrapping="Wrap"/>
<SelectableTextBlock Text="{Binding Body}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" TextWrapping="Wrap"/>
</ScrollViewer>
</Grid>
</StackPanel>