# HG changeset patch # User Mike Becker # Date 1757858307 -7200 # Node ID a0c4d4038f2173cdd0ef4642e394d4b25c510afc # Parent 41ce87983ab5c36d34e196f107cb5ab93d97080a fix incorrect diff in comments and descriptions - part 2/2 fixes #719 diff -r 41ce87983ab5 -r a0c4d4038f21 src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt --- a/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sun Sep 14 15:42:23 2025 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sun Sep 14 15:58:27 2025 +0200 @@ -59,6 +59,20 @@ .build() ) + /** + * Fixes the incompetence of Java DiffUtils. + * Only the CHANGE and EQUAL cases are presented correctly out of the box. + * For DELETE and INSERT we need to add the tags ourselves. + */ + fun presentDiff(row: DiffRow): String { + return when (row.tag) { + DiffRow.Tag.CHANGE -> row.oldLine + DiffRow.Tag.DELETE -> "${row.oldLine}" + DiffRow.Tag.INSERT -> "${row.newLine}" + DiffRow.Tag.EQUAL -> row.oldLine + } + } + private fun fullContent(data: IssueCommentHistoryEntry) = CommentDiff( issueid = data.issueid, @@ -75,9 +89,9 @@ project = cur.project, currentSubject = cur.subject, comment = diffGenerator.generateDiffRows( - next.comment.replace("\r", "").split('\n'), - cur.comment.replace("\r", "").split('\n') - ).joinToString("\n", transform = DiffRow::getOldLine) + listOf(next.comment.replace("\r", "")), + listOf(cur.comment.replace("\r", "")) + ).joinToString("\n", transform = this::presentDiff) ) private fun fullContent(http: HttpRequest, issue: IssueHistoryEntry) = IssueDiff( @@ -112,18 +126,18 @@ return IssueDiff( id = curContent.id, project = curContent.project, - subject = result[0].oldLine, - component = result[1].oldLine, - status = result[2].oldLine, - category = result[3].oldLine, - assignee = result[4].oldLine, - eta = result[5].oldLine, - affected = result[6].oldLine, - resolved = result[7].oldLine, + subject = presentDiff(result[0]), + component = presentDiff(result[1]), + status = presentDiff(result[2]), + category = presentDiff(result[3]), + assignee = presentDiff(result[4]), + eta = presentDiff(result[5]), + affected = presentDiff(result[6]), + resolved = presentDiff(result[7]), description = diffGenerator.generateDiffRows( nextContent.description.split('\n'), curContent.description.split('\n') - ).joinToString("\n", transform = DiffRow::getOldLine) + ).joinToString("\n", transform = this::presentDiff) ) }