mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
refactor: commits only hold the end position of subject in body
This commit is contained in:
parent
064d04fccc
commit
b4e01a8b93
8 changed files with 27 additions and 41 deletions
|
@ -57,17 +57,18 @@ namespace SourceGit.Commands
|
||||||
if (line.Equals(_endOfBodyToken, StringComparison.Ordinal))
|
if (line.Equals(_endOfBodyToken, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_nextPartIdx = 0;
|
_nextPartIdx = 0;
|
||||||
_current.Message = _messageReader.ToString().Trim();
|
_current.Body = _bodyReader.ToString().TrimEnd();
|
||||||
_messageReader.Clear();
|
_bodyReader.Clear();
|
||||||
}
|
|
||||||
else if (!_isSubjectSet)
|
|
||||||
{
|
|
||||||
_isSubjectSet = true;
|
|
||||||
_current.Subject = line;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_messageReader.AppendLine(line);
|
if (!_isSubjectSet)
|
||||||
|
{
|
||||||
|
_isSubjectSet = true;
|
||||||
|
_current.SubjectLen = line.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bodyReader.AppendLine(line);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,9 +192,9 @@ namespace SourceGit.Commands
|
||||||
private List<Models.Commit> _commits = new List<Models.Commit>();
|
private List<Models.Commit> _commits = new List<Models.Commit>();
|
||||||
private Models.Commit _current = null;
|
private Models.Commit _current = null;
|
||||||
private bool _isHeadFounded = false;
|
private bool _isHeadFounded = false;
|
||||||
private readonly bool _findFirstMerged = true;
|
private bool _findFirstMerged = true;
|
||||||
private int _nextPartIdx = 0;
|
private int _nextPartIdx = 0;
|
||||||
private bool _isSubjectSet = false;
|
private bool _isSubjectSet = false;
|
||||||
private StringBuilder _messageReader = new StringBuilder();
|
private StringBuilder _bodyReader = new StringBuilder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,15 +32,12 @@ namespace SourceGit.Commands
|
||||||
commit.AuthorTime = ulong.Parse(lines[4]);
|
commit.AuthorTime = ulong.Parse(lines[4]);
|
||||||
commit.Committer = Models.User.FindOrAdd(lines[5]);
|
commit.Committer = Models.User.FindOrAdd(lines[5]);
|
||||||
commit.CommitterTime = ulong.Parse(lines[6]);
|
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 = 7; i < lines.Length; i++)
|
||||||
StringBuilder builder = new StringBuilder();
|
builder.AppendLine(lines[i]);
|
||||||
for (int i = 8; i < lines.Length; i++)
|
commit.Body = builder.ToString().TrimEnd();
|
||||||
builder.Append(lines[i]);
|
|
||||||
commit.Message = builder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,33 +12,22 @@ namespace SourceGit.Models
|
||||||
public ulong AuthorTime { get; set; } = 0;
|
public ulong AuthorTime { get; set; } = 0;
|
||||||
public User Committer { get; set; } = User.Invalid;
|
public User Committer { get; set; } = User.Invalid;
|
||||||
public ulong CommitterTime { get; set; } = 0;
|
public ulong CommitterTime { get; set; } = 0;
|
||||||
public string Subject { get; set; } = string.Empty;
|
public int SubjectLen { get; set; } = 0;
|
||||||
public string Message { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
public List<string> Parents { get; set; } = new List<string>();
|
public List<string> Parents { get; set; } = new List<string>();
|
||||||
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
|
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
|
||||||
public bool HasDecorators => Decorators.Count > 0;
|
public bool HasDecorators => Decorators.Count > 0;
|
||||||
public bool IsMerged { get; set; } = false;
|
public bool IsMerged { get; set; } = false;
|
||||||
public Thickness Margin { get; set; } = new Thickness(0);
|
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 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 CommitterTimeStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd HH:mm:ss");
|
||||||
public string AuthorTimeShortStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd");
|
public string AuthorTimeShortStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd");
|
||||||
public string CommitterTimeShortStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd");
|
public string CommitterTimeShortStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd");
|
||||||
|
|
||||||
public bool IsCommitterVisible
|
public bool IsCommitterVisible => Author != Committer || AuthorTime != CommitterTime;
|
||||||
{
|
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
|
||||||
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}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
private static readonly DateTime _utcStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,8 +419,7 @@ namespace SourceGit.ViewModels
|
||||||
foreach (var c in _histories.Commits)
|
foreach (var c in _histories.Commits)
|
||||||
{
|
{
|
||||||
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
||||||
|| c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|| c.Body.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
||||||
|| c.Message.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|
||||||
|| c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|| c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
||||||
|| c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|| c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
||||||
|| c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
|| c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
|
||||||
|
|
|
@ -22,13 +22,13 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
Head = head;
|
Head = head;
|
||||||
Message = head.FullMessage;
|
Message = head.Body;
|
||||||
View = new Views.Reword() { DataContext = this };
|
View = new Views.Reword() { DataContext = this };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
if (_message == Head.FullMessage)
|
if (_message == Head.Body)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace SourceGit.ViewModels
|
||||||
public Squash(Repository repo, Models.Commit head, Models.Commit parent)
|
public Squash(Repository repo, Models.Commit head, Models.Commit parent)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_message = parent.FullMessage;
|
_message = parent.Body;
|
||||||
Head = head;
|
Head = head;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
View = new Views.Squash() { DataContext = this };
|
View = new Views.Squash() { DataContext = this };
|
||||||
|
|
|
@ -93,7 +93,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CommitMessage = commits[0].FullMessage;
|
CommitMessage = commits[0].Body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
<!-- Messages -->
|
<!-- Messages -->
|
||||||
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.Message}" VerticalAlignment="Top" Margin="0,4,0,0" />
|
<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">
|
<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>
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
Loading…
Reference in a new issue