Diff-0.5: Diff algorithm in pure Haskell
Copyright(c) David Fox (2015)
LicenseBSD 3 Clause
Maintainers.clover@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Algorithm.DiffContext

Description

Generates a grouped diff with merged runs, and outputs them in the manner of diff -u

Synopsis

Documentation

getContextDiffNew Source #

Arguments

:: Eq a 
=> Maybe Int

Number of context elements, Nothing means infinite

-> [a] 
-> [a] 
-> ContextDiff a 

See https://github.com/seereason/Diff/commit/35596ca45fdd6ee2559cf610bef7a86b4617988a. The original getContextDiff omitted trailing context in diff hunks. This new one corrects the issue. Here is the example from the test suite:

prettyContextDiff (text "file1") (text "file2") text (getContextDiffOld 2 (lines textA) (lines textB))
  • -- file1 +++ file2 @@ a b
  • c @ d e @ i j
  • k
prettyContextDiff (text "file1") (text "file2") text (getContextDiff 2 (lines textA) (lines textB))
  • -- file1 +++ file2 @@ a b
  • c d e @@ i j
  • k

getContextDiff :: Eq a => Int -> [a] -> [a] -> ContextDiff a Source #

getContextDiffOld :: Eq a => Int -> [a] -> [a] -> ContextDiff a Source #

Do a grouped diff and then split up the chunks into runs that contain differences surrounded by N lines of unchanged text. If there is less then 2N+1 lines of unchanged text between two changes, the runs are left merged.

prettyContextDiff Source #

Arguments

:: Doc

Document 1 name

-> Doc

Document 2 name

-> (c -> Doc)

Element pretty printer

-> ContextDiff c 
-> Doc 

Pretty print a ContextDiff in the manner of diff -u.