diff options
author | zeripath <art27@cantab.net> | 2021-08-29 15:28:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-29 15:28:04 +0100 |
commit | f5b0e2c9d2336367dfcf121be6ff5154017192cf (patch) | |
tree | 85b820b9aed4583ad05c232ed1ddb7abb93d50c2 /services | |
parent | d24eb6e6ced43fbf198617c36686655570bb92bc (diff) | |
download | gitea-f5b0e2c9d2336367dfcf121be6ff5154017192cf.tar.gz gitea-f5b0e2c9d2336367dfcf121be6ff5154017192cf.zip |
Simplify split diff view generation and remove JS dependency (#16775)
Gitea has relied on some slow JS code to match up added and deleted lines on the
diff pages. This can cause a considerable slow down on large diff pages.
This PR makes a small change meaning that the matching up can occur much more simply.
Partial fix #1351
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services')
-rw-r--r-- | services/gitdiff/gitdiff.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index d50e41eb40..59da680d48 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -75,6 +75,7 @@ const ( type DiffLine struct { LeftIdx int RightIdx int + Match int Type DiffLineType Content string Comments []*models.Comment @@ -943,6 +944,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curFileLFSPrefix bool ) + lastLeftIdx := -1 leftLine, rightLine := 1, 1 for { @@ -1027,13 +1029,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curFile.IsIncomplete = true continue } - diffLine := &DiffLine{Type: DiffLineAdd, RightIdx: rightLine} + diffLine := &DiffLine{Type: DiffLineAdd, RightIdx: rightLine, Match: -1} rightLine++ if curSection == nil { // Create a new section to represent this hunk curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) } + if lastLeftIdx > -1 { + diffLine.Match = lastLeftIdx + curSection.Lines[lastLeftIdx].Match = len(curSection.Lines) + lastLeftIdx++ + if lastLeftIdx >= len(curSection.Lines) || curSection.Lines[lastLeftIdx].Type != DiffLineDel { + lastLeftIdx = -1 + } + } curSection.Lines = append(curSection.Lines, diffLine) case '-': curFileLinesCount++ @@ -1042,7 +1052,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curFile.IsIncomplete = true continue } - diffLine := &DiffLine{Type: DiffLineDel, LeftIdx: leftLine} + diffLine := &DiffLine{Type: DiffLineDel, LeftIdx: leftLine, Match: -1} if leftLine > 0 { leftLine++ } @@ -1051,6 +1061,9 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) } + if len(curSection.Lines) == 0 || curSection.Lines[len(curSection.Lines)-1].Type != DiffLineDel { + lastLeftIdx = len(curSection.Lines) + } curSection.Lines = append(curSection.Lines, diffLine) case ' ': curFileLinesCount++ @@ -1061,6 +1074,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio diffLine := &DiffLine{Type: DiffLinePlain, LeftIdx: leftLine, RightIdx: rightLine} leftLine++ rightLine++ + lastLeftIdx = -1 if curSection == nil { // Create a new section to represent this hunk curSection = &DiffSection{} |