From b505f7147e4452090a61950ec92ac877a3ecaca3 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Sat, 18 Mar 2023 23:53:05 +0100 Subject: [PATCH] Truncate diff --- internal/git/output_parser.go | 9 +++++++++ templates/pages/revisions.html | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/git/output_parser.go b/internal/git/output_parser.go index c7d02a6..3b75cec 100644 --- a/internal/git/output_parser.go +++ b/internal/git/output_parser.go @@ -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() diff --git a/templates/pages/revisions.html b/templates/pages/revisions.html index d1eef7c..40fd01d 100644 --- a/templates/pages/revisions.html +++ b/templates/pages/revisions.html @@ -39,7 +39,9 @@

- {{ if and (eq $file.Content "") (ne $file.OldFilename "") }} + {{ if $file.Truncated }} +

Diff truncated because its too large to be shown

+ {{ else if and (eq $file.Content "") (ne $file.OldFilename "") }}

File renamed without changes

{{ else if eq $file.Content "" }}

Empty file