mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
enhance: only store subject in commits.
It has several advantages: * reduce the memory costed by histories * higher performance while parsing commits * no need to calculate subject every time, which is invoked most frequently to render histories
This commit is contained in:
parent
6426da3289
commit
9e45a8a77d
12 changed files with 67 additions and 65 deletions
19
src/Commands/QueryCommitFullMessage.cs
Normal file
19
src/Commands/QueryCommitFullMessage.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Models.Commit> _commits = new List<Models.Commit>();
|
||||
private Models.Commit _current = null;
|
||||
private bool _findFirstMerged = false;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue