Skip to content

Commit b4e01a8

Browse files
committed
refactor: commits only hold the end position of subject in body
1 parent 064d04f commit b4e01a8

File tree

8 files changed

+27
-41
lines changed

8 files changed

+27
-41
lines changed

src/Commands/QueryCommits.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ protected override void OnReadline(string line)
5757
if (line.Equals(_endOfBodyToken, StringComparison.Ordinal))
5858
{
5959
_nextPartIdx = 0;
60-
_current.Message = _messageReader.ToString().Trim();
61-
_messageReader.Clear();
62-
}
63-
else if (!_isSubjectSet)
64-
{
65-
_isSubjectSet = true;
66-
_current.Subject = line;
60+
_current.Body = _bodyReader.ToString().TrimEnd();
61+
_bodyReader.Clear();
6762
}
6863
else
6964
{
70-
_messageReader.AppendLine(line);
65+
if (!_isSubjectSet)
66+
{
67+
_isSubjectSet = true;
68+
_current.SubjectLen = line.Length;
69+
}
70+
71+
_bodyReader.AppendLine(line);
7172
}
7273
return;
7374
}
@@ -191,9 +192,9 @@ private void MarkFirstMerged()
191192
private List<Models.Commit> _commits = new List<Models.Commit>();
192193
private Models.Commit _current = null;
193194
private bool _isHeadFounded = false;
194-
private readonly bool _findFirstMerged = true;
195+
private bool _findFirstMerged = true;
195196
private int _nextPartIdx = 0;
196197
private bool _isSubjectSet = false;
197-
private StringBuilder _messageReader = new StringBuilder();
198+
private StringBuilder _bodyReader = new StringBuilder();
198199
}
199200
}

src/Commands/QuerySingleCommit.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ public Models.Commit Result()
3232
commit.AuthorTime = ulong.Parse(lines[4]);
3333
commit.Committer = Models.User.FindOrAdd(lines[5]);
3434
commit.CommitterTime = ulong.Parse(lines[6]);
35-
commit.Subject = lines[7];
35+
commit.SubjectLen = lines[7].Length;
3636

37-
if (lines.Length > 8)
38-
{
39-
StringBuilder builder = new StringBuilder();
40-
for (int i = 8; i < lines.Length; i++)
41-
builder.Append(lines[i]);
42-
commit.Message = builder.ToString();
43-
}
37+
StringBuilder builder = new StringBuilder();
38+
for (int i = 7; i < lines.Length; i++)
39+
builder.AppendLine(lines[i]);
40+
commit.Body = builder.ToString().TrimEnd();
4441

4542
return commit;
4643
}

src/Models/Commit.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,22 @@ public class Commit
1212
public ulong AuthorTime { get; set; } = 0;
1313
public User Committer { get; set; } = User.Invalid;
1414
public ulong CommitterTime { get; set; } = 0;
15-
public string Subject { get; set; } = string.Empty;
16-
public string Message { get; set; } = string.Empty;
15+
public int SubjectLen { get; set; } = 0;
16+
public string Body { get; set; } = string.Empty;
1717
public List<string> Parents { get; set; } = new List<string>();
1818
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
1919
public bool HasDecorators => Decorators.Count > 0;
2020
public bool IsMerged { get; set; } = false;
2121
public Thickness Margin { get; set; } = new Thickness(0);
2222

23+
public string Subject => string.IsNullOrWhiteSpace(Body) ? string.Empty : Body.Substring(0, SubjectLen);
2324
public string AuthorTimeStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd HH:mm:ss");
2425
public string CommitterTimeStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd HH:mm:ss");
2526
public string AuthorTimeShortStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd");
2627
public string CommitterTimeShortStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd");
2728

28-
public bool IsCommitterVisible
29-
{
30-
get => Author != Committer || AuthorTime != CommitterTime;
31-
}
32-
33-
public bool IsCurrentHead
34-
{
35-
get => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
36-
}
37-
38-
public string FullMessage
39-
{
40-
get => string.IsNullOrWhiteSpace(Message) ? Subject : $"{Subject}\n\n{Message}";
41-
}
29+
public bool IsCommitterVisible => Author != Committer || AuthorTime != CommitterTime;
30+
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
4231

4332
private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
4433
}

src/ViewModels/Repository.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ public void StartSearchCommits()
419419
foreach (var c in _histories.Commits)
420420
{
421421
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
422-
|| c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
423-
|| c.Message.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
422+
|| c.Body.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
424423
|| c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
425424
|| c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
426425
|| c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)

src/ViewModels/Reword.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public Reword(Repository repo, Models.Commit head)
2222
{
2323
_repo = repo;
2424
Head = head;
25-
Message = head.FullMessage;
25+
Message = head.Body;
2626
View = new Views.Reword() { DataContext = this };
2727
}
2828

2929
public override Task<bool> Sure()
3030
{
31-
if (_message == Head.FullMessage)
31+
if (_message == Head.Body)
3232
return null;
3333

3434
_repo.SetWatcherEnabled(false);

src/ViewModels/Squash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public string Message
2727
public Squash(Repository repo, Models.Commit head, Models.Commit parent)
2828
{
2929
_repo = repo;
30-
_message = parent.FullMessage;
30+
_message = parent.Body;
3131
Head = head;
3232
Parent = parent;
3333
View = new Views.Squash() { DataContext = this };

src/ViewModels/WorkingCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public bool UseAmend
9393
}
9494
else
9595
{
96-
CommitMessage = commits[0].FullMessage;
96+
CommitMessage = commits[0].Body;
9797
}
9898
}
9999

src/Views/CommitBaseInfo.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<!-- Messages -->
105105
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.Message}" VerticalAlignment="Top" Margin="0,4,0,0" />
106106
<ScrollViewer Grid.Row="3" Grid.Column="1" Margin="12,5,8,0" MaxHeight="64" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
107-
<SelectableTextBlock Text="{Binding FullMessage}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" TextWrapping="Wrap"/>
107+
<SelectableTextBlock Text="{Binding Body}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" TextWrapping="Wrap"/>
108108
</ScrollViewer>
109109
</Grid>
110110
</StackPanel>

0 commit comments

Comments
 (0)