Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Why we have not considered Line Endings for Different OS(Linux, Windows, MacOS) #137

Open

Description

@deepanshukhanna

I came across one issue in which my files saved on git are differ in terms of line start or end. git diff or git UI handles it as it normalize line endings to LF (/n) on Unix-based systems and to CRLF (/r/n) on Windows-based systems. My point here is if git handling it in diff or UI we will never able to see these differences and that too doesn't matter as per the file changes. can we configure here or do some changes so that this diff match patch don't consider while evaluating differences? reason for this is, it will be very difficult to take this into consideration after evaluation of diff-match-patch.

Activity

  1. dmsnell commented on Feb 15, 2023

    @dmsnell

    @deepanshukhanna the easiest thing might be to normalize those line endings before running the texts in diff-match-patch. Not sure what language you are using, but a Regular Expression pattern should be translatable to pretty much anything, or you could manually scan the text.

    replace( text_a, search: "/\r\n/g", replace: "\n" )
    

    this would prevent those differences from appearing in a diff. the other side of this coin is that if you do this to hide those differences you won't be able to move from the original input text to the other as the indices will be changed during normalization.

    alternatively it may not be as hard as you imagine to post-process. we're only expecting the addition of \r or the deletion of \r, so you can skip over those in any display you are using. if you find a diff operation that's only \r you can skip it as if it doesn't exist. if you're working with the patch format which only states how many characters to delete then you can still analyze this against the input text to remove the display of those line-ending changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions