mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 11:16:11 +01:00
feat: Improve diff being generated
Add `DiffCleanupSemantic` into the mix when generated diffs (PR review, commit view and issue/comment history). This avoids trying to produce a optimal diff and tries to reduce the amount of edits, by combing them into larger edits, which is nicer and easier to 'look at'. There's no need for a perfect minimal diff, as the output isn't being parsed by a computer, it's parsed by people. Ref: https://codeberg.org/forgejo/forgejo/issues/4996
This commit is contained in:
parent
d97e36f6d7
commit
58ee9fdc4a
|
@ -154,6 +154,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
|
|||
dmp := diffmatchpatch.New()
|
||||
// `checklines=false` makes better diff result
|
||||
diff := dmp.DiffMain(prevHistoryContentText, history.ContentText, false)
|
||||
diff = dmp.DiffCleanupSemantic(diff)
|
||||
diff = dmp.DiffCleanupEfficiency(diff)
|
||||
|
||||
// use chroma to render the diff html
|
||||
|
|
|
@ -97,6 +97,7 @@ func (hcd *HighlightCodeDiff) diffWithHighlight(filename, language, codeA, codeB
|
|||
convertedCodeB := hcd.ConvertToPlaceholders(string(highlightCodeB))
|
||||
|
||||
diffs := diffMatchPatch.DiffMain(convertedCodeA, convertedCodeB, true)
|
||||
diffs = diffMatchPatch.DiffCleanupSemantic(diffs)
|
||||
diffs = diffMatchPatch.DiffCleanupEfficiency(diffs)
|
||||
|
||||
for i := range diffs {
|
||||
|
|
Loading…
Reference in a new issue