filediff-2.0.0: Diffing and patching module

Safe Haskell None Haskell2010

Filediff

Contents

Description

The module exposing the functionality of this package

Synopsis

# lists

diffLists :: forall a. Eq a => [a] -> [a] -> ListDiff a Source

Computes the minimal number of additions and deletions needed to transform the first parameter into the second.

```λ diffLists "abcdefg" "wabxyze"
ListDiff {dels = [(2,'c'),(3,'d'),(5,'f'),(6,'g')], adds = [(0,'w'),(3,'x'),(4,'y'),(5,'z')]}```

applyListDiff :: forall a. Eq a => ListDiff a -> [a] -> Either Error [a] Source

Applies a list diff. For example,

```ListDiff {dels = [(2,'c'),(3,'d'),(5,'f'),(6,'g')], adds = [(0,'w'),(3,'x'),(4,'y'),(5,'z')]}
λ applyListDiff it "abcdefg"
Right "wabxyze"```

Returns a fail state if the diff cannot be applied. This can happen for two reasons: first, the diff calls for a deletion at an index but the element at that index doesn't match the element believed by the to be diff at that index. Second, it can happen if the diff calls for an element to be added at an index too large for the given input. Here are respective examples of inputs that would trigger this case:

```let base = "abcdefg"
let faultyBase = "ab*defg"
let comp = "wabxyze"
let listDiff = F.diffLists base comp
F.applyListDiff listDiff faultyBase -- fails```

and

```let base = "abcdefg"
let faultyBase = "abcde"
let comp = "wabxyzefgq"
let listDiff = F.diffLists base comp
F.applyListDiff listDiff faultyBase -- fails```

# files

O(mn). Compute the difference between the two files (more specifically, the minimal number of changes to make to transform the file residing at the location specified by the first parameter into the second). Throws an exception if either or both of the parameters point to a directory, not a file.

Files are allowed to not exist at either or both of the parameters.

O(n). Apply a diff to a file. Returns the fail state if application fails. For more on how diff application can fail, see `applyListDiff`.

# directories

Compute the difference between the two directories (more specifically, the minimal number of changes to make to transform the directory residing at the location specified by the first parameter into the second). Throws an exception if either or both of the parameters point to a file, not a directory.

Diff two directories, ignoring some subdirectories. The first `[FilePath]` parameter refers to the first `FilePath` parameter, and same for the second, respectively.

Applies a `Diff` to a directory. Returns the fail state if any file application fails, but because of the parallelism in the implementation, all file diffs will be attempted to be applied, so if this fails, your directory will be left in an inconsistent state. For more on how diff application can fail, see `applyListDiff`.