diff-lcs 1.3 → 1.6.2

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.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +518 -0
  3. data/CODE_OF_CONDUCT.md +128 -0
  4. data/CONTRIBUTING.md +71 -0
  5. data/CONTRIBUTORS.md +49 -0
  6. data/{License.md → LICENCE.md} +21 -20
  7. data/Manifest.txt +84 -6
  8. data/README.md +92 -0
  9. data/Rakefile +104 -46
  10. data/SECURITY.md +41 -0
  11. data/bin/htmldiff +9 -6
  12. data/bin/ldiff +4 -1
  13. data/docs/artistic.txt +1 -1
  14. data/lib/diff/lcs/array.rb +2 -2
  15. data/lib/diff/lcs/backports.rb +13 -0
  16. data/lib/diff/lcs/block.rb +5 -5
  17. data/lib/diff/lcs/callbacks.rb +22 -17
  18. data/lib/diff/lcs/change.rb +44 -51
  19. data/lib/diff/lcs/htmldiff.rb +25 -14
  20. data/lib/diff/lcs/hunk.rb +174 -71
  21. data/lib/diff/lcs/internals.rb +57 -56
  22. data/lib/diff/lcs/ldiff.rb +101 -79
  23. data/lib/diff/lcs/string.rb +1 -1
  24. data/lib/diff/lcs/version.rb +7 -0
  25. data/lib/diff/lcs.rb +229 -212
  26. data/lib/diff-lcs.rb +2 -2
  27. data/mise.toml +5 -0
  28. data/spec/change_spec.rb +58 -34
  29. data/spec/diff_spec.rb +13 -9
  30. data/spec/fixtures/123_x +2 -0
  31. data/spec/fixtures/456_x +2 -0
  32. data/spec/fixtures/aX +1 -0
  33. data/spec/fixtures/bXaX +1 -0
  34. data/spec/fixtures/empty +0 -0
  35. data/spec/fixtures/file1.bin +0 -0
  36. data/spec/fixtures/file2.bin +0 -0
  37. data/spec/fixtures/four_lines +4 -0
  38. data/spec/fixtures/four_lines_with_missing_new_line +4 -0
  39. data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  40. data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  41. data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  42. data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  43. data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
  44. data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
  45. data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  46. data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  47. data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  48. data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  49. data/spec/fixtures/ldiff/output.diff +4 -0
  50. data/spec/fixtures/ldiff/output.diff-c +7 -0
  51. data/spec/fixtures/ldiff/output.diff-e +3 -0
  52. data/spec/fixtures/ldiff/output.diff-f +3 -0
  53. data/spec/fixtures/ldiff/output.diff-u +5 -0
  54. data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
  55. data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
  56. data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
  57. data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
  58. data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
  59. data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
  60. data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
  61. data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
  62. data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
  63. data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
  64. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  65. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  66. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  67. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  68. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  69. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  70. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  71. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  72. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  73. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  74. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  75. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  76. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  77. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  78. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  79. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  80. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  81. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  82. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  83. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  84. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  85. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  86. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  87. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
  88. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
  89. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  90. data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  91. data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  92. data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  93. data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  94. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  95. data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  96. data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  97. data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  98. data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  99. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  100. data/spec/fixtures/new-chef +4 -0
  101. data/spec/fixtures/new-chef2 +17 -0
  102. data/spec/fixtures/old-chef +4 -0
  103. data/spec/fixtures/old-chef2 +14 -0
  104. data/spec/hunk_spec.rb +49 -38
  105. data/spec/issues_spec.rb +132 -21
  106. data/spec/lcs_spec.rb +3 -3
  107. data/spec/ldiff_spec.rb +83 -30
  108. data/spec/patch_spec.rb +14 -20
  109. data/spec/sdiff_spec.rb +83 -81
  110. data/spec/spec_helper.rb +220 -165
  111. data/spec/traverse_balanced_spec.rb +138 -136
  112. data/spec/traverse_sequences_spec.rb +7 -9
  113. metadata +127 -77
  114. data/Code-of-Conduct.md +0 -74
  115. data/Contributing.md +0 -83
  116. data/History.md +0 -220
  117. data/README.rdoc +0 -84
  118. data/autotest/discover.rb +0 -1
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,71 @@
1
+ # Contributing
2
+
3
+ Contribution to diff-lcs is encouraged in any form: a bug report, a feature
4
+ request, or code contributions. There are a few DOs and DON'Ts for
5
+ contributions.
6
+
7
+ - DO:
8
+
9
+ - Keep the coding style that already exists for any updated Ruby code (support
10
+ or otherwise). I use [Standard Ruby][standardrb] for linting and formatting.
11
+
12
+ - Use thoughtfully-named topic branches for contributions. Rebase your commits
13
+ into logical chunks as necessary.
14
+
15
+ - Use [quality commit messages][qcm].
16
+
17
+ - Add your name or GitHub handle to `CONTRIBUTORS.md` and a record in the
18
+ `CHANGELOG.md` as a separate commit from your main change. (Follow the style
19
+ in the `CHANGELOG.md` and provide a link to your PR.)
20
+
21
+ - Add or update tests as appropriate for your change. The test suite is
22
+ written in [RSpec][rspec].
23
+
24
+ - Add or update documentation as appropriate for your change. The
25
+ documentation is RDoc; diff-lcs does not use extensions that may be present
26
+ in alternative documentation generators.
27
+
28
+ - DO NOT:
29
+
30
+ - Modify `VERSION` in `lib/diff/lcs/version.rb`. When your patch is accepted
31
+ and a release is made, the version will be updated at that point.
32
+
33
+ - Modify `diff-lcs.gemspec`; it is a generated file. (You _may_ use
34
+ `rake gemspec` to regenerate it if your change involves metadata related to
35
+ gem itself).
36
+
37
+ - Modify the `Gemfile`.
38
+
39
+ ## Test Dependencies
40
+
41
+ diff-lcs uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it adds
42
+ a number of rake tasks. You will mostly be interested in `rake`, which runs
43
+ tests in the same way that `rake spec` does.
44
+
45
+ To assist with the installation of the development dependencies for diff-lcs, I
46
+ have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file.
47
+ `minitar.gemspec` file. This will permit you to use `bundle install` to install
48
+ the dependencies.
49
+
50
+ You can run tests with code coverage analysis by running `rake spec:coverage`.
51
+
52
+ ## Workflow
53
+
54
+ Here's the most direct way to get your work merged into the project:
55
+
56
+ - Fork the project.
57
+ - Clone your fork (`git clone git://github.com/<username>/diff-lcs.git`).
58
+ - Create a topic branch to contain your change
59
+ (`git checkout -b my_awesome_feature`).
60
+ - Hack away, add tests. Not necessarily in that order.
61
+ - Make sure everything still passes by running `rake`.
62
+ - If necessary, rebase your commits into logical chunks, without errors.
63
+ - Push the branch up (`git push origin my_awesome_feature`).
64
+ - Create a pull request against halostatue/diff-lcs and describe what your
65
+ change does and the why you think it should be merged.
66
+
67
+ [hoe]: https://github.com/seattlerb/hoe
68
+ [qcm]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
69
+ [release-gem]: https://github.com/rubygems/release-gem
70
+ [rspec]: http://rspec.info/documentation/
71
+ [standardrb]: https://github.com/standardrb/standard
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,49 @@
1
+ # Contributors
2
+
3
+ - Austin Ziegler (@halostatue) created diff-lcs.
4
+
5
+ Thanks to everyone else who has contributed to diff-lcs over the years:
6
+
7
+ - @ginriki
8
+ - @joshbronson
9
+ - @kevinmook
10
+ - @mckaz
11
+ - Akinori Musha
12
+ - Artem Ignatyev
13
+ - Brandon Fish
14
+ - Baptiste Courtois (@annih)
15
+ - Camille Drapier
16
+ - Cédric Boutillier
17
+ - @earlopain
18
+ - Gregg Kellogg
19
+ - Jagdeep Singh
20
+ - Jason Gladish
21
+ - Jon Rowe
22
+ - Josef Strzibny
23
+ - Josep (@apuratepp)
24
+ - Josh Bronson
25
+ - Jun Aruga
26
+ - Justin Steele
27
+ - Kenichi Kamiya
28
+ - Kensuke Nagae
29
+ - Kevin Ansfield
30
+ - Koichi Ito
31
+ - Mark Friedgan
32
+ - Masato Nakamura
33
+ - Mark Young
34
+ - Michael Granger
35
+ - Myron Marston
36
+ - Nicolas Leger
37
+ - Oleg Orlov
38
+ - Patrick Linnane
39
+ - Paul Kunysch
40
+ - Pete Higgins
41
+ - Peter Goldstein
42
+ - Peter Wagenet
43
+ - Philippe Lafoucrière
44
+ - Ryan Lovelett
45
+ - Scott Steele
46
+ - Simon Courtois
47
+ - Tien (@tiendo1011)
48
+ - Tomas Jura
49
+ - Vít Ondruch
@@ -1,39 +1,40 @@
1
- == License
1
+ # Licence
2
2
 
