java-diff-utils / java-diff-utils

Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.

Home Page:https://java-diff-utils.github.io/java-diff-utils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detecting Moved Lines in Diffs

RunXia2 opened this issue · comments

Hello,

I've been using java-diff-utils to generate diffs between text files and I've noticed that the library doesn't seem to explicitly handle or detect moved lines (lines that have been relocated but not modified). This feature can be particularly useful for understanding code refactoring or changes in documents where paragraphs have been rearranged without modification.

I searched through the existing issues but didn't find any that addressed this particular use case.

Has there been any discussion or consideration for adding support to detect moved lines within the diff process? If not, I believe this would be a valuable feature to add to java-diff-utils.

As an example to illustrate the importance of detecting moved lines, consider the following scenario with two versions of a text:

Original text:
The Supplier shall ensure that all documents for the Products provided to XXX for customs clearance (if any) are
accurate, correct and in accordance with the actual Products supplied XXX for smooth customs clearance. If the
Products supplied to XXX are held by the customs authorities due to Supplier’s failure to provide accurate and/or
correct documentations, Supplier shall pay to MFS for all actual losses suffered by XXX (including without limitation
any penalties and interest charged by any taxation or customs authorities), and compensate XXX 10% of the value of
the Purchase Order for goods which are held by the customs authorities.

New text:
The Supplier shall ensure that all documents for the Products provided to XXX for customs clearance (if
any) are accurate, correct and in accordance with the actual Products supplied XXX for smooth customs
clearance. If the Products supplied to XXX are held by the customs authorities due to Supplier’s failure to
provide accurate and/or correct documentations, Supplier shall pay to XXX for all actual losses suffered by
XXX (including without limitation any penalties and interest charged by any taxation or customs authorities),
and compensate XXX 10% of the value of the Purchase Order for goods which are held by the customs authorities.

In this example, the text has been reformatted with different line breaks but the content remains unchanged. A diff tool without the ability to detect moved lines might indicate many changes when, in reality, the only difference is the line structure.

Thank you for your work on this library!

Unfortunately there is no discussion and no plan implementing this. You could make a suggestion. PRs are welcome.

Stale issue message