Unified diffs of two texts, for --diff.
Lines are matched with a longest common subsequence computed by Hirschberg's algorithm, which needs memory linear in the number of lines, so a diff of a file whose every line changed is still cheap. Lines are compared as integers after hashing.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | OP_DELETE | = | 1 | |
| integer, | private, | parameter | :: | OP_EQUAL | = | 0 | |
| integer, | private, | parameter | :: | OP_INSERT | = | 2 |
The edits that turn the lines of one text into those of the other, in order.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | n | = | 0 |
number of edits in |
|
| integer, | public, | allocatable | :: | op(:) |
OP_EQUAL, OP_DELETE (line of a) or OP_INSERT (line of b) |
FNV-1a hash.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | s |
the bytes to hash |
row(k): the length of the longest common subsequence of a and b(1:k).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | a(:) |
line numbers of the two texts |
||
| integer, | intent(in) | :: | b(:) |
line numbers of the two texts |
start,n for a hunk header; start is the line before the hunk when it is empty.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | start |
first line of the hunk |
||
| integer, | intent(in) | :: | n |
number of lines in the hunk |
The lines of text, each with its line ending (the last one may have none).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | text |
the text |
The changes from a to b as a unified diff with context lines of context (default 3),
with name in the headers. Empty if the texts are equal.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | a |
the old text |
||
| character(len=*), | intent(in) | :: | b |
the new text |
||
| character(len=*), | intent(in) | :: | name |
file name for the |
||
| integer, | intent(in), | optional | :: | context |
number of unchanged lines shown around each change |
Append the edits that turn a(a0:a1) into b(b0:b1) along a longest common subsequence
(Hirschberg's algorithm).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | a(:) |
line numbers of the two texts, from |
||
| integer, | intent(in) | :: | a0 |
the ranges of |
||
| integer, | intent(in) | :: | a1 |
the ranges of |
||
| integer, | intent(in) | :: | b(:) |
line numbers of the two texts, from |
||
| integer, | intent(in) | :: | b0 |
the ranges of |
||
| integer, | intent(in) | :: | b1 |
the ranges of |
||
| type(edit_t), | intent(inout) | :: | e |
the edits so far; |
Number the distinct lines, so that equal lines have equal numbers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(string_t), | intent(in) | :: | la(:) |
the lines of the two texts |
||
| type(string_t), | intent(in) | :: | lb(:) |
the lines of the two texts |
||
| integer, | intent(out), | allocatable | :: | ia(:) |
the number of each line of |
|
| integer, | intent(out), | allocatable | :: | ib(:) |
the number of each line of |