]> source.dussan.org Git - gitea.git/commit
Fix broken spans in diffs (#14678) (#14683)
authorzeripath <art27@cantab.net>
Sun, 14 Feb 2021 23:30:07 +0000 (23:30 +0000)
committerGitHub <noreply@github.com>
Sun, 14 Feb 2021 23:30:07 +0000 (00:30 +0100)
commitad6084a222c0091719e7837d6fca85c3a8035e7e
tree522b44026fc5ccddf8a22df911b3252565aab495
parentd3200db041a8b26169a4ec4b793fcbd1044370c1
Fix broken spans in diffs (#14678) (#14683)

Backport #14678

Gitea runs diff on highlighted code fragment for each line in order to
provide code highlight diffs. Unfortunately this diff algorithm is not
aware that span tags and entities are atomic and cannot be split.

The current fixup code makes some attempt to fix these broken tags
however, it cannot handle situations where a tag is split over multiple
blocks.

This PR provides a more algorithmic fixup mechanism whereby spans and
entities are completely coalesced into their respective blocks.

This may result in a incompletely reduced diff but - it will definitely
prevent the broken entities and spans that are currently possible.

As a result of this fixup several inconsistencies were discovered in our
testcases and these were also fixed.

Fix #14231

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
services/gitdiff/gitdiff.go
services/gitdiff/gitdiff_test.go