3
3
  This software is available under three licenses: the GNU GPL version 2 (or at
4
4
  your option, a later version), the Perl Artistic license, or the MIT license.
5
5
  Note that my preference for licensing is the MIT license, but Algorithm::Diff
6
- was dually originally licensed with the Perl Artistic and the GNU GPL ("the
7
- same terms as Perl itself") and given that the Ruby implementation originally
8
- hewed pretty closely to the Perl version, I must maintain the additional
9
- licensing terms.
6
+ was dually originally licensed with the Perl Artistic and the GNU GPL ("the same
7
+ terms as Perl itself") and given that the Ruby implementation originally hewed
8
+ pretty closely to the Perl version, I must maintain the additional licensing
9
+ terms.
10
10
 
11
- * Copyright 2004–2013 Austin Ziegler.
12
- * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
11
+ - Copyright 2004–2025 Austin Ziegler and contributors.
12
+ - Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
13
13
  Mario I. Wolczko.
14
14
 
15
- === MIT License
15
+ ## MIT License
16
16
 
17
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of
18
18
  this software and associated documentation files (the "Software"), to deal in
19
19
  the Software without restriction, including without limitation the rights to
20
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
21
- of the Software, and to permit persons to whom the Software is furnished to do
22
- so, subject to the following conditions:
20
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
21
+ the Software, and to permit persons to whom the Software is furnished to do so,
22
+ subject to the following conditions:
23
23
 
24
24
  The above copyright notice and this permission notice shall be included in all
25
25
  copies or substantial portions of the Software.
26
26
 
27
27
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
34
-
35
- === Perl Artistic License (version 2)
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
29
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
30
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
+
34
+ ## Perl Artistic License
35
+
36
36
  See the file docs/artistic.txt in the main distribution.
37
37
 
38
- === GNU GPL version 2
38
+ ## GNU GPL version 2
39
+
39
40
  See the file docs/COPYING.txt in the main distribution.
data/Manifest.txt CHANGED
@@ -1,12 +1,13 @@
1
1
  .rspec
2
- Code-of-Conduct.md
3
- Contributing.md
4
- History.md
5
- License.md
2
+ CHANGELOG.md
3
+ CODE_OF_CONDUCT.md
4
+ CONTRIBUTING.md
5
+ CONTRIBUTORS.md
6
+ LICENCE.md
6
7
  Manifest.txt
7
- README.rdoc
8
+ README.md
8
9
  Rakefile
9
- autotest/discover.rb
10
+ SECURITY.md
10
11
  bin/htmldiff
11
12
  bin/ldiff
12
13
  docs/COPYING.txt
@@ -14,6 +15,7 @@ docs/artistic.txt
14
15
  lib/diff-lcs.rb
15
16
  lib/diff/lcs.rb
16
17
  lib/diff/lcs/array.rb
18
+ lib/diff/lcs/backports.rb
17
19
  lib/diff/lcs/block.rb
18
20
  lib/diff/lcs/callbacks.rb
19
21
  lib/diff/lcs/change.rb
@@ -22,10 +24,86 @@ lib/diff/lcs/hunk.rb
22
24
  lib/diff/lcs/internals.rb
23
25
  lib/diff/lcs/ldiff.rb
24
26
  lib/diff/lcs/string.rb
27
+ lib/diff/lcs/version.rb
28
+ mise.toml
25
29
  spec/change_spec.rb
26
30
  spec/diff_spec.rb
31
+ spec/fixtures/123_x
32
+ spec/fixtures/456_x
33
+ spec/fixtures/aX
34
+ spec/fixtures/bXaX
27
35
  spec/fixtures/ds1.csv
28
36
  spec/fixtures/ds2.csv
37
+ spec/fixtures/empty
38
+ spec/fixtures/file1.bin
39
+ spec/fixtures/file2.bin
40
+ spec/fixtures/four_lines
41
+ spec/fixtures/four_lines_with_missing_new_line
42
+ spec/fixtures/ldiff/diff.missing_new_line1-e
43
+ spec/fixtures/ldiff/diff.missing_new_line1-f
44
+ spec/fixtures/ldiff/diff.missing_new_line2-e
45
+ spec/fixtures/ldiff/diff.missing_new_line2-f
46
+ spec/fixtures/ldiff/error.diff.chef-e
47
+ spec/fixtures/ldiff/error.diff.chef-f
48
+ spec/fixtures/ldiff/error.diff.missing_new_line1-e
49
+ spec/fixtures/ldiff/error.diff.missing_new_line1-f
50
+ spec/fixtures/ldiff/error.diff.missing_new_line2-e
51
+ spec/fixtures/ldiff/error.diff.missing_new_line2-f
52
+ spec/fixtures/ldiff/output.diff
53
+ spec/fixtures/ldiff/output.diff-c
54
+ spec/fixtures/ldiff/output.diff-e
55
+ spec/fixtures/ldiff/output.diff-f
56
+ spec/fixtures/ldiff/output.diff-u
57
+ spec/fixtures/ldiff/output.diff.bin1
58
+ spec/fixtures/ldiff/output.diff.bin1-c
59
+ spec/fixtures/ldiff/output.diff.bin1-e
60
+ spec/fixtures/ldiff/output.diff.bin1-f
61
+ spec/fixtures/ldiff/output.diff.bin1-u
62
+ spec/fixtures/ldiff/output.diff.bin2
63
+ spec/fixtures/ldiff/output.diff.bin2-c
64
+ spec/fixtures/ldiff/output.diff.bin2-e
65
+ spec/fixtures/ldiff/output.diff.bin2-f
66
+ spec/fixtures/ldiff/output.diff.bin2-u
67
+ spec/fixtures/ldiff/output.diff.chef
68
+ spec/fixtures/ldiff/output.diff.chef-c
69
+ spec/fixtures/ldiff/output.diff.chef-e
70
+ spec/fixtures/ldiff/output.diff.chef-f
71
+ spec/fixtures/ldiff/output.diff.chef-u
72
+ spec/fixtures/ldiff/output.diff.chef2
73
+ spec/fixtures/ldiff/output.diff.chef2-c
74
+ spec/fixtures/ldiff/output.diff.chef2-d
75
+ spec/fixtures/ldiff/output.diff.chef2-e
76
+ spec/fixtures/ldiff/output.diff.chef2-f
77
+ spec/fixtures/ldiff/output.diff.chef2-u
78
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines
79
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c
80
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e
81
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f
82
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u
83
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty
84
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c
85
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e
86
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f
87
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u
88
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context
89
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-c
90
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-e
91
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-f
92
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-u
93
+ spec/fixtures/ldiff/output.diff.missing_new_line1
94
+ spec/fixtures/ldiff/output.diff.missing_new_line1-c
95
+ spec/fixtures/ldiff/output.diff.missing_new_line1-e
96
+ spec/fixtures/ldiff/output.diff.missing_new_line1-f
97
+ spec/fixtures/ldiff/output.diff.missing_new_line1-u
98
+ spec/fixtures/ldiff/output.diff.missing_new_line2
99
+ spec/fixtures/ldiff/output.diff.missing_new_line2-c
100
+ spec/fixtures/ldiff/output.diff.missing_new_line2-e
101
+ spec/fixtures/ldiff/output.diff.missing_new_line2-f
102
+ spec/fixtures/ldiff/output.diff.missing_new_line2-u
103
+ spec/fixtures/new-chef
104
+ spec/fixtures/new-chef2
105
+ spec/fixtures/old-chef
106
+ spec/fixtures/old-chef2
29
107
  spec/hunk_spec.rb
30
108
  spec/issues_spec.rb
31
109
  spec/lcs_spec.rb
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Diff::LCS
2
+
3
+ - home :: https://github.com/halostatue/diff-lcs
4
+ - changelog :: https://github.com/halostatue/diff-lcs/blob/main/CHANGELOG.md
5
+ - code :: https://github.com/halostatue/diff-lcs
6
+ - bugs :: https://github.com/halostatue/diff-lcs/issues
7
+ - rdoc :: http://rubydoc.info/github/halostatue/diff-lcs
8
+
9
+ <a href="https://github.com/halostatue/diff-lcs/actions">
10
+ <img src="https://github.com/halostatue/diff-lcs/workflows/CI/badge.svg" />
11
+ </a>
12
+
13
+ ## Description
14
+
15
+ Diff::LCS computes the difference between two Enumerable sequences using the
16
+ McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
17
+ to create a simple HTML diff output format and a standard diff-like tool.
18
+
19
+ This is release 1.6.1, providing a simple extension that allows for
20
+ Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number
21
+ of formatting issues.
22
+
23
+ Ruby versions below 2.5 are soft-deprecated, which means that older versions are
24
+ no longer part of the CI test suite. If any changes have been introduced that
25
+ break those versions, bug reports and patches will be accepted, but it will be
26
+ up to the reporter to verify any fixes prior to release. The next major release
27
+ will completely break compatibility.
28
+
29
+ ## Synopsis
30
+
31
+ Using this module is quite simple. By default, Diff::LCS does not extend objects
32
+ with the Diff::LCS interface, but will be called as if it were a function:
33
+
34
+ ```ruby
35
+ require 'diff/lcs'
36
+
37
+ seq1 = %w(a b c e h j l m n p)
38
+ seq2 = %w(b c d e f j k l m r s t)
39
+
40
+ lcs = Diff::LCS.LCS(seq1, seq2)
41
+ diffs = Diff::LCS.diff(seq1, seq2)
42
+ sdiff = Diff::LCS.sdiff(seq1, seq2)
43
+ seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
44
+ bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
45
+ seq2 == Diff::LCS.patch!(seq1, diffs)
46
+ seq1 == Diff::LCS.unpatch!(seq2, diffs)
47
+ seq2 == Diff::LCS.patch!(seq1, sdiff)
48
+ seq1 == Diff::LCS.unpatch!(seq2, sdiff)
49
+ ```
50
+
51
+ Objects can be extended with Diff::LCS:
52
+
53
+ ```ruby
54
+ seq1.extend(Diff::LCS)
55
+ lcs = seq1.lcs(seq2)
56
+ diffs = seq1.diff(seq2)
57
+ sdiff = seq1.sdiff(seq2)
58
+ seq = seq1.traverse_sequences(seq2, callback_obj)
59
+ bal = seq1.traverse_balanced(seq2, callback_obj)
60
+ seq2 == seq1.patch!(diffs)
61
+ seq1 == seq2.unpatch!(diffs)
62
+ seq2 == seq1.patch!(sdiff)
63
+ seq1 == seq2.unpatch!(sdiff)
64
+ ```
65
+
66
+ By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be
67
+ extended for use this way.
68
+
69
+ Note that Diff::LCS requires a sequenced enumerable container, which means that
70
+ the order of enumeration is both predictable and consistent for the same set of
71
+ data. While it is theoretically possible to generate a diff for an unordered
72
+ hash, it will only be meaningful if the enumeration of the hashes is consistent.
73
+ In general, this will mean that containers that behave like String or Array will
74
+ perform best.
75
+
76
+ ## History
77
+
78
+ Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest
79
+ common subsequence (LCS) algorithm to compute intelligent differences between
80
+ two sequenced enumerable containers. The implementation is based on Mario I.
81
+ Wolczko's [Smalltalk version 1.2][smalltalk] (1993) and Ned Konz's Perl version
82
+ [Algorithm::Diff 1.15][perl]. `Diff::LCS#sdiff` and
83
+ `Diff::LCS#traverse_balanced` were originally written for the Perl version by
84
+ Mike Schilli.
85
+
86
+ The algorithm is described in <em>A Fast Algorithm for Computing Longest Common
87
+ Subsequences</em>, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor
88
+ improvements to improve the speed. A simplified description of the algorithm,
89
+ originally written for the Perl version, was written by Mark-Jason Dominus.
90
+
91
+ [smalltalk]: ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
92
+ [perl]: http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/
data/Rakefile CHANGED
@@ -1,57 +1,115 @@
1
- # -*- ruby encoding: utf-8 -*-
2
-
3
- require 'rubygems'
4
- require 'rspec'
5
- require 'hoe'
6
-
7
- Hoe.plugin :bundler
8
- Hoe.plugin :doofus
9
- Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
10
- Hoe.plugin :gemspec2
11
- Hoe.plugin :git
12
- Hoe.plugin :travis
13
-
14
- spec = Hoe.spec 'diff-lcs' do
15
- developer('Austin Ziegler', 'halostatue@gmail.com')
16
-
17
- require_ruby_version '>= 1.8'
18
-
19
- self.history_file = 'History.md'
20
- self.readme_file = 'README.rdoc'
21
- self.licenses = [ 'MIT', 'Artistic-2.0', 'GPL-2.0+' ]
22
-
23
- extra_dev_deps << ['hoe-doofus', '~> 1.0']
24
- extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
25
- extra_dev_deps << ['hoe-git', '~> 1.6']
26
- extra_dev_deps << ['hoe-rubygems', '~> 1.0']
27
- extra_dev_deps << ['hoe-travis', '~> 1.2']
28
- extra_dev_deps << ['rspec', '>= 2.0', '< 4']
29
- extra_dev_deps << ['rake', '>= 10.0', '< 12']
30
- extra_dev_deps << ['rdoc', '>= 0']
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "rspec/core/rake_task"
4
+ require "hoe"
5
+ require "rake/clean"
6
+
7
+ MAINTENANCE = ENV["MAINTENANCE"] == "true"
8
+ BUILD_DOCS = MAINTENANCE || ENV["DOCS"] == "true"
9
+ TRUSTED_RELEASE = ENV["rubygems_release_gem"] == "true"
10
+
11
+ Hoe.plugin :halostatue
12
+ Hoe.plugin :rubygems
13
+
14
+ Hoe.plugins.delete :debug
15
+ Hoe.plugins.delete :newb
16
+ Hoe.plugins.delete :signing
17
+ Hoe.plugins.delete :publish unless BUILD_DOCS
18
+
19
+ if RUBY_VERSION < "1.9"
20
+ class Array # :nodoc:
21
+ def to_h
22
+ Hash[*flatten(1)]
23
+ end
24
+ end
25
+
26
+ class Gem::Specification # :nodoc:
27
+ def metadata=(*)
28
+ end
29
+
30
+ def default_value(*)
31
+ end
32
+ end
33
+
34
+ class Object # :nodoc:
35
+ def caller_locations(*)
36
+ []
37
+ end
38
+ end
39
+ end
40
+
41
+ _spec = Hoe.spec "diff-lcs" do
42
+ developer("Austin Ziegler", "halostatue@gmail.com")
43
+
44
+ self.trusted_release = TRUSTED_RELEASE
45
+
46
+ require_ruby_version ">= 1.8"
47
+
48
+ self.history_file = "CHANGELOG.md"
49
+ self.readme_file = "README.md"
50
+ self.licenses = ["MIT", "Artistic-1.0-Perl", "GPL-2.0-or-later"]
51
+
52
+ spec_extras[:metadata] = ->(val) {
53
+ val["rubygems_mfa_required"] = "true"
54
+ }
55
+
56
+ extra_dev_deps << ["hoe", "~> 4.0"]
57
+ extra_dev_deps << ["hoe-halostatue", "~> 2.0"]
58
+ extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
59
+ extra_dev_deps << ["rspec", ">= 2.0", "< 4"]
60
+ extra_dev_deps << ["rake", ">= 10.0", "< 14"]
61
+ extra_dev_deps << ["rdoc", ">= 6.3.1", "< 7"]
31
62
  end
32
63
 
33
- unless Rake::Task.task_defined? :test
34
- task :test => :spec
35
- Rake::Task['travis'].prerequisites.replace(%w(spec))
64
+ if BUILD_DOCS
65
+ rake_tasks = Rake.application.instance_variable_get(:@tasks)
66
+ tasks = ["publish_docs", "publish_on_announce", "debug_email", "post_blog", "announce"]
67
+ tasks.each do |task|
68
+ rake_tasks.delete(task)
69
+ end
36
70
  end
37
71
 
38
- if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby'
39
- namespace :spec do
40
- task :coveralls do
41
- if ENV['CI'] or ENV['TRAVIS']
42
- ENV['COVERALLS'] = 'yes'
43
- Rake::Task['spec'].execute
44
- else
45
- Rake::Task['spec:coverage'].execute
46
- end
47
- end
72
+ desc "Run all specifications"
73
+ RSpec::Core::RakeTask.new(:spec) do |t|
74
+ rspec_dirs = %w[spec lib].join(":")
75
+ t.rspec_opts = ["-I#{rspec_dirs}"]
76
+ end
48
77
 
78
+ task :version do
79
+ require "diff/lcs/version"
80
+ puts Diff::LCS::VERSION
81
+ end
82
+
83
+ Rake::Task["spec"].actions.uniq! { |a| a.source_location }
84
+
85
+ # standard:disable Style/HashSyntax
86
+ task :default => :spec unless Rake::Task["default"].prereqs.include?("spec")
87
+ task :test => :spec unless Rake::Task["test"].prereqs.include?("spec")
88
+ # standard:enable Style/HashSyntax
89
+
90
+ if RUBY_VERSION >= "3.0" && RUBY_ENGINE == "ruby"
91
+ namespace :spec do
49
92
  desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed."
50
93
  task :coverage do
51
- ENV['COVERAGE'] = 'yes'
52
- Rake::Task['spec'].execute
94
+ ENV["COVERAGE"] = "true"
95
+ Rake::Task["spec"].execute
53
96
  end
54
97
  end
98
+ end
99
+
100
+ if MAINTENANCE
101
+ task ruby18: :package do
102
+ require "diff/lcs/version"
103
+ # standard:disable Layout/HeredocIndentation
104
+ puts <<-MESSAGE
105
+ You are starting a barebones Ruby 1.8 docker environment for testing.
106
+ A snapshot package has been built, so install it with:
55
107
 
56
- # Rake::Task['travis'].prerequisites.replace(%w(spec:coveralls))
108
+ cd diff-lcs
109
+ gem install pkg/diff-lcs-#{Diff::LCS::VERSION}
110
+
111
+ MESSAGE
112
+ # standard:enable Layout/HeredocIndentation
113
+ sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
114
+ end
57
115
  end
data/SECURITY.md ADDED
@@ -0,0 +1,41 @@
1
+ # diff-lcs Security
2
+
3
+ ## Supported Versions
4
+
5
+ Security reports are accepted for the most recent major release and the previous
6
+ version for a limited time after the initial major release version. After a
7
+ major release, the previous version will receive full support for six months and
8
+ security support for an additional six months (for a total of twelve months).
9
+
10
+ Because diff-lcs 1.x supports a wide range of Ruby versions, security reports
11
+ will only be accepted when they can be demonstrated on Ruby 3.1 or higher.
12
+
13
+ > [!information]
14
+ >
15
+ > There will be a diff-lcs 2.0 released in 2025 which narrows support to modern
16
+ > versions of Ruby only.
17
+ >
18
+ > | Release Date | Support Ends | Security Support Ends |
19
+ > | ------------ | ------------ | --------------------- |
20
+ > | 2025 | +6 months | +12 months |
21
+ >
22
+ > If the 2.0.0 release happens on 2025-07-01, regular support for diff-lcs 1.x
23
+ > will end on 2026-12-31 and security support for diff-lcs 1.x will end on
24
+ > 2026-06-30.
25
+
26
+ ## Reporting a Vulnerability
27
+
28
+ By preference, use the [Tidelift security contact][tidelift]. Tidelift will
29
+ coordinate the fix and disclosure.
30
+
31
+ Alternatively, Send an email to [diff-lcs@halostatue.ca][email] with the text
32
+ `Diff::LCS` in the subject. Emails sent to this address should be encrypted
33
+ using [age][age] with the following public key:
34
+
35
+ ```
36
+ age1fc6ngxmn02m62fej5cl30lrvwmxn4k3q2atqu53aatekmnqfwumqj4g93w
37
+ ```
38
+
39
+ [tidelift]: https://tidelift.com/security
40
+ [email]: mailto:diff-lcs@halostatue.ca
41
+ [age]: https://github.com/FiloSottile/age
data/bin/htmldiff CHANGED
@@ -1,17 +1,18 @@
1
- #!ruby -w
1
+ #! /usr/bin/env ruby -w
2
+ # frozen_string_literal: true
2
3
 
3
- require 'diff/lcs'
4
- require 'diff/lcs/htmldiff'
4
+ require "diff/lcs"
5
+ require "diff/lcs/htmldiff"
5
6
 
6
7
  begin
7
- require 'text/format'
8
+ require "text/format"
8
9
  rescue LoadError
9
10
  Diff::LCS::HTMLDiff.can_expand_tabs = false
10
11
  end
11
12
 
12
13
  if ARGV.size < 2 or ARGV.size > 3
13
- $stderr.puts "usage: #{File.basename($0)} old new [output.html]"
14
- $stderr.puts " #{File.basename($0)} old new > output.html"
14
+ warn "usage: #{File.basename($0)} old new [output.html]"
15
+ warn " #{File.basename($0)} old new > output.html"
15
16
  exit 127
16
17
  end
17
18
 
@@ -30,3 +31,5 @@ if ARGV[2]
30
31
  else
31
32
  htmldiff.run
32
33
  end
34
+
35
+ # vim: ft=ruby
data/bin/ldiff CHANGED
@@ -1,6 +1,9 @@
1
- #!ruby -w
1
+ #! /usr/bin/env ruby -w
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'diff/lcs'
4
5
  require 'diff/lcs/ldiff'
5
6
 
6
7
  exit Diff::LCS::Ldiff.run(ARGV)
8
+
9
+ # vim: ft=ruby
data/docs/artistic.txt CHANGED
@@ -122,6 +122,6 @@ products derived from this software without specific prior written permission.
122
122
 
123
123
  10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
124
124
  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
125
- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
125
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
126
126
 
127
127
  The End
@@ -1,6 +1,6 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'diff/lcs'
3
+ require "diff/lcs"
4
4
 
5
5
  class Array
6
6
  include Diff::LCS
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless 0.respond_to?(:positive?)
4
+ class Fixnum # standard:disable Lint/UnifiedInteger
5
+ def positive?
6
+ self > 0
7
+ end
8
+
9
+ def negative?
10
+ self < 0
11
+ end
12
+ end
13
+ end