Diff highlighting doesn't always include all changes #8867

Closed
opened 2025-11-02 08:21:37 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @Gusted on GitHub (Apr 26, 2022).

Description

Currently when Gitea is highlighting a diff, it's possible that not all code is correctly "diffed", this means that part of added code isn't included in the added-code span, but rather outside of it.

This is caused by broken spans! Gitea is diffing the code after it has been highlighted by chroma. This means we're diffing with HTML code, this causes that certain HTML elements are being split apart from each other, one part could live in the "equal" part and the other part in the "insert" this causes Broken spans, @zeripath has made a excellent attempt at fixing most cases of this broken spans, but there are still cases where this code fails to fix the broken spans:

https://try.gitea.io/Gusted/Test-repo/pulls/3/files

You can clearly see here that the ), xdg' part also should be included into the inserted code part. But because of certain set of conditions we're not fixing all broken spans in this case.

Gitea Version

03eba32bd9

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

N/A

Screenshots

Actual:
image

Expected:
image

Git Version

N/A

Operating System

N/A

How are you running Gitea?

https://try.gitea.io/Gusted/Test-repo/pulls/3/files

Database

No response

Originally created by @Gusted on GitHub (Apr 26, 2022). ### Description Currently when Gitea is highlighting a diff, it's possible that not all code is correctly "diffed", this means that part of added code isn't included in the `added-code` span, but rather outside of it. This is caused by broken spans! Gitea is diffing the code after it has been highlighted by chroma. This means we're diffing with HTML code, this causes that certain HTML elements are being split apart from each other, one part could live in the "equal" part and the other part in the "insert" this causes Broken spans, @zeripath has made [a excellent attempt](https://github.com/go-gitea/gitea/pull/14678) at fixing most cases of this broken spans, but there are still cases where this code fails to fix the broken spans: https://try.gitea.io/Gusted/Test-repo/pulls/3/files You can clearly see here that the `), xdg'` part also should be included into the `inserted` code part. But because of certain set of conditions we're not fixing all broken spans in this case. ### Gitea Version https://github.com/go-gitea/gitea/commit/03eba32bd91533f090a82b62bd9cffd9e448aaa7 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist N/A ### Screenshots Actual: ![image](https://user-images.githubusercontent.com/25481501/165333462-4d25909c-6be2-4fa9-b4ca-fc4e3f0eea84.png) Expected: ![image](https://user-images.githubusercontent.com/25481501/165333431-510e8276-ff2c-415a-888a-bce4ea34a92c.png) ### Git Version N/A ### Operating System N/A ### How are you running Gitea? https://try.gitea.io/Gusted/Test-repo/pulls/3/files ### Database _No response_
GiteaMirror added the type/bug label 2025-11-02 08:21:37 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Jul 23, 2022):

@Gusted I checked https://try.gitea.io/Gusted/Test-repo/pulls/3/files , it's better than before.

image

@wxiaoguang commented on GitHub (Jul 23, 2022): @Gusted I checked https://try.gitea.io/Gusted/Test-repo/pulls/3/files , it's better than before. ![image](https://user-images.githubusercontent.com/2114189/180604911-a299cc46-8dc7-407a-9ee1-818ae0afe5d3.png)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8867