Truncate diff

This commit is contained in:
Thomas Miceli 2023-03-18 23:53:05 +01:00
parent bd64922554
commit b505f7147e
No known key found for this signature in database
GPG key ID: D86C6F6390AF050F
2 changed files with 12 additions and 1 deletions

View file

@ -58,6 +58,7 @@ func parseLog(out io.Reader) []*Commit {
var currentCommit *Commit
var currentFile *File
var isContent bool
var bytesRead = 0
for scanner.Scan() {
// new commit found
@ -103,6 +104,7 @@ func parseLog(out io.Reader) []*Commit {
// create a new file
isContent = false
bytesRead = 0
currentFile = &File{}
filenameRegex := regexp.MustCompile(`^diff --git a/(.+) b/(.+)$`)
matches := filenameRegex.FindStringSubmatch(string(line))
@ -131,6 +133,13 @@ func parseLog(out io.Reader) []*Commit {
if isContent {
currentFile.Content += string(line) + "\n"
bytesRead += len(line)
if bytesRead > 2<<18 {
currentFile.Truncated = true
currentFile.Content = ""
isContent = false
}
}
scanner.Scan()

View file

@ -39,7 +39,9 @@
</p>
</div>
<div class="code overflow-auto">
{{ if and (eq $file.Content "") (ne $file.OldFilename "") }}
{{ if $file.Truncated }}
<p class="m-2 ml-4 text-xs">Diff truncated because its too large to be shown</p>
{{ else if and (eq $file.Content "") (ne $file.OldFilename "") }}
<p class="m-2 ml-4 text-xs">File renamed without changes</p>
{{ else if eq $file.Content "" }}
<p class="m-2 ml-4 text-xs">Empty file</p>