diff-lcs 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +170 -85
- data/CODE_OF_CONDUCT.md +49 -48
- data/CONTRIBUTING.md +29 -28
- data/CONTRIBUTORS.md +15 -11
- data/LICENCE.md +19 -38
- data/Manifest.txt +16 -3
- data/README.md +24 -22
- data/Rakefile +3 -0
- data/SECURITY.md +5 -5
- data/lib/diff/lcs/array.rb +3 -1
- data/lib/diff/lcs/callbacks.rb +1 -1
- data/lib/diff/lcs/change.rb +74 -32
- data/lib/diff/lcs/frozen_value.rb +74 -0
- data/lib/diff/lcs/hunk.rb +146 -58
- data/lib/diff/lcs/internals.rb +183 -72
- data/lib/diff/lcs/ldiff.rb +23 -45
- data/lib/diff/lcs/string.rb +3 -1
- data/lib/diff/lcs/version.rb +1 -1
- data/lib/diff/lcs.rb +29 -26
- data/licences/MIT.txt +19 -0
- data/spec/ldiff_spec.rb +9 -7
- data/test/fixtures/ldiff/output.diff.bin1-q +0 -0
- data/test/fixtures/ldiff/output.diff.bin2-q +1 -0
- data/test/fixtures/ldiff/output.diff.hunks +9 -0
- data/test/fixtures/ldiff/output.diff.hunks-c +35 -0
- data/test/fixtures/ldiff/output.diff.hunks-u +20 -0
- data/test/fixtures/ldiff/output.diff.same +0 -0
- data/test/fixtures/ldiff/output.diff.same-c +0 -0
- data/test/fixtures/ldiff/output.diff.same-u +0 -0
- data/test/fixtures/new-hunks +31 -0
- data/test/fixtures/old-hunks +30 -0
- data/test/test_change.rb +23 -19
- data/test/test_frozen_value.rb +155 -0
- data/test/test_helper.rb +5 -0
- data/test/test_hunk.rb +238 -0
- data/test/test_lcs.rb +147 -0
- data/test/test_ldiff.rb +64 -7
- metadata +24 -11
- /data/{licenses → licences}/COPYING.txt +0 -0
- /data/{licenses → licences}/artistic.txt +0 -0
- /data/{licenses → licences}/dco.txt +0 -0
data/CONTRIBUTING.md
CHANGED
|
@@ -4,7 +4,7 @@ Contribution to diff-lcs is encouraged: bug reports, feature requests, or code
|
|
|
4
4
|
contributions. New features should be proposed and discussed in an
|
|
5
5
|
[issue][issues].
|
|
6
6
|
|
|
7
|
-
Before contributing patches, please read the [Licence](
|
|
7
|
+
Before contributing patches, please read the [Licence](LICENCE.md).
|
|
8
8
|
|
|
9
9
|
diff-lcs is governed under the [Contributor Covenant Code of Conduct][cccoc].
|
|
10
10
|
|
|
@@ -15,29 +15,29 @@ I have several guidelines to contributing code through pull requests:
|
|
|
15
15
|
- All code changes require tests. In most cases, this will be added or updated
|
|
16
16
|
unit tests. I use [Minitest][minitest].
|
|
17
17
|
|
|
18
|
-
- There are integration tests with RSpec which must not be broken,
|
|
19
|
-
through `rake integration`. This requires a non-bundled RSpec,
|
|
18
|
+
- There are integration tests with RSpec which must not be broken,
|
|
19
|
+
accessible through `rake integration`. This requires a non-bundled RSpec,
|
|
20
20
|
`gem install rspec`.
|
|
21
21
|
|
|
22
|
-
- I use code formatters, static analysis tools, and linting to ensure
|
|
23
|
-
styles and formatting. There should be no warning output from
|
|
24
|
-
processes. I use [Standard Ruby][standardrb].
|
|
22
|
+
- I use code formatters, static analysis tools, and linting to ensure
|
|
23
|
+
consistent styles and formatting. There should be no warning output from
|
|
24
|
+
test run processes. I use [Standard Ruby][standardrb].
|
|
25
25
|
|
|
26
|
-
- Proposed changes should be on a thoughtfully-named topic branch and
|
|
27
|
-
into logical commit chunks as appropriate.
|
|
26
|
+
- Proposed changes should be on a thoughtfully-named topic branch and
|
|
27
|
+
organized into logical commit chunks as appropriate.
|
|
28
28
|
|
|
29
29
|
- Use [Conventional Commits][conventional] with my
|
|
30
30
|
[conventions](#commit-conventions).
|
|
31
31
|
|
|
32
|
-
- Versions must not be updated in pull requests unless otherwise directed.
|
|
33
|
-
means that you must not:
|
|
32
|
+
- Versions must not be updated in pull requests unless otherwise directed.
|
|
33
|
+
This means that you must not:
|
|
34
34
|
|
|
35
35
|
- Modify `VERSION` in `lib/diff/lcs/version.rb`. When your patch is accepted
|
|
36
36
|
and a release is made, the version will be updated at that point.
|
|
37
37
|
|
|
38
38
|
- Modify `diff-lcs.gemspec`; it is a generated file. (You _may_ use
|
|
39
|
-
`rake gemspec` to regenerate it if your change involves metadata related
|
|
40
|
-
gem itself).
|
|
39
|
+
`rake gemspec` to regenerate it if your change involves metadata related
|
|
40
|
+
to gem itself).
|
|
41
41
|
|
|
42
42
|
- Modify the `Gemfile`.
|
|
43
43
|
|
|
@@ -52,7 +52,8 @@ I have several guidelines to contributing code through pull requests:
|
|
|
52
52
|
`CHANGELOG.md` as a separate commit from your main change. (Follow the style
|
|
53
53
|
in the `CHANGELOG.md` and provide a link to your PR.)
|
|
54
54
|
|
|
55
|
-
- Include your DCO sign-off in each commit message (see
|
|
55
|
+
- Include your DCO sign-off in each commit message (see
|
|
56
|
+
[LICENCE](LICENCE.md)).
|
|
56
57
|
|
|
57
58
|
## AI Contribution Policy
|
|
58
59
|
|
|
@@ -62,17 +63,17 @@ sort be well understood by the submitter and that the developer can attest to
|
|
|
62
63
|
the [Developer Certificate of Origin][dco] for each pull request (see
|
|
63
64
|
[LICENCE](LICENCE.md)).
|
|
64
65
|
|
|
65
|
-
Any contribution (bug, feature request, or pull request) that uses undeclared
|
|
66
|
-
output will be rejected.
|
|
66
|
+
Any contribution (bug, feature request, or pull request) that uses undeclared
|
|
67
|
+
AI output will be rejected.
|
|
67
68
|
|
|
68
69
|
## Test Dependencies
|
|
69
70
|
|
|
70
|
-
diff-lcs uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it
|
|
71
|
-
a number of rake tasks. You will mostly be interested in `rake`, which
|
|
72
|
-
tests in the same way that `rake spec` does.
|
|
71
|
+
diff-lcs uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it
|
|
72
|
+
adds a number of rake tasks. You will mostly be interested in `rake`, which
|
|
73
|
+
runs tests in the same way that `rake spec` does.
|
|
73
74
|
|
|
74
|
-
To assist with the installation of the development dependencies for diff-lcs,
|
|
75
|
-
have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file.
|
|
75
|
+
To assist with the installation of the development dependencies for diff-lcs,
|
|
76
|
+
I have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file.
|
|
76
77
|
This will permit you to use `bundle install` to install the dependencies.
|
|
77
78
|
|
|
78
79
|
You can run tests with code coverage analysis by running `rake spec:coverage`.
|
|
@@ -100,21 +101,21 @@ required metadata trailers are:
|
|
|
100
101
|
- `Breaking-Change`: if the change is a breaking change. **Do not** use the
|
|
101
102
|
shorthand form (`feat!(scope)`) or `BREAKING CHANGE`.
|
|
102
103
|
|
|
103
|
-
- `Signed-off-by`: this is required for all developers except me, as outlined
|
|
104
|
-
the [Licence](
|
|
104
|
+
- `Signed-off-by`: this is required for all developers except me, as outlined
|
|
105
|
+
in the [Licence](LICENCE.md#developer-certificate-of-origin).
|
|
105
106
|
|
|
106
107
|
- `Fixes` or `Resolves`: If a change fixes one or more open [issues][issues],
|
|
107
108
|
that issue must be included in the `Fixes` or `Resolves` trailer. Multiple
|
|
108
109
|
issues should be listed comma separated in the same trailer:
|
|
109
|
-
`Fixes: #1, #5, #7`, but _may_ appear in separate trailers. While both
|
|
110
|
-
and `Resolves` are synonyms, only _one_ should be used in a given
|
|
111
|
-
pull request.
|
|
110
|
+
`Fixes: #1, #5, #7`, but _may_ appear in separate trailers. While both
|
|
111
|
+
`Fixes` and `Resolves` are synonyms, only _one_ should be used in a given
|
|
112
|
+
commit or pull request.
|
|
112
113
|
|
|
113
|
-
- `Related to`: If a change does not fix an issue, those issue references
|
|
114
|
-
be included in this trailer.
|
|
114
|
+
- `Related to`: If a change does not fix an issue, those issue references
|
|
115
|
+
should be included in this trailer.
|
|
115
116
|
|
|
116
117
|
[cbeams]: https://cbea.ms/git-commit/
|
|
117
|
-
[cccoc]:
|
|
118
|
+
[cccoc]: CODE_OF_CONDUCT.md
|
|
118
119
|
[conventional]: https://www.conventionalcommits.org/en/v1.0.0/
|
|
119
120
|
[dco]: licences/dco.txt
|
|
120
121
|
[hoe]: https://github.com/seattlerb/hoe
|
data/CONTRIBUTORS.md
CHANGED
|
@@ -4,19 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
Thanks to everyone else who has contributed to diff-lcs over the years:
|
|
6
6
|
|
|
7
|
-
- [@ginriki][gh-user-ginriki]
|
|
8
|
-
- [@joshbronson][gh-user-joshbronson]
|
|
9
|
-
- [@kevinmook][gh-user-kevinmook]
|
|
10
|
-
- [@mckaz][gh-user-mckaz]
|
|
11
7
|
- Akinori Musha
|
|
12
8
|
- Artem Ignatyev
|
|
13
|
-
- Brandon Fish
|
|
14
9
|
- Baptiste Courtois ([@annih][gh-user-annih])
|
|
10
|
+
- Brandon Fish
|
|
15
11
|
- Camille Drapier
|
|
16
12
|
- Cédric Boutillier
|
|
17
|
-
- [@
|
|
13
|
+
- Clément Joubert ([@czj][gh-user-czj])
|
|
18
14
|
- Gregg Kellogg
|
|
19
15
|
- Jagdeep Singh
|
|
16
|
+
- James Thompson ([@thompson-tomo][gh-user-thompson-tomo])
|
|
20
17
|
- Jason Gladish
|
|
21
18
|
- Jon Rowe
|
|
22
19
|
- Josef Strzibny
|
|
@@ -29,8 +26,8 @@ Thanks to everyone else who has contributed to diff-lcs over the years:
|
|
|
29
26
|
- Kevin Ansfield
|
|
30
27
|
- Koichi Ito
|
|
31
28
|
- Mark Friedgan
|
|
32
|
-
- Masato Nakamura
|
|
33
29
|
- Mark Young
|
|
30
|
+
- Masato Nakamura
|
|
34
31
|
- Michael Granger
|
|
35
32
|
- Myron Marston
|
|
36
33
|
- Nicolas Leger
|
|
@@ -47,13 +44,20 @@ Thanks to everyone else who has contributed to diff-lcs over the years:
|
|
|
47
44
|
- Tien ([@tiendo1011][gh-user-tiendo1011])
|
|
48
45
|
- Tomas Jura
|
|
49
46
|
- Vít Ondruch
|
|
47
|
+
- [@earlopain][gh-user-earlopain]
|
|
48
|
+
- [@ginriki][gh-user-ginriki]
|
|
49
|
+
- [@joshbronson][gh-user-joshbronson]
|
|
50
|
+
- [@kevinmook][gh-user-kevinmook]
|
|
51
|
+
- [@mckaz][gh-user-mckaz]
|
|
50
52
|
|
|
51
|
-
[gh-user-
|
|
53
|
+
[gh-user-annih]: https://github.com/annih
|
|
54
|
+
[gh-user-apuratepp]: https://github.com/apuratepp
|
|
55
|
+
[gh-user-czj]: https://github.com/czj
|
|
56
|
+
[gh-user-earlopain]: https://github.com/earlopain
|
|
52
57
|
[gh-user-ginriki]: https://github.com/ginriki
|
|
58
|
+
[gh-user-halostatue]: https://github.com/halostatue
|
|
53
59
|
[gh-user-joshbronson]: https://github.com/joshbronson
|
|
54
60
|
[gh-user-kevinmook]: https://github.com/kevinmook
|
|
55
61
|
[gh-user-mckaz]: https://github.com/mckaz
|
|
56
|
-
[gh-user-
|
|
57
|
-
[gh-user-earlopain]: https://github.com/earlopain
|
|
58
|
-
[gh-user-apuratepp]: https://github.com/apuratepp
|
|
62
|
+
[gh-user-thompson-tomo]: https://github.com/thompson-tomo
|
|
59
63
|
[gh-user-tiendo1011]: https://github.com/tiendo1011
|
data/LICENCE.md
CHANGED
|
@@ -1,47 +1,26 @@
|
|
|
1
1
|
# Licence
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[Artistic-1.0-Perl][artistic-perl]
|
|
3
|
+
<!-- SPDX-License-Identifier: MIT OR Artistic-1.0-Perl OR GPL-2.0-or-later -->
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Algorithm::Diff was dually originally licensed with the Perl Artistic and the
|
|
10
|
-
GNU GPL ("the same terms as Perl itself") and given that the Ruby implementation
|
|
11
|
-
originally hewed pretty closely to the Perl version, I must maintain the
|
|
12
|
-
additional licensing terms.
|
|
5
|
+
Diff::LCS is copyright 2004–2026 Austin Ziegler and contributors, adapted from
|
|
6
|
+
Algorithm::Diff (Perl) by Ned Konz and a Smalltalk diff implementation by
|
|
7
|
+
Mario I. Wolczko.
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
- Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
|
|
16
|
-
Mario I. Wolczko.
|
|
9
|
+
This software is available under three disjunctive licences:
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
- the [MIT license](licences/MIT.txt);
|
|
12
|
+
- the [Perl Artistic license](licences/artistic.txt); or
|
|
13
|
+
- the [GNU GPL version 2](licences/COPYING.txt) (or at your option, a later
|
|
14
|
+
version).
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
subject to the following conditions:
|
|
16
|
+
Note that my preference for licensing is the MIT license, but Algorithm::Diff
|
|
17
|
+
was dually originally licensed with the Perl Artistic and the GNU GPL ("the
|
|
18
|
+
same terms as Perl itself") and given that the Ruby implementation originally
|
|
19
|
+
hewed pretty closely to the Perl version, I must maintain the additional
|
|
20
|
+
licensing terms.
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
32
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
33
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
34
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
35
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
36
|
-
|
|
37
|
-
## Perl Artistic License
|
|
38
|
-
|
|
39
|
-
See [licences/artistic.txt](licences/artistic.txt) in the main distribution.
|
|
40
|
-
|
|
41
|
-
## GNU GPL version 2
|
|
42
|
-
|
|
43
|
-
See the file [licences/COPYING.txt](licences/COPYING.txt) in the main
|
|
44
|
-
distribution.
|
|
22
|
+
- SPDX License: [MIT][mit] OR [Artistic-1.0-Perl][artistic-perl] OR
|
|
23
|
+
[GPL-2.0-or-later][gpl2-or-later]
|
|
45
24
|
|
|
46
25
|
## Developer Certificate of Origin
|
|
47
26
|
|
|
@@ -52,7 +31,9 @@ certification of the [Developer Certificate of Origin (Version 1.1)][dco].
|
|
|
52
31
|
Such certification is provided by ensuring that a `Signed-off-by`
|
|
53
32
|
[commit trailer][trailer] is present on every commit:
|
|
54
33
|
|
|
55
|
-
|
|
34
|
+
```text
|
|
35
|
+
Signed-off-by: FirstName LastName <email@example.org>
|
|
36
|
+
```
|
|
56
37
|
|
|
57
38
|
The `Signed-off-by` trailer can be automatically added by git with the `-s` or
|
|
58
39
|
`--signoff` option on `git commit`:
|
data/Manifest.txt
CHANGED
|
@@ -20,14 +20,16 @@ lib/diff/lcs/array.rb
|
|
|
20
20
|
lib/diff/lcs/block.rb
|
|
21
21
|
lib/diff/lcs/callbacks.rb
|
|
22
22
|
lib/diff/lcs/change.rb
|
|
23
|
+
lib/diff/lcs/frozen_value.rb
|
|
23
24
|
lib/diff/lcs/hunk.rb
|
|
24
25
|
lib/diff/lcs/internals.rb
|
|
25
26
|
lib/diff/lcs/ldiff.rb
|
|
26
27
|
lib/diff/lcs/string.rb
|
|
27
28
|
lib/diff/lcs/version.rb
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
licences/COPYING.txt
|
|
30
|
+
licences/MIT.txt
|
|
31
|
+
licences/artistic.txt
|
|
32
|
+
licences/dco.txt
|
|
31
33
|
spec/change_spec.rb
|
|
32
34
|
spec/diff_spec.rb
|
|
33
35
|
spec/hunk_spec.rb
|
|
@@ -67,11 +69,13 @@ test/fixtures/ldiff/output.diff.bin1
|
|
|
67
69
|
test/fixtures/ldiff/output.diff.bin1-c
|
|
68
70
|
test/fixtures/ldiff/output.diff.bin1-e
|
|
69
71
|
test/fixtures/ldiff/output.diff.bin1-f
|
|
72
|
+
test/fixtures/ldiff/output.diff.bin1-q
|
|
70
73
|
test/fixtures/ldiff/output.diff.bin1-u
|
|
71
74
|
test/fixtures/ldiff/output.diff.bin2
|
|
72
75
|
test/fixtures/ldiff/output.diff.bin2-c
|
|
73
76
|
test/fixtures/ldiff/output.diff.bin2-e
|
|
74
77
|
test/fixtures/ldiff/output.diff.bin2-f
|
|
78
|
+
test/fixtures/ldiff/output.diff.bin2-q
|
|
75
79
|
test/fixtures/ldiff/output.diff.bin2-u
|
|
76
80
|
test/fixtures/ldiff/output.diff.chef
|
|
77
81
|
test/fixtures/ldiff/output.diff.chef-c
|
|
@@ -90,6 +94,9 @@ test/fixtures/ldiff/output.diff.four_lines.vs.empty-c
|
|
|
90
94
|
test/fixtures/ldiff/output.diff.four_lines.vs.empty-e
|
|
91
95
|
test/fixtures/ldiff/output.diff.four_lines.vs.empty-f
|
|
92
96
|
test/fixtures/ldiff/output.diff.four_lines.vs.empty-u
|
|
97
|
+
test/fixtures/ldiff/output.diff.hunks
|
|
98
|
+
test/fixtures/ldiff/output.diff.hunks-c
|
|
99
|
+
test/fixtures/ldiff/output.diff.hunks-u
|
|
93
100
|
test/fixtures/ldiff/output.diff.issue95_trailing_context
|
|
94
101
|
test/fixtures/ldiff/output.diff.issue95_trailing_context-c
|
|
95
102
|
test/fixtures/ldiff/output.diff.issue95_trailing_context-e
|
|
@@ -105,13 +112,19 @@ test/fixtures/ldiff/output.diff.missing_new_line2-c
|
|
|
105
112
|
test/fixtures/ldiff/output.diff.missing_new_line2-e
|
|
106
113
|
test/fixtures/ldiff/output.diff.missing_new_line2-f
|
|
107
114
|
test/fixtures/ldiff/output.diff.missing_new_line2-u
|
|
115
|
+
test/fixtures/ldiff/output.diff.same
|
|
116
|
+
test/fixtures/ldiff/output.diff.same-c
|
|
117
|
+
test/fixtures/ldiff/output.diff.same-u
|
|
108
118
|
test/fixtures/new-chef
|
|
109
119
|
test/fixtures/new-chef2
|
|
120
|
+
test/fixtures/new-hunks
|
|
110
121
|
test/fixtures/old-chef
|
|
111
122
|
test/fixtures/old-chef2
|
|
123
|
+
test/fixtures/old-hunks
|
|
112
124
|
test/test_block.rb
|
|
113
125
|
test/test_change.rb
|
|
114
126
|
test/test_diff.rb
|
|
127
|
+
test/test_frozen_value.rb
|
|
115
128
|
test/test_helper.rb
|
|
116
129
|
test/test_hunk.rb
|
|
117
130
|
test/test_issues.rb
|
data/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Diff::LCS
|
|
2
2
|
|
|
3
|
-
[![RubyGems Version]
|
|
4
|
-
[](https://rubygems.org/gems/diff-lcs)
|
|
4
|
+
[](https://coveralls.io/github/halostatue/diff-lcs?branch=main)
|
|
5
|
+
[](https://github.com/halostatue/diff-lcs/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/halostatue/diff-lcs/blob/main/LICENCE.md)
|
|
5
7
|
|
|
6
8
|
- code :: <https://github.com/halostatue/diff-lcs>
|
|
7
9
|
- issues :: <https://github.com/halostatue/diff-lcs/issues>
|
|
@@ -15,8 +17,8 @@ McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
|
|
|
15
17
|
to create a simple HTML diff output format and a standard diff-like tool.
|
|
16
18
|
|
|
17
19
|
This is release 2.0, which has significant breaking changes (removal of
|
|
18
|
-
deprecations and workarounds) and requires at least Ruby 3.2 or higher. See
|
|
19
|
-
details in the `CHANGELOG`, but users of diff-lcs should not notice any
|
|
20
|
+
deprecations and workarounds) and requires at least Ruby 3.2 or higher. See
|
|
21
|
+
full details in the `CHANGELOG`, but users of diff-lcs should not notice any
|
|
20
22
|
significant changes to the APIs.
|
|
21
23
|
|
|
22
24
|
### Performance and Compatibility
|
|
@@ -28,14 +30,15 @@ strict compatibility) should allow better optimization by modern Ruby
|
|
|
28
30
|
implementations.
|
|
29
31
|
|
|
30
32
|
If you are using RSpec for your test suite, you are unlikely to be able to use
|
|
31
|
-
Diff::LCS 2.0 because of the minimum Ruby version unless the developers of
|
|
32
|
-
loosen their version constraints. I cannot control this and have raised
|
|
33
|
+
Diff::LCS 2.0 because of the minimum Ruby version unless the developers of
|
|
34
|
+
RSpec loosen their version constraints. I cannot control this and have raised
|
|
33
35
|
[rspec/rspec#290][rspec-issue-290].
|
|
34
36
|
|
|
35
37
|
## Synopsis
|
|
36
38
|
|
|
37
|
-
Using this module is quite simple. By default, Diff::LCS does not extend
|
|
38
|
-
with the Diff::LCS interface, but will be called as if it were a
|
|
39
|
+
Using this module is quite simple. By default, Diff::LCS does not extend
|
|
40
|
+
objects with the Diff::LCS interface, but will be called as if it were a
|
|
41
|
+
function:
|
|
39
42
|
|
|
40
43
|
```ruby
|
|
41
44
|
require 'diff/lcs'
|
|
@@ -72,25 +75,25 @@ seq1 == seq2.unpatch!(sdiff)
|
|
|
72
75
|
By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be
|
|
73
76
|
extended for use this way.
|
|
74
77
|
|
|
75
|
-
Note that Diff::LCS requires a sequenced enumerable container, which means
|
|
76
|
-
the order of enumeration is both predictable and consistent for the same
|
|
77
|
-
data. While it is theoretically possible to generate a diff for an
|
|
78
|
-
hash, it will only be meaningful if the enumeration of the hashes is
|
|
79
|
-
In general, this will mean that containers that behave like String
|
|
80
|
-
perform best.
|
|
78
|
+
Note that Diff::LCS requires a sequenced enumerable container, which means
|
|
79
|
+
that the order of enumeration is both predictable and consistent for the same
|
|
80
|
+
set of data. While it is theoretically possible to generate a diff for an
|
|
81
|
+
unordered hash, it will only be meaningful if the enumeration of the hashes is
|
|
82
|
+
consistent. In general, this will mean that containers that behave like String
|
|
83
|
+
or Array will perform best.
|
|
81
84
|
|
|
82
85
|
## History
|
|
83
86
|
|
|
84
|
-
Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt
|
|
85
|
-
common subsequence (LCS) algorithm to compute intelligent differences
|
|
86
|
-
two sequenced enumerable containers. The implementation is based on
|
|
87
|
-
Wolczko's [Smalltalk version 1.2][smalltalk] (1993) and Ned Konz's
|
|
88
|
-
[Algorithm::Diff 1.15][perl]. `Diff::LCS#sdiff` and
|
|
87
|
+
Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt
|
|
88
|
+
longest common subsequence (LCS) algorithm to compute intelligent differences
|
|
89
|
+
between two sequenced enumerable containers. The implementation is based on
|
|
90
|
+
Mario I. Wolczko's [Smalltalk version 1.2][smalltalk] (1993) and Ned Konz's
|
|
91
|
+
Perl version [Algorithm::Diff 1.15][perl]. `Diff::LCS#sdiff` and
|
|
89
92
|
`Diff::LCS#traverse_balanced` were originally written for the Perl version by
|
|
90
93
|
Mike Schilli.
|
|
91
94
|
|
|
92
|
-
The algorithm is described in
|
|
93
|
-
|
|
95
|
+
The algorithm is described in _A Fast Algorithm for Computing Longest Common
|
|
96
|
+
Subsequences_, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor
|
|
94
97
|
improvements to improve the speed. A simplified description of the algorithm,
|
|
95
98
|
originally written for the Perl version, was written by Mark-Jason Dominus.
|
|
96
99
|
|
|
@@ -101,5 +104,4 @@ originally written for the Perl version, was written by Mark-Jason Dominus.
|
|
|
101
104
|
[rubygems]: https://rubygems.org/gems/diff-lcs
|
|
102
105
|
[shield-ci]: https://img.shields.io/github/actions/workflow/status/halostatue/diff-lcs/ci.yml?style=for-the-badge "Build Status"
|
|
103
106
|
[shield-coveralls]: https://img.shields.io/coverallsCoverage/github/halostatue/diff-lcs?style=for-the-badge
|
|
104
|
-
[shield-gems]: https://img.shields.io/gem/v/diff-lcs?style=for-the-badge "Version"
|
|
105
107
|
[smalltalk]: ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
|
data/Rakefile
CHANGED
data/SECURITY.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# diff-lcs Security
|
|
1
|
+
# `diff-lcs` Security
|
|
2
2
|
|
|
3
3
|
## LLM-Generated Security Report Policy
|
|
4
4
|
|
|
5
|
-
Absolutely no security reports will be accepted that have been generated
|
|
6
|
-
agents.
|
|
5
|
+
Absolutely no security reports will be accepted that have been generated
|
|
6
|
+
solely by LLM agents. There must be a human that confirms the issue.
|
|
7
7
|
|
|
8
8
|
## Supported Versions
|
|
9
9
|
|
|
10
|
-
Security reports are accepted for the most recent major release, with a
|
|
11
|
-
window of support after the initial major release.
|
|
10
|
+
Security reports are accepted for the most recent major release, with a
|
|
11
|
+
limited window of support after the initial major release.
|
|
12
12
|
|
|
13
13
|
- Bug reports will be accepted up to three months after release.
|
|
14
14
|
- Security reports will be accepted up to six months after release.
|
data/lib/diff/lcs/array.rb
CHANGED
data/lib/diff/lcs/callbacks.rb
CHANGED
|
@@ -234,7 +234,7 @@ end
|
|
|
234
234
|
# old and new objects will be presented for both changed <strong>and unchanged</strong>
|
|
235
235
|
# objects. `nil` will be substituted for a discarded object.
|
|
236
236
|
#
|
|
237
|
-
# The
|
|
237
|
+
# The diff set produced by this callback, when provided to Diff::LCS#sdiff, will compute
|
|
238
238
|
# and display the necessary components to show two sequences and their minimized
|
|
239
239
|
# differences side by side, just like the Unix utility `sdiff`.
|
|
240
240
|
#
|
data/lib/diff/lcs/change.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Diff::LCS::ContextChange = Data.define(:action, :old_position, :old_element, :new_position, :new_element) # :nodoc:
|
|
3
|
+
require "diff/lcs/frozen_value"
|
|
5
4
|
|
|
6
5
|
# Represents a simplistic (non-contextual) change. Represents the removal or addition of
|
|
7
6
|
# an element from either the old or the new sequenced enumerable.
|
|
8
7
|
class Diff::LCS::Change
|
|
8
|
+
include Diff::LCS::FrozenValue
|
|
9
|
+
|
|
9
10
|
# The only actions valid for changes are '+' (add), '-' (delete), '=' (no change), '!'
|
|
10
11
|
# (changed), '<' (tail changes from first sequence), or '>' (tail changes from second
|
|
11
12
|
# sequence). The last two ('<>') are only found with Diff::LCS::diff and
|
|
@@ -14,23 +15,37 @@ class Diff::LCS::Change
|
|
|
14
15
|
|
|
15
16
|
def self.valid_action?(action) = VALID_ACTIONS.include?(action)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
MEMBERS = %i[action position element].freeze
|
|
19
|
+
private_constant :MEMBERS
|
|
20
|
+
|
|
21
|
+
# Returns the member names of a Change, in the order of its positional arguments.
|
|
22
|
+
def self.members = MEMBERS.dup
|
|
23
|
+
|
|
18
24
|
# Returns the action this Change represents.
|
|
19
|
-
|
|
25
|
+
attr_reader :action
|
|
20
26
|
|
|
21
|
-
##
|
|
22
27
|
# Returns the position of the Change.
|
|
23
|
-
|
|
28
|
+
attr_reader :position
|
|
24
29
|
|
|
25
|
-
##
|
|
26
30
|
# Returns the sequence element of the Change.
|
|
27
|
-
|
|
31
|
+
attr_reader :element
|
|
32
|
+
|
|
33
|
+
# :call-seq:
|
|
34
|
+
# new(action, position, element) -> change
|
|
35
|
+
# new(action:, position:, element:) -> change
|
|
36
|
+
#
|
|
37
|
+
# Returns a new frozen Change. `action` must be one of VALID_ACTIONS and `position`
|
|
38
|
+
# must be an Integer.
|
|
39
|
+
def initialize(action = NO_ARGUMENT, position = NO_ARGUMENT, element = NO_ARGUMENT)
|
|
40
|
+
action, position, element = arguments_to_values(action, position, element) if NO_ARGUMENT.equal?(element)
|
|
28
41
|
|
|
29
|
-
def initialize(action:, position:, element:)
|
|
30
42
|
fail "Invalid Change Action '#{action}'" unless Diff::LCS::Change.valid_action?(action)
|
|
31
43
|
fail "Invalid Position Type" unless position.is_a?(Integer)
|
|
32
44
|
|
|
33
|
-
|
|
45
|
+
@action = action
|
|
46
|
+
@position = position
|
|
47
|
+
@element = element
|
|
48
|
+
freeze
|
|
34
49
|
end
|
|
35
50
|
|
|
36
51
|
def inspect(*_args) = "#<#{self.class}: #{to_a.inspect}>"
|
|
@@ -41,6 +56,12 @@ class Diff::LCS::Change
|
|
|
41
56
|
|
|
42
57
|
def deconstruct_keys(_) = {action:, position:, element:}
|
|
43
58
|
|
|
59
|
+
protected def values # :nodoc:
|
|
60
|
+
[@action, @position, @element]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private def member_names = MEMBERS
|
|
64
|
+
|
|
44
65
|
def self.from_a(arr)
|
|
45
66
|
case arr
|
|
46
67
|
in [action, [old_position, old_element], [new_position, new_element]]
|
|
@@ -84,32 +105,51 @@ end
|
|
|
84
105
|
# Represents a contextual change. Contains the position and values of the elements in the
|
|
85
106
|
# old and the new sequenced enumerable values as well as the action taken.
|
|
86
107
|
class Diff::LCS::ContextChange
|
|
87
|
-
|
|
108
|
+
include Diff::LCS::FrozenValue
|
|
109
|
+
|
|
110
|
+
MEMBERS = %i[action old_position old_element new_position new_element].freeze
|
|
111
|
+
private_constant :MEMBERS
|
|
112
|
+
|
|
113
|
+
# Returns the member names of a ContextChange, in the order of its positional arguments.
|
|
114
|
+
def self.members = MEMBERS.dup
|
|
115
|
+
|
|
88
116
|
# Returns the action this Change represents.
|
|
89
|
-
|
|
117
|
+
attr_reader :action
|
|
90
118
|
|
|
91
|
-
##
|
|
92
119
|
# Returns the old position being changed.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
##
|
|
96
|
-
# Returns the new position being changed.
|
|
97
|
-
# :attr_reader: new_position
|
|
120
|
+
attr_reader :old_position
|
|
98
121
|
|
|
99
|
-
##
|
|
100
122
|
# Returns the old element being changed.
|
|
101
|
-
|
|
123
|
+
attr_reader :old_element
|
|
124
|
+
|
|
125
|
+
# Returns the new position being changed.
|
|
126
|
+
attr_reader :new_position
|
|
102
127
|
|
|
103
|
-
##
|
|
104
128
|
# Returns the new element being changed.
|
|
105
|
-
|
|
129
|
+
attr_reader :new_element
|
|
130
|
+
|
|
131
|
+
# Returns a new frozen ContextChange. `action` must be one of Change::VALID_ACTIONS,
|
|
132
|
+
# and each position must be an Integer or `nil`.
|
|
133
|
+
#
|
|
134
|
+
# :call-seq:
|
|
135
|
+
# new(action, old_position, old_element, new_position, new_element) -> context_change
|
|
136
|
+
# new(action:, old_position:, old_element:, new_position:, new_element:) -> context_change
|
|
137
|
+
def initialize(action = NO_ARGUMENT, old_position = NO_ARGUMENT, old_element = NO_ARGUMENT, new_position = NO_ARGUMENT, new_element = NO_ARGUMENT)
|
|
138
|
+
if NO_ARGUMENT.equal?(new_element)
|
|
139
|
+
action, old_position, old_element, new_position, new_element =
|
|
140
|
+
arguments_to_values(action, old_position, old_element, new_position, new_element)
|
|
141
|
+
end
|
|
106
142
|
|
|
107
|
-
def initialize(action:, old_position:, old_element:, new_position:, new_element:)
|
|
108
143
|
fail "Invalid Change Action '#{action}'" unless Diff::LCS::Change.valid_action?(action)
|
|
109
144
|
fail "Invalid (Old) Position Type" unless old_position.nil? || old_position.is_a?(Integer)
|
|
110
145
|
fail "Invalid (New) Position Type" unless new_position.nil? || new_position.is_a?(Integer)
|
|
111
146
|
|
|
112
|
-
|
|
147
|
+
@action = action
|
|
148
|
+
@old_position = old_position
|
|
149
|
+
@old_element = old_element
|
|
150
|
+
@new_position = new_position
|
|
151
|
+
@new_element = new_element
|
|
152
|
+
freeze
|
|
113
153
|
end
|
|
114
154
|
|
|
115
155
|
def to_a = [action, [old_position, old_element], [new_position, new_element]]
|
|
@@ -118,20 +158,22 @@ class Diff::LCS::ContextChange
|
|
|
118
158
|
|
|
119
159
|
def deconstruct_keys(_) = {action:, old_position:, old_element:, new_position:, new_element:}
|
|
120
160
|
|
|
161
|
+
protected def values # :nodoc:
|
|
162
|
+
[@action, @old_position, @old_element, @new_position, @new_element]
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
private def member_names = MEMBERS
|
|
166
|
+
|
|
121
167
|
def self.from_a(arr) = Diff::LCS::Change.from_a(arr)
|
|
122
168
|
|
|
123
169
|
# Simplifies a context change for use in some diff callbacks. '<' actions are converted
|
|
124
170
|
# to '-' and '>' actions are converted to '+'.
|
|
125
171
|
def self.simplify(event)
|
|
126
172
|
case event.action
|
|
127
|
-
when "-"
|
|
128
|
-
event.
|
|
129
|
-
when "
|
|
130
|
-
event.
|
|
131
|
-
when "+"
|
|
132
|
-
event.with(old_element: nil)
|
|
133
|
-
when ">"
|
|
134
|
-
event.with(action: "+", old_element: nil)
|
|
173
|
+
when "-", "<"
|
|
174
|
+
event.class.new("-", event.old_position, event.old_element, event.new_position, nil)
|
|
175
|
+
when "+", ">"
|
|
176
|
+
event.class.new("+", event.old_position, nil, event.new_position, event.new_element)
|
|
135
177
|
else
|
|
136
178
|
event
|
|
137
179
|
end
|