diff-lcs-1.5.1/0000755000004100000410000000000014571064670013247 5ustar www-datawww-datadiff-lcs-1.5.1/Manifest.txt0000644000004100000410000000262614571064670015564 0ustar www-datawww-data.rspec Code-of-Conduct.md Contributing.md History.md License.md Manifest.txt README.rdoc Rakefile bin/htmldiff bin/ldiff docs/COPYING.txt docs/artistic.txt lib/diff-lcs.rb lib/diff/lcs.rb lib/diff/lcs/array.rb lib/diff/lcs/backports.rb lib/diff/lcs/block.rb lib/diff/lcs/callbacks.rb lib/diff/lcs/change.rb lib/diff/lcs/htmldiff.rb lib/diff/lcs/hunk.rb lib/diff/lcs/internals.rb lib/diff/lcs/ldiff.rb lib/diff/lcs/string.rb spec/change_spec.rb spec/diff_spec.rb spec/fixtures/aX spec/fixtures/bXaX spec/fixtures/ds1.csv spec/fixtures/ds2.csv spec/fixtures/ldiff/output.diff spec/fixtures/ldiff/output.diff-c spec/fixtures/ldiff/output.diff-e spec/fixtures/ldiff/output.diff-f spec/fixtures/ldiff/output.diff-u spec/fixtures/ldiff/output.diff.chef spec/fixtures/ldiff/output.diff.chef-c spec/fixtures/ldiff/output.diff.chef-e spec/fixtures/ldiff/output.diff.chef-f spec/fixtures/ldiff/output.diff.chef-u spec/fixtures/ldiff/output.diff.chef2 spec/fixtures/ldiff/output.diff.chef2-c spec/fixtures/ldiff/output.diff.chef2-d spec/fixtures/ldiff/output.diff.chef2-e spec/fixtures/ldiff/output.diff.chef2-f spec/fixtures/ldiff/output.diff.chef2-u spec/fixtures/new-chef spec/fixtures/new-chef2 spec/fixtures/old-chef spec/fixtures/old-chef2 spec/hunk_spec.rb spec/issues_spec.rb spec/lcs_spec.rb spec/ldiff_spec.rb spec/patch_spec.rb spec/sdiff_spec.rb spec/spec_helper.rb spec/traverse_balanced_spec.rb spec/traverse_sequences_spec.rb diff-lcs-1.5.1/bin/0000755000004100000410000000000014571064670014017 5ustar www-datawww-datadiff-lcs-1.5.1/bin/ldiff0000755000004100000410000000022414571064670015027 0ustar www-datawww-data#! /usr/bin/env ruby -w # frozen_string_literal: true require 'diff/lcs' require 'diff/lcs/ldiff' exit Diff::LCS::Ldiff.run(ARGV) # vim: ft=ruby diff-lcs-1.5.1/bin/htmldiff0000755000004100000410000000126414571064670015545 0ustar www-datawww-data#! /usr/bin/env ruby -w # frozen_string_literal: true require "diff/lcs" require "diff/lcs/htmldiff" begin require "text/format" rescue LoadError Diff::LCS::HTMLDiff.can_expand_tabs = false end if ARGV.size < 2 or ARGV.size > 3 warn "usage: #{File.basename($0)} old new [output.html]" warn " #{File.basename($0)} old new > output.html" exit 127 end left = IO.read(ARGV[0]).split($/) right = IO.read(ARGV[1]).split($/) options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" } htmldiff = Diff::LCS::HTMLDiff.new(left, right, options) if ARGV[2] File.open(ARGV[2], "w") do |f| htmldiff.options[:output] = f htmldiff.run end else htmldiff.run end # vim: ft=ruby diff-lcs-1.5.1/diff-lcs.gemspec0000644000004100000410000001271014571064670016304 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: diff-lcs 1.5.1 ruby lib Gem::Specification.new do |s| s.name = "diff-lcs".freeze s.version = "1.5.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "bug_tracker_uri" => "https://github.com/halostatue/diff-lcs/issues", "homepage_uri" => "https://github.com/halostatue/diff-lcs", "rubygems_mfa_required" => "true", "source_code_uri" => "https://github.com/halostatue/diff-lcs" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Austin Ziegler".freeze] s.date = "2024-01-31" s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.4.3, providing a simple extension that allows for\nDiff::LCS::Change objects to be treated implicitly as arrays and fixes a\nnumber of formatting issues.\n\nRuby versions below 2.5 are soft-deprecated, which means that older versions\nare no longer part of the CI test suite. If any changes have been introduced\nthat break those versions, bug reports and patches will be accepted, but it\nwill be up to the reporter to verify any fixes prior to release. The next\nmajor release will completely break compatibility.".freeze s.email = ["halostatue@gmail.com".freeze] s.executables = ["htmldiff".freeze, "ldiff".freeze] s.extra_rdoc_files = ["Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "License.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "docs/COPYING.txt".freeze, "docs/artistic.txt".freeze] s.files = [".rspec".freeze, "Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "License.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "bin/htmldiff".freeze, "bin/ldiff".freeze, "docs/COPYING.txt".freeze, "docs/artistic.txt".freeze, "lib/diff-lcs.rb".freeze, "lib/diff/lcs.rb".freeze, "lib/diff/lcs/array.rb".freeze, "lib/diff/lcs/backports.rb".freeze, "lib/diff/lcs/block.rb".freeze, "lib/diff/lcs/callbacks.rb".freeze, "lib/diff/lcs/change.rb".freeze, "lib/diff/lcs/htmldiff.rb".freeze, "lib/diff/lcs/hunk.rb".freeze, "lib/diff/lcs/internals.rb".freeze, "lib/diff/lcs/ldiff.rb".freeze, "lib/diff/lcs/string.rb".freeze, "spec/change_spec.rb".freeze, "spec/diff_spec.rb".freeze, "spec/fixtures/aX".freeze, "spec/fixtures/bXaX".freeze, "spec/fixtures/ds1.csv".freeze, "spec/fixtures/ds2.csv".freeze, "spec/fixtures/ldiff/output.diff".freeze, "spec/fixtures/ldiff/output.diff-c".freeze, "spec/fixtures/ldiff/output.diff-e".freeze, "spec/fixtures/ldiff/output.diff-f".freeze, "spec/fixtures/ldiff/output.diff-u".freeze, "spec/fixtures/ldiff/output.diff.chef".freeze, "spec/fixtures/ldiff/output.diff.chef-c".freeze, "spec/fixtures/ldiff/output.diff.chef-e".freeze, "spec/fixtures/ldiff/output.diff.chef-f".freeze, "spec/fixtures/ldiff/output.diff.chef-u".freeze, "spec/fixtures/ldiff/output.diff.chef2".freeze, "spec/fixtures/ldiff/output.diff.chef2-c".freeze, "spec/fixtures/ldiff/output.diff.chef2-d".freeze, "spec/fixtures/ldiff/output.diff.chef2-e".freeze, "spec/fixtures/ldiff/output.diff.chef2-f".freeze, "spec/fixtures/ldiff/output.diff.chef2-u".freeze, "spec/fixtures/new-chef".freeze, "spec/fixtures/new-chef2".freeze, "spec/fixtures/old-chef".freeze, "spec/fixtures/old-chef2".freeze, "spec/hunk_spec.rb".freeze, "spec/issues_spec.rb".freeze, "spec/lcs_spec.rb".freeze, "spec/ldiff_spec.rb".freeze, "spec/patch_spec.rb".freeze, "spec/sdiff_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/traverse_balanced_spec.rb".freeze, "spec/traverse_sequences_spec.rb".freeze] s.homepage = "https://github.com/halostatue/diff-lcs".freeze s.licenses = ["MIT".freeze, "Artistic-2.0".freeze, "GPL-2.0-or-later".freeze] s.rdoc_options = ["--main".freeze, "README.rdoc".freeze] s.required_ruby_version = Gem::Requirement.new(">= 1.8".freeze) s.rubygems_version = "3.3.15".freeze s.summary = "Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm".freeze if s.respond_to? :specification_version then s.specification_version = 4 end if s.respond_to? :add_runtime_dependency then s.add_development_dependency(%q.freeze, [">= 3.0", "< 5"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) s.add_development_dependency(%q.freeze, ["~> 1.1"]) s.add_development_dependency(%q.freeze, ["~> 1.7"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) s.add_development_dependency(%q.freeze, [">= 10.0", "< 14"]) s.add_development_dependency(%q.freeze, [">= 6.3.1", "< 7"]) s.add_development_dependency(%q.freeze, [">= 2.0", "< 4"]) else s.add_dependency(%q.freeze, [">= 3.0", "< 5"]) s.add_dependency(%q.freeze, ["~> 1.0"]) s.add_dependency(%q.freeze, ["~> 1.1"]) s.add_dependency(%q.freeze, ["~> 1.7"]) s.add_dependency(%q.freeze, ["~> 1.0"]) s.add_dependency(%q.freeze, [">= 10.0", "< 14"]) s.add_dependency(%q.freeze, [">= 6.3.1", "< 7"]) s.add_dependency(%q.freeze, [">= 2.0", "< 4"]) end end diff-lcs-1.5.1/README.rdoc0000644000004100000410000000677114571064670015070 0ustar www-datawww-data= Diff::LCS home :: https://github.com/halostatue/diff-lcs code :: https://github.com/halostatue/diff-lcs bugs :: https://github.com/halostatue/diff-lcs/issues rdoc :: http://rubydoc.info/github/halostatue/diff-lcs continuous integration :: {}[https://github.com/halostatue/diff-lcs/actions] == Description Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities to create a simple HTML diff output format and a standard diff-like tool. This is release 1.4.3, providing a simple extension that allows for Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number of formatting issues. Ruby versions below 2.5 are soft-deprecated, which means that older versions are no longer part of the CI test suite. If any changes have been introduced that break those versions, bug reports and patches will be accepted, but it will be up to the reporter to verify any fixes prior to release. The next major release will completely break compatibility. == Synopsis Using this module is quite simple. By default, Diff::LCS does not extend objects with the Diff::LCS interface, but will be called as if it were a function: require 'diff/lcs' seq1 = %w(a b c e h j l m n p) seq2 = %w(b c d e f j k l m r s t) lcs = Diff::LCS.LCS(seq1, seq2) diffs = Diff::LCS.diff(seq1, seq2) sdiff = Diff::LCS.sdiff(seq1, seq2) seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj) bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj) seq2 == Diff::LCS.patch!(seq1, diffs) seq1 == Diff::LCS.unpatch!(seq2, diffs) seq2 == Diff::LCS.patch!(seq1, sdiff) seq1 == Diff::LCS.unpatch!(seq2, sdiff) Objects can be extended with Diff::LCS: seq1.extend(Diff::LCS) lcs = seq1.lcs(seq2) diffs = seq1.diff(seq2) sdiff = seq1.sdiff(seq2) seq = seq1.traverse_sequences(seq2, callback_obj) bal = seq1.traverse_balanced(seq2, callback_obj) seq2 == seq1.patch!(diffs) seq1 == seq2.unpatch!(diffs) seq2 == seq1.patch!(sdiff) seq1 == seq2.unpatch!(sdiff) By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be extended for use this way. Note that Diff::LCS requires a sequenced enumerable container, which means that the order of enumeration is both predictable and consistent for the same set of data. While it is theoretically possible to generate a diff for an unordered hash, it will only be meaningful if the enumeration of the hashes is consistent. In general, this will mean that containers that behave like String or Array will perform best. == History Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest common subsequence (LCS) algorithm to compute intelligent differences between two sequenced enumerable containers. The implementation is based on Mario I. Wolczko's {Smalltalk version 1.2}[ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st] (1993) and Ned Konz's Perl version {Algorithm::Diff 1.15}[http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/]. Diff::LCS#sdiff and Diff::LCS#traverse_balanced were originally written for the Perl version by Mike Schilli. The algorithm is described in A Fast Algorithm for Computing Longest Common Subsequences, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor improvements to improve the speed. A simplified description of the algorithm, originally written for the Perl version, was written by Mark-Jason Dominus. diff-lcs-1.5.1/lib/0000755000004100000410000000000014571064670014015 5ustar www-datawww-datadiff-lcs-1.5.1/lib/diff/0000755000004100000410000000000014571064670014725 5ustar www-datawww-datadiff-lcs-1.5.1/lib/diff/lcs/0000755000004100000410000000000014571064670015506 5ustar www-datawww-datadiff-lcs-1.5.1/lib/diff/lcs/backports.rb0000644000004100000410000000025114571064670020021 0ustar www-datawww-data# frozen_string_literal: true unless 0.respond_to?(:positive?) class Fixnum # standard:disable Lint/UnifiedInteger def positive? self > 0 end end end diff-lcs-1.5.1/lib/diff/lcs/string.rb0000644000004100000410000000010414571064670017334 0ustar www-datawww-data# frozen_string_literal: true class String include Diff::LCS end diff-lcs-1.5.1/lib/diff/lcs/callbacks.rb0000644000004100000410000002447314571064670017764 0ustar www-datawww-data# frozen_string_literal: true require "diff/lcs/change" module Diff::LCS # This callback object implements the default set of callback events, # which only returns the event itself. Note that #finished_a and # #finished_b are not implemented -- I haven't yet figured out where they # would be useful. # # Note that this is intended to be called as is, e.g., # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::DefaultCallbacks) class DefaultCallbacks class << self # Called when two items match. def match(event) event end # Called when the old value is discarded in favour of the new value. def discard_a(event) event end # Called when the new value is discarded in favour of the old value. def discard_b(event) event end # Called when both the old and new values have changed. def change(event) event end private :new end end # An alias for DefaultCallbacks that is used in # Diff::LCS#traverse_sequences. # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::SequenceCallbacks) SequenceCallbacks = DefaultCallbacks # An alias for DefaultCallbacks that is used in # Diff::LCS#traverse_balanced. # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::BalancedCallbacks) BalancedCallbacks = DefaultCallbacks def self.callbacks_for(callbacks) callbacks.new rescue callbacks end end # This will produce a compound array of simple diff change objects. Each # element in the #diffs array is a +hunk+ or +hunk+ array, where each # element in each +hunk+ array is a single Change object representing the # addition or removal of a single element from one of the two tested # sequences. The +hunk+ provides the full context for the changes. # # diffs = Diff::LCS.diff(seq1, seq2) # # This example shows a simplified array format. # # [ [ [ '-', 0, 'a' ] ], # 1 # # [ [ '+', 2, 'd' ] ], # 2 # # [ [ '-', 4, 'h' ], # 3 # # [ '+', 4, 'f' ] ], # # [ [ '+', 6, 'k' ] ], # 4 # # [ [ '-', 8, 'n' ], # 5 # # [ '-', 9, 'p' ], # # [ '+', 9, 'r' ], # # [ '+', 10, 's' ], # # [ '+', 11, 't' ] ] ] # # There are five hunks here. The first hunk says that the +a+ at position 0 # of the first sequence should be deleted ('-'). The second hunk # says that the +d+ at position 2 of the second sequence should be inserted # ('+'). The third hunk says that the +h+ at position 4 of the # first sequence should be removed and replaced with the +f+ from position 4 # of the second sequence. The other two hunks are described similarly. # # === Use # # This callback object must be initialised and is used by the Diff::LCS#diff # method. # # cbo = Diff::LCS::DiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # cbo.finish # # Note that the call to #finish is absolutely necessary, or the last set of # changes will not be visible. Alternatively, can be used as: # # cbo = Diff::LCS::DiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # The necessary #finish call will be made. # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.map { |f| f.to_a } } class Diff::LCS::DiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs def initialize # :yields: self @hunk = [] @diffs = [] return unless block_given? begin yield self ensure finish end end # Finalizes the diff process. If an unprocessed hunk still exists, then it # is appended to the diff list. def finish finish_hunk end def match(_event) finish_hunk end def discard_a(event) @hunk << Diff::LCS::Change.new("-", event.old_position, event.old_element) end def discard_b(event) @hunk << Diff::LCS::Change.new("+", event.new_position, event.new_element) end def finish_hunk @diffs << @hunk unless @hunk.empty? @hunk = [] end private :finish_hunk end # This will produce a compound array of contextual diff change objects. Each # element in the #diffs array is a "hunk" array, where each element in each # "hunk" array is a single change. Each change is a Diff::LCS::ContextChange # that contains both the old index and new index values for the change. The # "hunk" provides the full context for the changes. Both old and new objects # will be presented for changed objects. +nil+ will be substituted for a # discarded object. # # seq1 = %w(a b c e h j l m n p) # seq2 = %w(b c d e f j k l m r s t) # # diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) # # This example shows a simplified array format. # # [ [ [ '-', [ 0, 'a' ], [ 0, nil ] ] ], # 1 # # [ [ '+', [ 3, nil ], [ 2, 'd' ] ] ], # 2 # # [ [ '-', [ 4, 'h' ], [ 4, nil ] ], # 3 # # [ '+', [ 5, nil ], [ 4, 'f' ] ] ], # # [ [ '+', [ 6, nil ], [ 6, 'k' ] ] ], # 4 # # [ [ '-', [ 8, 'n' ], [ 9, nil ] ], # 5 # # [ '+', [ 9, nil ], [ 9, 'r' ] ], # # [ '-', [ 9, 'p' ], [ 10, nil ] ], # # [ '+', [ 10, nil ], [ 10, 's' ] ], # # [ '+', [ 10, nil ], [ 11, 't' ] ] ] ] # # The five hunks shown are comprised of individual changes; if there is a # related set of changes, they are still shown individually. # # This callback can also be used with Diff::LCS#sdiff, which will produce # results like: # # diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks) # # This example shows a simplified array format. # # [ [ [ "-", [ 0, "a" ], [ 0, nil ] ] ], # 1 # # [ [ "+", [ 3, nil ], [ 2, "d" ] ] ], # 2 # # [ [ "!", [ 4, "h" ], [ 4, "f" ] ] ], # 3 # # [ [ "+", [ 6, nil ], [ 6, "k" ] ] ], # 4 # # [ [ "!", [ 8, "n" ], [ 9, "r" ] ], # 5 # # [ "!", [ 9, "p" ], [ 10, "s" ] ], # # [ "+", [ 10, nil ], [ 11, "t" ] ] ] ] # # The five hunks are still present, but are significantly shorter in total # presentation, because changed items are shown as changes ("!") instead of # potentially "mismatched" pairs of additions and deletions. # # The result of this operation is similar to that of # Diff::LCS::SDiffCallbacks. They may be compared as: # # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" } # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1) # # s == c # -> true # # === Use # # This callback object must be initialised and can be used by the # Diff::LCS#diff or Diff::LCS#sdiff methods. # # cbo = Diff::LCS::ContextDiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # cbo.finish # # Note that the call to #finish is absolutely necessary, or the last set of # changes will not be visible. Alternatively, can be used as: # # cbo = Diff::LCS::ContextDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # The necessary #finish call will be made. # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.map { |f| f.to_a } } class Diff::LCS::ContextDiffCallbacks < Diff::LCS::DiffCallbacks def discard_a(event) @hunk << Diff::LCS::ContextChange.simplify(event) end def discard_b(event) @hunk << Diff::LCS::ContextChange.simplify(event) end def change(event) @hunk << Diff::LCS::ContextChange.simplify(event) end end # This will produce a simple array of diff change objects. Each element in # the #diffs array is a single ContextChange. In the set of #diffs provided # by SDiffCallbacks, both old and new objects will be presented for both # changed and unchanged objects. +nil+ will be substituted # for a discarded object. # # The diffset produced by this callback, when provided to Diff::LCS#sdiff, # will compute and display the necessary components to show two sequences # and their minimized differences side by side, just like the Unix utility # +sdiff+. # # same same # before | after # old < - # - > new # # seq1 = %w(a b c e h j l m n p) # seq2 = %w(b c d e f j k l m r s t) # # diffs = Diff::LCS.sdiff(seq1, seq2) # # This example shows a simplified array format. # # [ [ "-", [ 0, "a"], [ 0, nil ] ], # # [ "=", [ 1, "b"], [ 0, "b" ] ], # # [ "=", [ 2, "c"], [ 1, "c" ] ], # # [ "+", [ 3, nil], [ 2, "d" ] ], # # [ "=", [ 3, "e"], [ 3, "e" ] ], # # [ "!", [ 4, "h"], [ 4, "f" ] ], # # [ "=", [ 5, "j"], [ 5, "j" ] ], # # [ "+", [ 6, nil], [ 6, "k" ] ], # # [ "=", [ 6, "l"], [ 7, "l" ] ], # # [ "=", [ 7, "m"], [ 8, "m" ] ], # # [ "!", [ 8, "n"], [ 9, "r" ] ], # # [ "!", [ 9, "p"], [ 10, "s" ] ], # # [ "+", [ 10, nil], [ 11, "t" ] ] ] # # The result of this operation is similar to that of # Diff::LCS::ContextDiffCallbacks. They may be compared as: # # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" } # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1) # # s == c # -> true # # === Use # # This callback object must be initialised and is used by the Diff::LCS#sdiff # method. # # cbo = Diff::LCS::SDiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # # As with the other initialisable callback objects, # Diff::LCS::SDiffCallbacks can be initialised with a block. As there is no # "fininishing" to be done, this has no effect on the state of the object. # # cbo = Diff::LCS::SDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.to_a } class Diff::LCS::SDiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs def initialize # :yields: self @diffs = [] yield self if block_given? end def match(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def discard_a(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def discard_b(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def change(event) @diffs << Diff::LCS::ContextChange.simplify(event) end end diff-lcs-1.5.1/lib/diff/lcs/internals.rb0000644000004100000410000002105714571064670020037 0ustar www-datawww-data# frozen_string_literal: true class << Diff::LCS def diff_traversal(method, seq1, seq2, callbacks, &block) callbacks = callbacks_for(callbacks) case method when :diff traverse_sequences(seq1, seq2, callbacks) when :sdiff traverse_balanced(seq1, seq2, callbacks) end callbacks.finish if callbacks.respond_to? :finish if block callbacks.diffs.map do |hunk| if hunk.is_a? Array hunk.map { |hunk_block| block[hunk_block] } else block[hunk] end end else callbacks.diffs end end private :diff_traversal end module Diff::LCS::Internals # :nodoc: end class << Diff::LCS::Internals # Compute the longest common subsequence between the sequenced # Enumerables +a+ and +b+. The result is an array whose contents is such # that # # result = Diff::LCS::Internals.lcs(a, b) # result.each_with_index do |e, i| # assert_equal(a[i], b[e]) unless e.nil? # end def lcs(a, b) a_start = b_start = 0 a_finish = a.size - 1 b_finish = b.size - 1 vector = [] # Collect any common elements at the beginning... while (a_start <= a_finish) && (b_start <= b_finish) && (a[a_start] == b[b_start]) vector[a_start] = b_start a_start += 1 b_start += 1 end # Now the end... while (a_start <= a_finish) && (b_start <= b_finish) && (a[a_finish] == b[b_finish]) vector[a_finish] = b_finish a_finish -= 1 b_finish -= 1 end # Now, compute the equivalence classes of positions of elements. # An explanation for how this works: https://codeforces.com/topic/92191 b_matches = position_hash(b, b_start..b_finish) thresh = [] links = [] string = a.is_a?(String) (a_start..a_finish).each do |i| ai = string ? a[i, 1] : a[i] bm = b_matches[ai] k = nil bm.reverse_each do |j| # Although the threshold check is not mandatory for this to work, # it may have an optimization purpose # An attempt to remove it: https://github.com/halostatue/diff-lcs/pull/72 # Why it is reintroduced: https://github.com/halostatue/diff-lcs/issues/78 if k && (thresh[k] > j) && (thresh[k - 1] < j) thresh[k] = j else k = replace_next_larger(thresh, j, k) end links[k] = [k.positive? ? links[k - 1] : nil, i, j] unless k.nil? end end unless thresh.empty? link = links[thresh.size - 1] until link.nil? vector[link[1]] = link[2] link = link[0] end end vector end # This method will analyze the provided patchset to provide a single-pass # normalization (conversion of the array form of Diff::LCS::Change objects to # the object form of same) and detection of whether the patchset represents # changes to be made. def analyze_patchset(patchset, depth = 0) fail "Patchset too complex" if depth > 1 has_changes = false new_patchset = [] # Format: # [ # patchset # # hunk (change) # [ # hunk # # change # ] # ] patchset.each do |hunk| case hunk when Diff::LCS::Change has_changes ||= !hunk.unchanged? new_patchset << hunk when Array # Detect if the 'hunk' is actually an array-format change object. if Diff::LCS::Change.valid_action? hunk[0] hunk = Diff::LCS::Change.from_a(hunk) has_changes ||= !hunk.unchanged? new_patchset << hunk else with_changes, hunk = analyze_patchset(hunk, depth + 1) has_changes ||= with_changes new_patchset.concat(hunk) end else fail ArgumentError, "Cannot normalise a hunk of class #{hunk.class}." end end [has_changes, new_patchset] end # Examine the patchset and the source to see in which direction the # patch should be applied. # # WARNING: By default, this examines the whole patch, so this could take # some time. This also works better with Diff::LCS::ContextChange or # Diff::LCS::Change as its source, as an array will cause the creation # of one of the above. def intuit_diff_direction(src, patchset, limit = nil) string = src.is_a?(String) count = left_match = left_miss = right_match = right_miss = 0 patchset.each do |change| count += 1 case change when Diff::LCS::ContextChange le = string ? src[change.old_position, 1] : src[change.old_position] re = string ? src[change.new_position, 1] : src[change.new_position] case change.action when "-" # Remove details from the old string if le == change.old_element left_match += 1 else left_miss += 1 end when "+" if re == change.new_element right_match += 1 else right_miss += 1 end when "=" left_miss += 1 if le != change.old_element right_miss += 1 if re != change.new_element when "!" if le == change.old_element left_match += 1 elsif re == change.new_element right_match += 1 else left_miss += 1 right_miss += 1 end end when Diff::LCS::Change # With a simplistic change, we can't tell the difference between # the left and right on '!' actions, so we ignore those. On '=' # actions, if there's a miss, we miss both left and right. element = string ? src[change.position, 1] : src[change.position] case change.action when "-" if element == change.element left_match += 1 else left_miss += 1 end when "+" if element == change.element right_match += 1 else right_miss += 1 end when "=" if element != change.element left_miss += 1 right_miss += 1 end end end break if !limit.nil? && (count > limit) end no_left = left_match.zero? && left_miss.positive? no_right = right_match.zero? && right_miss.positive? case [no_left, no_right] when [false, true] :patch when [true, false] :unpatch else case left_match <=> right_match when 1 if left_miss.zero? :patch else :unpatch end when -1 if right_miss.zero? :unpatch else :patch end else fail "The provided patchset does not appear to apply to the provided \ enumerable as either source or destination value." end end end # Find the place at which +value+ would normally be inserted into the # Enumerable. If that place is already occupied by +value+, do nothing # and return +nil+. If the place does not exist (i.e., it is off the end # of the Enumerable), add it to the end. Otherwise, replace the element # at that point with +value+. It is assumed that the Enumerable's values # are numeric. # # This operation preserves the sort order. def replace_next_larger(enum, value, last_index = nil) # Off the end? if enum.empty? || (value > enum[-1]) enum << value return enum.size - 1 end # Binary search for the insertion point last_index ||= enum.size - 1 first_index = 0 while first_index <= last_index i = (first_index + last_index) >> 1 found = enum[i] return nil if value == found if value > found first_index = i + 1 else last_index = i - 1 end end # The insertion point is in first_index; overwrite the next larger # value. enum[first_index] = value first_index end private :replace_next_larger # If +vector+ maps the matching elements of another collection onto this # Enumerable, compute the inverse of +vector+ that maps this Enumerable # onto the collection. (Currently unused.) def inverse_vector(a, vector) inverse = a.dup (0...vector.size).each do |i| inverse[vector[i]] = i unless vector[i].nil? end inverse end private :inverse_vector # Returns a hash mapping each element of an Enumerable to the set of # positions it occupies in the Enumerable, optionally restricted to the # elements specified in the range of indexes specified by +interval+. def position_hash(enum, interval) string = enum.is_a?(String) hash = Hash.new { |h, k| h[k] = [] } interval.each do |i| k = string ? enum[i, 1] : enum[i] hash[k] << i end hash end private :position_hash end diff-lcs-1.5.1/lib/diff/lcs/hunk.rb0000644000004100000410000002523214571064670017004 0ustar www-datawww-data# frozen_string_literal: true require "diff/lcs/block" # A Hunk is a group of Blocks which overlap because of the context surrounding # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk OLD_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: ED_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) # Create a hunk using references to both the old and new data, as well as the # piece of data. def initialize(data_old, data_new, piece, flag_context, file_length_difference) # At first, a hunk will have just one Block in it @blocks = [Diff::LCS::Block.new(piece)] if @blocks[0].remove.empty? && @blocks[0].insert.empty? fail "Cannot build a hunk from #{piece.inspect}; has no add or remove actions" end if String.method_defined?(:encoding) @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0, "") }.encoding end @data_old = data_old @data_new = data_new before = after = file_length_difference after += @blocks[0].diff_size @file_length_difference = after # The caller must get this manually @max_diff_size = @blocks.map { |e| e.diff_size.abs }.max # Save the start & end of each array. If the array doesn't exist (e.g., # we're only adding items in this block), then figure out the line number # based on the line number of the other file and the current difference in # file lengths. if @blocks[0].remove.empty? a1 = a2 = nil else a1 = @blocks[0].remove[0].position a2 = @blocks[0].remove[-1].position end if @blocks[0].insert.empty? b1 = b2 = nil else b1 = @blocks[0].insert[0].position b2 = @blocks[0].insert[-1].position end @start_old = a1 || (b1 - before) @start_new = b1 || (a1 + before) @end_old = a2 || (b2 - after) @end_new = b2 || (a2 + after) self.flag_context = flag_context end attr_reader :blocks attr_reader :start_old, :start_new attr_reader :end_old, :end_new attr_reader :file_length_difference # Change the "start" and "end" fields to note that context should be added # to this hunk. attr_accessor :flag_context undef :flag_context= def flag_context=(context) # :nodoc: # standard:disable Lint/DuplicateMethods return if context.nil? || context.zero? add_start = (context > @start_old) ? @start_old : context @start_old -= add_start @start_new -= add_start old_size = @data_old.size add_end = if (@end_old + context) > old_size old_size - @end_old else context end add_end = @max_diff_size if add_end >= old_size @end_old += add_end @end_new += add_end end # Merges this hunk and the provided hunk together if they overlap. Returns # a truthy value so that if there is no overlap, you can know the merge # was skipped. def merge(hunk) return unless overlaps?(hunk) @start_old = hunk.start_old @start_new = hunk.start_new blocks.unshift(*hunk.blocks) end alias_method :unshift, :merge # Determines whether there is an overlap between this hunk and the # provided hunk. This will be true if the difference between the two hunks # start or end positions is within one position of each other. def overlaps?(hunk) hunk and (((@start_old - hunk.end_old) <= 1) or ((@start_new - hunk.end_new) <= 1)) end # Returns a diff string based on a format. def diff(format, last = false) case format when :old old_diff(last) when :unified unified_diff(last) when :context context_diff(last) when :ed self when :reverse_ed, :ed_finish ed_diff(format, last) else fail "Unknown diff format #{format}." end end # Note that an old diff can't have any context. Therefore, we know that # there's only one block in the hunk. def old_diff(_last = false) warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 block = @blocks[0] # Calculate item number range. Old diff range is just like a context # diff range, except the ranges are on one line with the action between # them. s = encode("#{context_range(:old, ",")}#{OLD_DIFF_OP_ACTION[block.op]}#{context_range(:new, ",")}\n") # If removing anything, just print out all the remove lines in the hunk # which is just all the remove lines in the block. unless block.remove.empty? @data_old[@start_old..@end_old].each { |e| s << encode("< ") + e.chomp + encode("\n") } end s << encode("---\n") if block.op == "!" unless block.insert.empty? @data_new[@start_new..@end_new].each { |e| s << encode("> ") + e.chomp + encode("\n") } end s end private :old_diff def unified_diff(last = false) # Calculate item number range. s = encode("@@ -#{unified_range(:old, last)} +#{unified_range(:new, last)} @@\n") # Outlist starts containing the hunk of the old file. Removing an item # just means putting a '-' in front of it. Inserting an item requires # getting it from the new file and splicing it in. We splice in # +num_added+ items. Remove blocks use +num_added+ because splicing # changed the length of outlist. # # We remove +num_removed+ items. Insert blocks use +num_removed+ # because their item numbers -- corresponding to positions in the NEW # file -- don't take removed items into account. lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0 # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } # standard:enable Performance/UnfreezeString last_block = blocks[-1] if last old_missing_newline = missing_last_newline?(@data_old) new_missing_newline = missing_last_newline?(@data_new) end @blocks.each do |block| block.remove.each do |item| op = item.action.to_s # - offset = item.position - lo + num_added outlist[offset][0, 1] = encode(op) num_removed += 1 end if last && block == last_block && old_missing_newline && !new_missing_newline outlist << encode('\\ No newline at end of file') num_removed += 1 end block.insert.each do |item| op = item.action.to_s # + offset = item.position - @start_new + num_removed outlist[offset, 0] = encode(op) + @data_new[item.position].chomp num_added += 1 end end outlist << encode('\\ No newline at end of file') if last && new_missing_newline s << outlist.join(encode("\n")) s end private :unified_diff def context_diff(last = false) s = encode("***************\n") s << encode("*** #{context_range(:old, ",", last)} ****\n") r = context_range(:new, ",", last) if last old_missing_newline = missing_last_newline?(@data_old) new_missing_newline = missing_last_newline?(@data_new) end # Print out file 1 part for each block in context diff format if there # are any blocks that remove items lo, hi = @start_old, @end_old removes = @blocks.reject { |e| e.remove.empty? } unless removes.empty? # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } # standard:enable Performance/UnfreezeString last_block = removes[-1] removes.each do |block| block.remove.each do |item| outlist[item.position - lo][0, 1] = encode(block.op) # - or ! end if last && block == last_block && old_missing_newline outlist << encode('\\ No newline at end of file') end end s << outlist.join(encode("\n")) << encode("\n") end s << encode("--- #{r} ----\n") lo, hi = @start_new, @end_new inserts = @blocks.reject { |e| e.insert.empty? } unless inserts.empty? # standard:disable Performance/UnfreezeString outlist = @data_new[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } # standard:enable Performance/UnfreezeString last_block = inserts[-1] inserts.each do |block| block.insert.each do |item| outlist[item.position - lo][0, 1] = encode(block.op) # + or ! end if last && block == last_block && new_missing_newline outlist << encode('\\ No newline at end of file') end end s << outlist.join(encode("\n")) end s end private :context_diff def ed_diff(format, _last = false) warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 s = if format == :reverse_ed encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ",")}\n") else encode("#{context_range(:old, " ")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n") end unless @blocks[0].insert.empty? @data_new[@start_new..@end_new].each do |e| s << e.chomp + encode("\n") end s << encode(".\n") end s end private :ed_diff # Generate a range of item numbers to print. Only print 1 number if the # range has only one item in it. Otherwise, it's 'start,end' def context_range(mode, op, last = false) case mode when :old s, e = (@start_old + 1), (@end_old + 1) when :new s, e = (@start_new + 1), (@end_new + 1) end e -= 1 if last e = 1 if e.zero? (s < e) ? "#{s}#{op}#{e}" : e.to_s end private :context_range # Generate a range of item numbers to print for unified diff. Print number # where block starts, followed by number of lines in the block # (don't print number of lines if it's 1) def unified_range(mode, last) case mode when :old s, e = (@start_old + 1), (@end_old + 1) when :new s, e = (@start_new + 1), (@end_new + 1) end length = e - s + (last ? 0 : 1) first = (length < 2) ? e : s # "strange, but correct" (length <= 1) ? first.to_s : "#{first},#{length}" end private :unified_range def missing_last_newline?(data) newline = encode("\n") if data[-2] data[-2].end_with?(newline) && !data[-1].end_with?(newline) elsif data[-1] !data[-1].end_with?(newline) else true end end if String.method_defined?(:encoding) def encode(literal, target_encoding = @preferred_data_encoding) literal.encode target_encoding end def encode_as(string, *args) args.map { |arg| arg.encode(string.encoding) } end else def encode(literal, _target_encoding = nil) literal end def encode_as(_string, *args) args end end private :encode private :encode_as end diff-lcs-1.5.1/lib/diff/lcs/htmldiff.rb0000644000004100000410000000703414571064670017634 0ustar www-datawww-data# frozen_string_literal: true require "cgi" # Produce a simple HTML diff view. class Diff::LCS::HTMLDiff class << self attr_accessor :can_expand_tabs # :nodoc: end self.can_expand_tabs = true class Callbacks # :nodoc: attr_accessor :output attr_accessor :match_class attr_accessor :only_a_class attr_accessor :only_b_class def initialize(output, options = {}) @output = output options ||= {} @match_class = options[:match_class] || "match" @only_a_class = options[:only_a_class] || "only_a" @only_b_class = options[:only_b_class] || "only_b" end def htmlize(element, css_class) element = " " if element.empty? %(
#{element}
\n) end private :htmlize # This will be called with both lines are the same def match(event) @output << htmlize(event.old_element, :match_class) end # This will be called when there is a line in A that isn't in B def discard_a(event) @output << htmlize(event.old_element, :only_a_class) end # This will be called when there is a line in B that isn't in A def discard_b(event) @output << htmlize(event.new_element, :only_b_class) end end # standard:disable Style/HashSyntax DEFAULT_OPTIONS = { :expand_tabs => nil, :output => nil, :css => nil, :title => nil }.freeze # standard:enable Style/HashSyntax # standard:disable Layout/HeredocIndentation DEFAULT_CSS = <<-CSS body { margin: 0; } .diff { border: 1px solid black; margin: 1em 2em; } p { margin-left: 2em; } pre { padding-left: 1em; margin: 0; font-family: Inconsolata, Consolas, Lucida, Courier, monospaced; white-space: pre; } .match { } .only_a { background-color: #fdd; color: red; text-decoration: line-through; } .only_b { background-color: #ddf; color: blue; border-left: 3px solid blue } h1 { margin-left: 2em; } CSS # standard:enable Layout/HeredocIndentation def initialize(left, right, options = nil) @left = left @right = right @options = options @options = DEFAULT_OPTIONS.dup if @options.nil? end def verify_options @options[:expand_tabs] ||= 4 @options[:expand_tabs] = 4 if @options[:expand_tabs].negative? @options[:output] ||= $stdout @options[:css] ||= DEFAULT_CSS.dup @options[:title] ||= "diff" end private :verify_options attr_reader :options def run verify_options if @options[:expand_tabs].positive? && self.class.can_expand_tabs formatter = Text::Format.new formatter.tabstop = @options[:expand_tabs] @left.map! { |line| formatter.expand(line.chomp) } @right.map! { |line| formatter.expand(line.chomp) } end @left.map! { |line| CGI.escapeHTML(line.chomp) } @right.map! { |line| CGI.escapeHTML(line.chomp) } # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT #{@options[:title]}

#{@options[:title]}

Legend: Only in Old  Only in New

OUTPUT # standard:enable Layout/HeredocIndentation callbacks = Callbacks.new(@options[:output]) Diff::LCS.traverse_sequences(@left, @right, callbacks) # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT
OUTPUT # standard:enable Layout/HeredocIndentation end end diff-lcs-1.5.1/lib/diff/lcs/change.rb0000644000004100000410000001034114571064670017257 0ustar www-datawww-data# frozen_string_literal: true # Represents a simplistic (non-contextual) change. Represents the removal or # addition of an element from either the old or the new sequenced # enumerable. class Diff::LCS::Change IntClass = 1.class # Fixnum is deprecated in Ruby 2.4 # rubocop:disable Naming/ConstantName # The only actions valid for changes are '+' (add), '-' (delete), '=' # (no change), '!' (changed), '<' (tail changes from first sequence), or # '>' (tail changes from second sequence). The last two ('<>') are only # found with Diff::LCS::diff and Diff::LCS::sdiff. VALID_ACTIONS = %w[+ - = ! > <].freeze def self.valid_action?(action) VALID_ACTIONS.include? action end # Returns the action this Change represents. attr_reader :action # Returns the position of the Change. attr_reader :position # Returns the sequence element of the Change. attr_reader :element def initialize(*args) @action, @position, @element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) fail "Invalid Position Type" unless @position.is_a? IntClass end def inspect(*_args) "#<#{self.class}: #{to_a.inspect}>" end def to_a [@action, @position, @element] end alias_method :to_ary, :to_a def self.from_a(arr) arr = arr.flatten(1) case arr.size when 5 Diff::LCS::ContextChange.new(*(arr[0...5])) when 3 Diff::LCS::Change.new(*(arr[0...3])) else fail "Invalid change array format provided." end end include Comparable def ==(other) (self.class == other.class) and (action == other.action) and (position == other.position) and (element == other.element) end def <=>(other) r = action <=> other.action r = position <=> other.position if r.zero? r = element <=> other.element if r.zero? r end def adding? @action == "+" end def deleting? @action == "-" end def unchanged? @action == "=" end def changed? @action == "!" end def finished_a? @action == ">" end def finished_b? @action == "<" end end # Represents a contextual change. Contains the position and values of the # elements in the old and the new sequenced enumerables as well as the action # taken. class Diff::LCS::ContextChange < Diff::LCS::Change # We don't need these two values. undef :position undef :element # Returns the old position being changed. attr_reader :old_position # Returns the new position being changed. attr_reader :new_position # Returns the old element being changed. attr_reader :old_element # Returns the new element being changed. attr_reader :new_element def initialize(*args) @action, @old_position, @old_element, @new_position, @new_element = *args fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action) fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.is_a?(IntClass) fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.is_a?(IntClass) end def to_a [ @action, [@old_position, @old_element], [@new_position, @new_element] ] end alias_method :to_ary, :to_a def self.from_a(arr) Diff::LCS::Change.from_a(arr) end # Simplifies a context change for use in some diff callbacks. '<' actions # are converted to '-' and '>' actions are converted to '+'. def self.simplify(event) ea = event.to_a case ea[0] when "-" ea[2][1] = nil when "<" ea[0] = "-" ea[2][1] = nil when "+" ea[1][1] = nil when ">" ea[0] = "+" ea[1][1] = nil end Diff::LCS::ContextChange.from_a(ea) end def ==(other) (self.class == other.class) and (@action == other.action) and (@old_position == other.old_position) and (@new_position == other.new_position) and (@old_element == other.old_element) and (@new_element == other.new_element) end def <=>(other) r = @action <=> other.action r = @old_position <=> other.old_position if r.zero? r = @new_position <=> other.new_position if r.zero? r = @old_element <=> other.old_element if r.zero? r = @new_element <=> other.new_element if r.zero? r end end diff-lcs-1.5.1/lib/diff/lcs/ldiff.rb0000644000004100000410000001154414571064670017124 0ustar www-datawww-data# frozen_string_literal: true require "optparse" require "ostruct" require "diff/lcs/hunk" module Diff::LCS::Ldiff # :nodoc: # standard:disable Layout/HeredocIndentation BANNER = <<-COPYRIGHT ldiff #{Diff::LCS::VERSION} Copyright 2004-2019 Austin Ziegler Part of Diff::LCS. https://github.com/halostatue/diff-lcs This program is free software. It may be redistributed and/or modified under the terms of the GPL version 2 (or later), the Perl Artistic licence, or the MIT licence. COPYRIGHT # standard:enable Layout/HeredocIndentation end class << Diff::LCS::Ldiff attr_reader :format, :lines # :nodoc: attr_reader :file_old, :file_new # :nodoc: attr_reader :data_old, :data_new # :nodoc: def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc: @binary = nil args.options do |o| o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile" o.separator "" o.on( "-c", "-C", "--context [LINES]", Integer, "Displays a context diff with LINES lines", "of context. Default 3 lines." ) do |ctx| @format = :context @lines = ctx || 3 end o.on( "-u", "-U", "--unified [LINES]", Integer, "Displays a unified diff with LINES lines", "of context. Default 3 lines." ) do |ctx| @format = :unified @lines = ctx || 3 end o.on("-e", "Creates an 'ed' script to change", "oldfile to newfile.") do |_ctx| @format = :ed end o.on("-f", "Creates an 'ed' script to change", "oldfile to newfile in reverse order.") do |_ctx| @format = :reverse_ed end o.on( "-a", "--text", "Treat the files as text and compare them", "line-by-line, even if they do not seem", "to be text." ) do |_txt| @binary = false end o.on("--binary", "Treats the files as binary.") do |_bin| @binary = true end o.on("-q", "--brief", "Report only whether or not the files", "differ, not the details.") do |_ctx| @format = :report end o.on_tail("--help", "Shows this text.") do error << o return 0 end o.on_tail("--version", "Shows the version of Diff::LCS.") do error << Diff::LCS::Ldiff::BANNER return 0 end o.on_tail "" o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.' o.parse! end unless args.size == 2 error << args.options return 127 end # Defaults are for old-style diff @format ||= :old @lines ||= 0 file_old, file_new = *ARGV case @format when :context char_old = "*" * 3 char_new = "-" * 3 when :unified char_old = "-" * 3 char_new = "+" * 3 end # After we've read up to a certain point in each file, the number of # items we've read from each file will differ by FLD (could be 0). file_length_difference = 0 data_old = File.read(file_old) data_new = File.read(file_new) # Test binary status if @binary.nil? old_txt = data_old[0, 4096].scan(/\0/).empty? new_txt = data_new[0, 4096].scan(/\0/).empty? @binary = !old_txt || !new_txt end unless @binary data_old = data_old.lines.to_a data_new = data_new.lines.to_a end # diff yields lots of pieces, each of which is basically a Block object if @binary diffs = (data_old == data_new) else diffs = Diff::LCS.diff(data_old, data_new) diffs = nil if diffs.empty? end return 0 unless diffs if @format == :report output << "Files #{file_old} and #{file_new} differ\n" return 1 end if (@format == :unified) || (@format == :context) ft = File.stat(file_old).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") output << "#{char_old} #{file_old}\t#{ft}\n" ft = File.stat(file_new).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z") output << "#{char_new} #{file_new}\t#{ft}\n" end # Loop over hunks. If a hunk overlaps with the last hunk, join them. # Otherwise, print out the old one. oldhunk = hunk = nil if @format == :ed real_output = output output = [] end diffs.each do |piece| begin # rubocop:disable Style/RedundantBegin hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines, file_length_difference) file_length_difference = hunk.file_length_difference next unless oldhunk next if @lines.positive? && hunk.merge(oldhunk) output << oldhunk.diff(@format) output << "\n" if @format == :unified ensure oldhunk = hunk end end last = oldhunk.diff(@format, true) last << "\n" if last.respond_to?(:end_with?) && !last.end_with?("\n") output << last output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed 1 end end diff-lcs-1.5.1/lib/diff/lcs/block.rb0000644000004100000410000000137114571064670017127 0ustar www-datawww-data# frozen_string_literal: true # A block is an operation removing, adding, or changing a group of items. # Basically, this is just a list of changes, where each change adds or # deletes a single item. Used by bin/ldiff. class Diff::LCS::Block attr_reader :changes, :insert, :remove def initialize(chunk) @changes = [] @insert = [] @remove = [] chunk.each do |item| @changes << item @remove << item if item.deleting? @insert << item if item.adding? end end def diff_size @insert.size - @remove.size end def op case [@remove.empty?, @insert.empty?] when [false, false] "!" when [false, true] "-" when [true, false] "+" else # [true, true] "^" end end end diff-lcs-1.5.1/lib/diff/lcs/array.rb0000644000004100000410000000012714571064670017151 0ustar www-datawww-data# frozen_string_literal: true require "diff/lcs" class Array include Diff::LCS end diff-lcs-1.5.1/lib/diff/lcs.rb0000644000004100000410000006377614571064670016056 0ustar www-datawww-data# frozen_string_literal: true module Diff; end unless defined? Diff # == How Diff Works (by Mark-Jason Dominus) # # I once read an article written by the authors of +diff+; they said that they # hard worked very hard on the algorithm until they found the right one. # # I think what they ended up using (and I hope someone will correct me, because # I am not very confident about this) was the `longest common subsequence' # method. In the LCS problem, you have two sequences of items: # # a b c d f g h j q z # a b c d e f g i j k r x y z # # and you want to find the longest sequence of items that is present in both # original sequences in the same order. That is, you want to find a new # sequence *S* which can be obtained from the first sequence by deleting some # items, and from the second sequence by deleting other items. You also want # *S* to be as long as possible. In this case *S* is: # # a b c d f g j z # # From there it's only a small step to get diff-like output: # # e h i k q r x y # + - + + - + + + # # This module solves the LCS problem. It also includes a canned function to # generate +diff+-like output. # # It might seem from the example above that the LCS of two sequences is always # pretty obvious, but that's not always the case, especially when the two # sequences have many repeated elements. For example, consider # # a x b y c z p d q # a b c a x b y c z # # A naive approach might start by matching up the +a+ and +b+ that appear at # the beginning of each sequence, like this: # # a x b y c z p d q # a b c a b y c z # # This finds the common subsequence +a b c z+. But actually, the LCS is +a x b # y c z+: # # a x b y c z p d q # a b c a x b y c z module Diff::LCS VERSION = "1.5.1" end require "diff/lcs/callbacks" require "diff/lcs/internals" module Diff::LCS # Returns an Array containing the longest common subsequence(s) between # +self+ and +other+. See Diff::LCS#lcs. # # lcs = seq1.lcs(seq2) # # A note when using objects: Diff::LCS only works properly when each object # can be used as a key in a Hash, which typically means that the objects must # implement Object#eql? in a way that two identical values compare # identically for key purposes. That is: # # O.new('a').eql?(O.new('a')) == true def lcs(other, &block) # :yields: self[i] if there are matched subsequences Diff::LCS.lcs(self, other, &block) end # Returns the difference set between +self+ and +other+. See Diff::LCS#diff. def diff(other, callbacks = nil, &block) Diff::LCS.diff(self, other, callbacks, &block) end # Returns the balanced ("side-by-side") difference set between +self+ and # +other+. See Diff::LCS#sdiff. def sdiff(other, callbacks = nil, &block) Diff::LCS.sdiff(self, other, callbacks, &block) end # Traverses the discovered longest common subsequences between +self+ and # +other+. See Diff::LCS#traverse_sequences. def traverse_sequences(other, callbacks = nil, &block) Diff::LCS.traverse_sequences(self, other, callbacks || Diff::LCS::SequenceCallbacks, &block) end # Traverses the discovered longest common subsequences between +self+ and # +other+ using the alternate, balanced algorithm. See # Diff::LCS#traverse_balanced. def traverse_balanced(other, callbacks = nil, &block) Diff::LCS.traverse_balanced(self, other, callbacks || Diff::LCS::BalancedCallbacks, &block) end # Attempts to patch +self+ with the provided +patchset+. A new sequence based # on +self+ and the +patchset+ will be created. See Diff::LCS#patch. Attempts # to autodiscover the direction of the patch. def patch(patchset) Diff::LCS.patch(self, patchset) end alias_method :unpatch, :patch # Attempts to patch +self+ with the provided +patchset+. A new sequence based # on +self+ and the +patchset+ will be created. See Diff::LCS#patch. Does no # patch direction autodiscovery. def patch!(patchset) Diff::LCS.patch!(self, patchset) end # Attempts to unpatch +self+ with the provided +patchset+. A new sequence # based on +self+ and the +patchset+ will be created. See Diff::LCS#unpatch. # Does no patch direction autodiscovery. def unpatch!(patchset) Diff::LCS.unpatch!(self, patchset) end # Attempts to patch +self+ with the provided +patchset+, using #patch!. If # the sequence this is used on supports #replace, the value of +self+ will be # replaced. See Diff::LCS#patch. Does no patch direction autodiscovery. def patch_me(patchset) if respond_to? :replace replace(patch!(patchset)) else patch!(patchset) end end # Attempts to unpatch +self+ with the provided +patchset+, using #unpatch!. # If the sequence this is used on supports #replace, the value of +self+ will # be replaced. See Diff::LCS#unpatch. Does no patch direction autodiscovery. def unpatch_me(patchset) if respond_to? :replace replace(unpatch!(patchset)) else unpatch!(patchset) end end end class << Diff::LCS def lcs(seq1, seq2, &block) # :yields: seq1[i] for each matched matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] string = seq1.is_a? String matches.each_index do |i| next if matches[i].nil? v = string ? seq1[i, 1] : seq1[i] v = block[v] if block ret << v end ret end alias_method :LCS, :lcs # #diff computes the smallest set of additions and deletions necessary to # turn the first sequence into the second, and returns a description of these # changes. # # See Diff::LCS::DiffCallbacks for the default behaviour. An alternate # behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a # Class argument is provided for +callbacks+, #diff will attempt to # initialise it. If the +callbacks+ object (possibly initialised) responds to # #finish, it will be called. def diff(seq1, seq2, callbacks = nil, &block) # :yields: diff changes diff_traversal(:diff, seq1, seq2, callbacks || Diff::LCS::DiffCallbacks, &block) end # #sdiff computes all necessary components to show two sequences and their # minimized differences side by side, just like the Unix utility # sdiff does: # # old < - # same same # before | after # - > new # # See Diff::LCS::SDiffCallbacks for the default behaviour. An alternate # behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a # Class argument is provided for +callbacks+, #diff will attempt to # initialise it. If the +callbacks+ object (possibly initialised) responds to # #finish, it will be called. # # Each element of a returned array is a Diff::LCS::ContextChange object, # which can be implicitly converted to an array. # # Diff::LCS.sdiff(a, b).each do |action, (old_pos, old_element), (new_pos, new_element)| # case action # when '!' # # replace # when '-' # # delete # when '+' # # insert # end # end def sdiff(seq1, seq2, callbacks = nil, &block) # :yields: diff changes diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks, &block) end # #traverse_sequences is the most general facility provided by this module; # #diff and #lcs are implemented as calls to it. # # The arguments to #traverse_sequences are the two sequences to traverse, and # a callback object, like this: # # traverse_sequences(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new) # # == Callback Methods # # Optional callback methods are emphasized. # # callbacks#match:: Called when +a+ and +b+ are pointing to # common elements in +A+ and +B+. # callbacks#discard_a:: Called when +a+ is pointing to an # element not in +B+. # callbacks#discard_b:: Called when +b+ is pointing to an # element not in +A+. # callbacks#finished_a:: Called when +a+ has reached the end of # sequence +A+. # callbacks#finished_b:: Called when +b+ has reached the end of # sequence +B+. # # == Algorithm # # a---+ # v # A = a b c e h j l m n p # B = b c d e f j k l m r s t # ^ # b---+ # # If there are two arrows (+a+ and +b+) pointing to elements of sequences +A+ # and +B+, the arrows will initially point to the first elements of their # respective sequences. #traverse_sequences will advance the arrows through # the sequences one element at a time, calling a method on the user-specified # callback object before each advance. It will advance the arrows in such a # way that if there are elements A[i] and B[j] which are # both equal and part of the longest common subsequence, there will be some # moment during the execution of #traverse_sequences when arrow +a+ is # pointing to A[i] and arrow +b+ is pointing to B[j]. When # this happens, #traverse_sequences will call callbacks#match and # then it will advance both arrows. # # Otherwise, one of the arrows is pointing to an element of its sequence that # is not part of the longest common subsequence. #traverse_sequences will # advance that arrow and will call callbacks#discard_a or # callbacks#discard_b, depending on which arrow it advanced. If both # arrows point to elements that are not part of the longest common # subsequence, then #traverse_sequences will advance arrow +a+ and call the # appropriate callback, then it will advance arrow +b+ and call the appropriate # callback. # # The methods for callbacks#match, callbacks#discard_a, and # callbacks#discard_b are invoked with an event comprising the # action ("=", "+", or "-", respectively), the indicies +i+ and +j+, and the # elements A[i] and B[j]. Return values are discarded by # #traverse_sequences. # # === End of Sequences # # If arrow +a+ reaches the end of its sequence before arrow +b+ does, # #traverse_sequence will try to call callbacks#finished_a with the # last index and element of +A+ (A[-1]) and the current index and # element of +B+ (B[j]). If callbacks#finished_a does not # exist, then callbacks#discard_b will be called on each element of # +B+ until the end of the sequence is reached (the call will be done with # A[-1] and B[j] for each element). # # If +b+ reaches the end of +B+ before +a+ reaches the end of +A+, # callbacks#finished_b will be called with the current index and # element of +A+ (A[i]) and the last index and element of +B+ # (A[-1]). Again, if callbacks#finished_b does not exist on # the callback object, then callbacks#discard_a will be called on # each element of +A+ until the end of the sequence is reached (A[i] # and B[-1]). # # There is a chance that one additional callbacks#discard_a or # callbacks#discard_b will be called after the end of the sequence # is reached, if +a+ has not yet reached the end of +A+ or +b+ has not yet # reached the end of +B+. def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks) # :yields: change events callbacks ||= Diff::LCS::SequenceCallbacks matches = Diff::LCS::Internals.lcs(seq1, seq2) run_finished_a = run_finished_b = false string = seq1.is_a?(String) a_size = seq1.size b_size = seq2.size ai = bj = 0 matches.each do |b_line| if b_line.nil? unless seq1[ai].nil? ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) end else ax = string ? seq1[ai, 1] : seq1[ai] loop do break unless bj < b_line bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("=", ai, ax, bj, bx) event = yield event if block_given? callbacks.match(event) bj += 1 end ai += 1 end # The last entry (if any) processed was a match. +ai+ and +bj+ point just # past the last matching lines in their sequences. while (ai < a_size) || (bj < b_size) # last A? if ai == a_size && bj < b_size if callbacks.respond_to?(:finished_a) && !run_finished_a ax = string ? seq1[-1, 1] : seq1[-1] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new(">", (a_size - 1), ax, bj, bx) event = yield event if block_given? callbacks.finished_a(event) run_finished_a = true else ax = string ? seq1[ai, 1] : seq1[ai] loop do bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 break unless bj < b_size end end end # last B? if bj == b_size && ai < a_size if callbacks.respond_to?(:finished_b) && !run_finished_b ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[-1, 1] : seq2[-1] event = Diff::LCS::ContextChange.new("<", ai, ax, (b_size - 1), bx) event = yield event if block_given? callbacks.finished_b(event) run_finished_b = true else bx = string ? seq2[bj, 1] : seq2[bj] loop do ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 break unless bj < b_size end end end if ai < a_size ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 end if bj < b_size ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end end # #traverse_balanced is an alternative to #traverse_sequences. It uses a # different algorithm to iterate through the entries in the computed longest # common subsequence. Instead of viewing the changes as insertions or # deletions from one of the sequences, #traverse_balanced will report # changes between the sequences. # # The arguments to #traverse_balanced are the two sequences to traverse and a # callback object, like this: # # traverse_balanced(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new) # # #sdiff is implemented with #traverse_balanced. # # == Callback Methods # # Optional callback methods are emphasized. # # callbacks#match:: Called when +a+ and +b+ are pointing to # common elements in +A+ and +B+. # callbacks#discard_a:: Called when +a+ is pointing to an # element not in +B+. # callbacks#discard_b:: Called when +b+ is pointing to an # element not in +A+. # callbacks#change:: Called when +a+ and +b+ are pointing to # the same relative position, but # A[a] and B[b] are not # the same; a change has # occurred. # # #traverse_balanced might be a bit slower than #traverse_sequences, # noticable only while processing huge amounts of data. # # == Algorithm # # a---+ # v # A = a b c e h j l m n p # B = b c d e f j k l m r s t # ^ # b---+ # # === Matches # # If there are two arrows (+a+ and +b+) pointing to elements of sequences +A+ # and +B+, the arrows will initially point to the first elements of their # respective sequences. #traverse_sequences will advance the arrows through # the sequences one element at a time, calling a method on the user-specified # callback object before each advance. It will advance the arrows in such a # way that if there are elements A[i] and B[j] which are # both equal and part of the longest common subsequence, there will be some # moment during the execution of #traverse_sequences when arrow +a+ is # pointing to A[i] and arrow +b+ is pointing to B[j]. When # this happens, #traverse_sequences will call callbacks#match and # then it will advance both arrows. # # === Discards # # Otherwise, one of the arrows is pointing to an element of its sequence that # is not part of the longest common subsequence. #traverse_sequences will # advance that arrow and will call callbacks#discard_a or # callbacks#discard_b, depending on which arrow it advanced. # # === Changes # # If both +a+ and +b+ point to elements that are not part of the longest # common subsequence, then #traverse_sequences will try to call # callbacks#change and advance both arrows. If # callbacks#change is not implemented, then # callbacks#discard_a and callbacks#discard_b will be # called in turn. # # The methods for callbacks#match, callbacks#discard_a, # callbacks#discard_b, and callbacks#change are invoked # with an event comprising the action ("=", "+", "-", or "!", respectively), # the indicies +i+ and +j+, and the elements A[i] and B[j]. # Return values are discarded by #traverse_balanced. # # === Context # # Note that +i+ and +j+ may not be the same index position, even if +a+ and # +b+ are considered to be pointing to matching or changed elements. def traverse_balanced(seq1, seq2, callbacks = Diff::LCS::BalancedCallbacks) matches = Diff::LCS::Internals.lcs(seq1, seq2) a_size = seq1.size b_size = seq2.size ai = bj = mb = 0 ma = -1 string = seq1.is_a?(String) # Process all the lines in the match vector. loop do # Find next match indices +ma+ and +mb+ loop do ma += 1 break unless ma < matches.size && matches[ma].nil? end break if ma >= matches.size # end of matches? mb = matches[ma] # Change(seq2) while (ai < ma) || (bj < mb) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] case [(ai < ma), (bj < mb)] when [true, true] if callbacks.respond_to?(:change) event = Diff::LCS::ContextChange.new("!", ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 else event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) end bj += 1 when [true, false] event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end # Match ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new("=", ai, ax, bj, bx) event = yield event if block_given? callbacks.match(event) ai += 1 bj += 1 end while (ai < a_size) || (bj < b_size) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] case [(ai < a_size), (bj < b_size)] when [true, true] if callbacks.respond_to?(:change) event = Diff::LCS::ContextChange.new("!", ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 else event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) end bj += 1 when [true, false] event = Diff::LCS::ContextChange.new("-", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] event = Diff::LCS::ContextChange.new("+", ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end end # standard:disable Style/HashSyntax PATCH_MAP = { # :nodoc: :patch => {"+" => "+", "-" => "-", "!" => "!", "=" => "="}.freeze, :unpatch => {"+" => "-", "-" => "+", "!" => "!", "=" => "="}.freeze }.freeze # standard:enable Style/HashSyntax # Applies a +patchset+ to the sequence +src+ according to the +direction+ # (:patch or :unpatch), producing a new sequence. # # If the +direction+ is not specified, Diff::LCS::patch will attempt to # discover the direction of the +patchset+. # # A +patchset+ can be considered to apply forward (:patch) if the # following expression is true: # # patch(s1, diff(s1, s2)) -> s2 # # A +patchset+ can be considered to apply backward (:unpatch) if the # following expression is true: # # patch(s2, diff(s1, s2)) -> s1 # # If the +patchset+ contains no changes, the +src+ value will be returned as # either src.dup or +src+. A +patchset+ can be deemed as having no # changes if the following predicate returns true: # # patchset.empty? or # patchset.flatten(1).all? { |change| change.unchanged? } # # === Patchsets # # A +patchset+ is always an enumerable sequence of changes, hunks of changes, # or a mix of the two. A hunk of changes is an enumerable sequence of # changes: # # [ # patchset # # change # [ # hunk # # change # ] # ] # # The +patch+ method accepts patchsets that are enumerable sequences # containing either Diff::LCS::Change objects (or a subclass) or the array # representations of those objects. Prior to application, array # representations of Diff::LCS::Change objects will be reified. def patch(src, patchset, direction = nil) # Normalize the patchset. has_changes, patchset = Diff::LCS::Internals.analyze_patchset(patchset) return src.respond_to?(:dup) ? src.dup : src unless has_changes string = src.is_a?(String) # Start with a new empty type of the source's class res = src.class.new direction ||= Diff::LCS::Internals.intuit_diff_direction(src, patchset) ai = bj = 0 patch_map = PATCH_MAP[direction] patchset.each do |change| # Both Change and ContextChange support #action action = patch_map[change.action] case change when Diff::LCS::ContextChange case direction when :patch el = change.new_element op = change.old_position np = change.new_position when :unpatch el = change.old_element op = change.new_position np = change.old_position end case action when "-" # Remove details from the old string while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 when "+" while bj < np res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end res << el bj += 1 when "=" # This only appears in sdiff output with the SDiff callback. # Therefore, we only need to worry about dealing with a single # element. res << el ai += 1 bj += 1 when "!" while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end bj += 1 ai += 1 res << el end when Diff::LCS::Change case action when "-" while ai < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 when "+" while bj < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end bj += 1 res << change.element end end end while ai < src.size res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end res end # Given a set of patchset, convert the current version to the prior version. # Does no auto-discovery. def unpatch!(src, patchset) patch(src, patchset, :unpatch) end # Given a set of patchset, convert the current version to the next version. # Does no auto-discovery. def patch!(src, patchset) patch(src, patchset, :patch) end end require "diff/lcs/backports" diff-lcs-1.5.1/lib/diff-lcs.rb0000644000004100000410000000006214571064670016027 0ustar www-datawww-data# frozen_string_literal: true require "diff/lcs" diff-lcs-1.5.1/spec/0000755000004100000410000000000014571064670014201 5ustar www-datawww-datadiff-lcs-1.5.1/spec/spec_helper.rb0000644000004100000410000001646514571064670017033 0ustar www-datawww-data# frozen_string_literal: true require "rubygems" require "pathname" require "psych" if RUBY_VERSION >= "1.9" if ENV["COVERAGE"] require "simplecov" def require_do(resource) require resource yield if block_given? rescue LoadError nil end formatters = [SimpleCov::Formatter::HTMLFormatter] require_do("simplecov-rcov") { formatters << SimpleCov::Formatter::RcovFormatter } require_do("simplecov-vim/formatter") { formatters << SimpleCov::Formatter::VimFormatter } require_do("simplecov-sublime-ruby-coverage") { formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter } SimpleCov.start do formatter SimpleCov::Formatter::MultiFormatter.new(formatters) end end file = Pathname.new(__FILE__).expand_path path = file.parent parent = path.parent $:.unshift parent.join("lib") module CaptureSubprocessIO def _synchronize yield end def capture_subprocess_io _synchronize { _capture_subprocess_io { yield } } end def _capture_subprocess_io require "tempfile" captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err") orig_stdout, orig_stderr = $stdout.dup, $stderr.dup $stdout.reopen captured_stdout $stderr.reopen captured_stderr yield $stdout.rewind $stderr.rewind [captured_stdout.read, captured_stderr.read] ensure captured_stdout.unlink captured_stderr.unlink $stdout.reopen orig_stdout $stderr.reopen orig_stderr end private :_capture_subprocess_io end require "diff-lcs" module Diff::LCS::SpecHelper def hello "hello" end def hello_ary %w[h e l l o] end def seq1 %w[a b c e h j l m n p] end def skipped_seq1 %w[a h n p] end def seq2 %w[b c d e f j k l m r s t] end def skipped_seq2 %w[d f k r s t] end def word_sequence %w[abcd efgh ijkl mnopqrstuvwxyz] end def correct_lcs %w[b c e j l m] end # standard:disable Layout/ExtraSpacing def correct_forward_diff [ [ ["-", 0, "a"] ], [ ["+", 2, "d"] ], [ ["-", 4, "h"], ["+", 4, "f"] ], [ ["+", 6, "k"] ], [ ["-", 8, "n"], ["+", 9, "r"], ["-", 9, "p"], ["+", 10, "s"], ["+", 11, "t"] ] ] end def correct_backward_diff [ [ ["+", 0, "a"] ], [ ["-", 2, "d"] ], [ ["-", 4, "f"], ["+", 4, "h"] ], [ ["-", 6, "k"] ], [ ["-", 9, "r"], ["+", 8, "n"], ["-", 10, "s"], ["+", 9, "p"], ["-", 11, "t"] ] ] end def correct_forward_sdiff [ ["-", [0, "a"], [0, nil]], ["=", [1, "b"], [0, "b"]], ["=", [2, "c"], [1, "c"]], ["+", [3, nil], [2, "d"]], ["=", [3, "e"], [3, "e"]], ["!", [4, "h"], [4, "f"]], ["=", [5, "j"], [5, "j"]], ["+", [6, nil], [6, "k"]], ["=", [6, "l"], [7, "l"]], ["=", [7, "m"], [8, "m"]], ["!", [8, "n"], [9, "r"]], ["!", [9, "p"], [10, "s"]], ["+", [10, nil], [11, "t"]] ] end # standard:enable Layout/ExtraSpacing def reverse_sdiff(forward_sdiff) forward_sdiff.map { |line| line[1], line[2] = line[2], line[1] case line[0] when "-" then line[0] = "+" when "+" then line[0] = "-" end line } end def change_diff(diff) map_diffs(diff, Diff::LCS::Change) end def context_diff(diff) map_diffs(diff, Diff::LCS::ContextChange) end def format_diffs(diffs) diffs.map { |e| if e.is_a?(Array) e.map { |f| f.to_a.join }.join(", ") else e.to_a.join end }.join("\n") end def map_diffs(diffs, klass = Diff::LCS::ContextChange) diffs.map do |chunks| if klass == Diff::LCS::ContextChange klass.from_a(chunks) else chunks.map { |changes| klass.from_a(changes) } end end end def balanced_traversal(s1, s2, callback_type) callback = __send__(callback_type) Diff::LCS.traverse_balanced(s1, s2, callback) callback end def balanced_reverse(change_result) new_result = [] change_result.each do |line| line = [line[0], line[2], line[1]] case line[0] when "<" line[0] = ">" when ">" line[0] = "<" end new_result << line end new_result.sort_by { |line| [line[1], line[2]] } end def map_to_no_change(change_result) new_result = [] change_result.each do |line| case line[0] when "!" new_result << ["<", line[1], line[2]] new_result << [">", line[1] + 1, line[2]] else new_result << line end end new_result end def simple_callback callbacks = Object.new class << callbacks attr_reader :matched_a attr_reader :matched_b attr_reader :discards_a attr_reader :discards_b attr_reader :done_a attr_reader :done_b def reset @matched_a = [] @matched_b = [] @discards_a = [] @discards_b = [] @done_a = [] @done_b = [] end def match(event) @matched_a << event.old_element @matched_b << event.new_element end def discard_b(event) @discards_b << event.new_element end def discard_a(event) @discards_a << event.old_element end def finished_a(event) @done_a << [ event.old_element, event.old_position, event.new_element, event.new_position ] end def finished_b(event) @done_b << [ event.old_element, event.old_position, event.new_element, event.new_position ] end end callbacks.reset callbacks end def simple_callback_no_finishers simple = simple_callback class << simple undef :finished_a undef :finished_b end simple end def balanced_callback cb = Object.new class << cb attr_reader :result def reset @result = [] end def match(event) @result << ["=", event.old_position, event.new_position] end def discard_a(event) @result << ["<", event.old_position, event.new_position] end def discard_b(event) @result << [">", event.old_position, event.new_position] end def change(event) @result << ["!", event.old_position, event.new_position] end end cb.reset cb end def balanced_callback_no_change balanced = balanced_callback class << balanced undef :change end balanced end module Matchers extend RSpec::Matchers::DSL matcher :be_nil_or_match_values do |ii, s1, s2| match do |ee| expect(ee).to(satisfy { |vee| vee.nil? || s1[ii] == s2[ee] }) end end matcher :correctly_map_sequence do |s1| match do |actual| actual.each_index { |ii| expect(actual[ii]).to be_nil_or_match_values(ii, s1, @s2) } end chain :to_other_sequence do |s2| @s2 = s2 end end end end RSpec.configure do |conf| conf.include Diff::LCS::SpecHelper conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:" # standard:disable Style/HashSyntax conf.filter_run_excluding :broken => true # standard:enable Style/HashSyntax end diff-lcs-1.5.1/spec/traverse_sequences_spec.rb0000644000004100000410000001112014571064670021441 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe "Diff::LCS.traverse_sequences" do describe "callback with no finishers" do describe "over (seq1, seq2)" do before(:each) do @callback_s1_s2 = simple_callback_no_finishers Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2) @callback_s2_s1 = simple_callback_no_finishers Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1) end it "has the correct LCS result on left-matches" do expect(@callback_s1_s2.matched_a).to eq(correct_lcs) expect(@callback_s2_s1.matched_a).to eq(correct_lcs) end it "has the correct LCS result on right-matches" do expect(@callback_s1_s2.matched_b).to eq(correct_lcs) expect(@callback_s2_s1.matched_b).to eq(correct_lcs) end it "has the correct skipped sequences with the left sequence" do expect(@callback_s1_s2.discards_a).to eq(skipped_seq1) expect(@callback_s2_s1.discards_a).to eq(skipped_seq2) end it "has the correct skipped sequences with the right sequence" do expect(@callback_s1_s2.discards_b).to eq(skipped_seq2) expect(@callback_s2_s1.discards_b).to eq(skipped_seq1) end it "does not have anything done markers from the left or right sequences" do expect(@callback_s1_s2.done_a).to be_empty expect(@callback_s1_s2.done_b).to be_empty expect(@callback_s2_s1.done_a).to be_empty expect(@callback_s2_s1.done_b).to be_empty end end describe "over (hello, hello)" do before(:each) do @callback = simple_callback_no_finishers Diff::LCS.traverse_sequences(hello, hello, @callback) end it "has the correct LCS result on left-matches" do expect(@callback.matched_a).to eq(hello.chars) end it "has the correct LCS result on right-matches" do expect(@callback.matched_b).to eq(hello.chars) end it "has the correct skipped sequences with the left sequence" do expect(@callback.discards_a).to be_empty end it "has the correct skipped sequences with the right sequence" do expect(@callback.discards_b).to be_empty end it "does not have anything done markers from the left or right sequences" do expect(@callback.done_a).to be_empty expect(@callback.done_b).to be_empty end end describe "over (hello_ary, hello_ary)" do before(:each) do @callback = simple_callback_no_finishers Diff::LCS.traverse_sequences(hello_ary, hello_ary, @callback) end it "has the correct LCS result on left-matches" do expect(@callback.matched_a).to eq(hello_ary) end it "has the correct LCS result on right-matches" do expect(@callback.matched_b).to eq(hello_ary) end it "has the correct skipped sequences with the left sequence" do expect(@callback.discards_a).to be_empty end it "has the correct skipped sequences with the right sequence" do expect(@callback.discards_b).to be_empty end it "does not have anything done markers from the left or right sequences" do expect(@callback.done_a).to be_empty expect(@callback.done_b).to be_empty end end end describe "callback with finisher" do before(:each) do @callback_s1_s2 = simple_callback Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2) @callback_s2_s1 = simple_callback Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1) end it "has the correct LCS result on left-matches" do expect(@callback_s1_s2.matched_a).to eq(correct_lcs) expect(@callback_s2_s1.matched_a).to eq(correct_lcs) end it "has the correct LCS result on right-matches" do expect(@callback_s1_s2.matched_b).to eq(correct_lcs) expect(@callback_s2_s1.matched_b).to eq(correct_lcs) end it "has the correct skipped sequences for the left sequence" do expect(@callback_s1_s2.discards_a).to eq(skipped_seq1) expect(@callback_s2_s1.discards_a).to eq(skipped_seq2) end it "has the correct skipped sequences for the right sequence" do expect(@callback_s1_s2.discards_b).to eq(skipped_seq2) expect(@callback_s2_s1.discards_b).to eq(skipped_seq1) end it "has done markers differently-sized sequences" do expect(@callback_s1_s2.done_a).to eq([["p", 9, "t", 11]]) expect(@callback_s1_s2.done_b).to be_empty expect(@callback_s2_s1.done_a).to be_empty expect(@callback_s2_s1.done_b).to eq([["t", 11, "p", 9]]) end end end diff-lcs-1.5.1/spec/sdiff_spec.rb0000644000004100000410000001210014571064670016625 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe "Diff::LCS.sdiff" do include Diff::LCS::SpecHelper::Matchers shared_examples "compare sequences correctly" do it "compares s1 -> s2 correctly" do expect(Diff::LCS.sdiff(s1, s2)).to eq(context_diff(result)) end it "compares s2 -> s1 correctly" do expect(Diff::LCS.sdiff(s2, s1)).to eq(context_diff(reverse_sdiff(result))) end end describe "using seq1 & seq2" do let(:s1) { seq1 } let(:s2) { seq2 } let(:result) { correct_forward_sdiff } it_has_behavior "compare sequences correctly" end describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do let(:s1) { %w[abc def yyy xxx ghi jkl] } let(:s2) { %w[abc dxf xxx ghi jkl] } let(:result) { # standard:disable Layout/ExtraSpacing [ ["=", [0, "abc"], [0, "abc"]], ["!", [1, "def"], [1, "dxf"]], ["-", [2, "yyy"], [2, nil]], ["=", [3, "xxx"], [2, "xxx"]], ["=", [4, "ghi"], [3, "ghi"]], ["=", [5, "jkl"], [4, "jkl"]] ] # standard:enable Layout/ExtraSpacing } it_has_behavior "compare sequences correctly" end describe "using %w(a b c d e) & %w(a e)" do let(:s1) { %w[a b c d e] } let(:s2) { %w[a e] } let(:result) { [ ["=", [0, "a"], [0, "a"]], ["-", [1, "b"], [1, nil]], ["-", [2, "c"], [1, nil]], ["-", [3, "d"], [1, nil]], ["=", [4, "e"], [1, "e"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e) & %w(a b c d e)" do let(:s1) { %w[a e] } let(:s2) { %w[a b c d e] } let(:result) { [ ["=", [0, "a"], [0, "a"]], ["+", [1, nil], [1, "b"]], ["+", [1, nil], [2, "c"]], ["+", [1, nil], [3, "d"]], ["=", [1, "e"], [4, "e"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(v x a e) & %w(w y a b c d e)" do let(:s1) { %w[v x a e] } let(:s2) { %w[w y a b c d e] } let(:result) { [ ["!", [0, "v"], [0, "w"]], ["!", [1, "x"], [1, "y"]], ["=", [2, "a"], [2, "a"]], ["+", [3, nil], [3, "b"]], ["+", [3, nil], [4, "c"]], ["+", [3, nil], [5, "d"]], ["=", [3, "e"], [6, "e"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(x a e) & %w(a b c d e)" do let(:s1) { %w[x a e] } let(:s2) { %w[a b c d e] } let(:result) { [ ["-", [0, "x"], [0, nil]], ["=", [1, "a"], [0, "a"]], ["+", [2, nil], [1, "b"]], ["+", [2, nil], [2, "c"]], ["+", [2, nil], [3, "d"]], ["=", [2, "e"], [4, "e"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e) & %w(x a b c d e)" do let(:s1) { %w[a e] } let(:s2) { %w[x a b c d e] } let(:result) { [ ["+", [0, nil], [0, "x"]], ["=", [0, "a"], [1, "a"]], ["+", [1, nil], [2, "b"]], ["+", [1, nil], [3, "c"]], ["+", [1, nil], [4, "d"]], ["=", [1, "e"], [5, "e"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e v) & %w(x a b c d e w x)" do let(:s1) { %w[a e v] } let(:s2) { %w[x a b c d e w x] } let(:result) { [ ["+", [0, nil], [0, "x"]], ["=", [0, "a"], [1, "a"]], ["+", [1, nil], [2, "b"]], ["+", [1, nil], [3, "c"]], ["+", [1, nil], [4, "d"]], ["=", [1, "e"], [5, "e"]], ["!", [2, "v"], [6, "w"]], ["+", [3, nil], [7, "x"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w() & %w(a b c)" do let(:s1) { %w[] } let(:s2) { %w[a b c] } let(:result) { [ ["+", [0, nil], [0, "a"]], ["+", [0, nil], [1, "b"]], ["+", [0, nil], [2, "c"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a b c) & %w(1)" do let(:s1) { %w[a b c] } let(:s2) { %w[1] } let(:result) { [ ["!", [0, "a"], [0, "1"]], ["-", [1, "b"], [1, nil]], ["-", [2, "c"], [1, nil]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a b c) & %w(c)" do let(:s1) { %w[a b c] } let(:s2) { %w[c] } let(:result) { [ ["-", [0, "a"], [0, nil]], ["-", [1, "b"], [0, nil]], ["=", [2, "c"], [0, "c"]] ] } it_has_behavior "compare sequences correctly" end describe "using %w(abcd efgh ijkl mnop) & []" do let(:s1) { %w[abcd efgh ijkl mnop] } let(:s2) { [] } let(:result) { [ ["-", [0, "abcd"], [0, nil]], ["-", [1, "efgh"], [0, nil]], ["-", [2, "ijkl"], [0, nil]], ["-", [3, "mnop"], [0, nil]] ] } it_has_behavior "compare sequences correctly" end describe "using [[1,2]] & []" do let(:s1) { [[1, 2]] } let(:s2) { [] } let(:result) { [ ["-", [0, [1, 2]], [0, nil]] ] } it_has_behavior "compare sequences correctly" end end diff-lcs-1.5.1/spec/fixtures/0000755000004100000410000000000014571064670016052 5ustar www-datawww-datadiff-lcs-1.5.1/spec/fixtures/new-chef0000644000004100000410000000005014571064670017464 0ustar www-datawww-data{ "name": "x", "description": "lo" }diff-lcs-1.5.1/spec/fixtures/ldiff/0000755000004100000410000000000014571064670017136 5ustar www-datawww-datadiff-lcs-1.5.1/spec/fixtures/ldiff/output.diff-f0000644000004100000410000000001214571064670021544 0ustar www-datawww-datac1 bXaX . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef0000644000004100000410000000007014571064670022231 0ustar www-datawww-data3c3 < "description": "hi" --- > "description": "lo" diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef-e0000644000004100000410000000003314571064670022452 0ustar www-datawww-data3c "description": "lo" . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef2-d0000644000004100000410000000010514571064670022533 0ustar www-datawww-datad2 a14 recipe[o::new] recipe[p::new] recipe[q::new] recipe[r::new] . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff-c0000644000004100000410000000024614571064670021552 0ustar www-datawww-data*** spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400 --- spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400 *************** *** 1 **** ! aX --- 1 ---- ! bXaX diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef2-c0000644000004100000410000000070414571064670022537 0ustar www-datawww-data*** spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400 --- spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400 *************** *** 1,5 **** recipe[a::default] - recipe[b::default] recipe[c::default] recipe[d::default] recipe[e::default] --- 1,4 ---- *************** *** 12,14 **** --- 11,17 ---- recipe[l::default] recipe[m::default] recipe[n::default] + recipe[o::new] + recipe[p::new] + recipe[q::new] + recipe[r::new] diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef2-u0000644000004100000410000000060214571064670022556 0ustar www-datawww-data--- spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400 +++ spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400 @@ -1,5 +1,4 @@ recipe[a::default] -recipe[b::default] recipe[c::default] recipe[d::default] recipe[e::default] @@ -12,3 +11,7 @@ recipe[l::default] recipe[m::default] recipe[n::default] +recipe[o::new] +recipe[p::new] +recipe[q::new] +recipe[r::new] diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef-u0000644000004100000410000000035614571064670022502 0ustar www-datawww-data--- spec/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400 +++ spec/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400 @@ -1,4 +1,4 @@ { "name": "x", - "description": "hi" + "description": "lo" } \ No newline at end of file diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef-f0000644000004100000410000000003314571064670022453 0ustar www-datawww-datac3 "description": "lo" . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef2-e0000644000004100000410000000010514571064670022534 0ustar www-datawww-data14a recipe[o::new] recipe[p::new] recipe[q::new] recipe[r::new] . 2d diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff-u0000644000004100000410000000021214571064670021565 0ustar www-datawww-data--- spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400 +++ spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400 @@ -1 +1 @@ -aX +bXaX diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff-e0000644000004100000410000000001214571064670021543 0ustar www-datawww-data1c bXaX . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef2-f0000644000004100000410000000010514571064670022535 0ustar www-datawww-datad2 a14 recipe[o::new] recipe[p::new] recipe[q::new] recipe[r::new] . diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef20000644000004100000410000000014614571064670022317 0ustar www-datawww-data2d1 < recipe[b::default] 14a14,17 > recipe[o::new] > recipe[p::new] > recipe[q::new] > recipe[r::new] diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff0000644000004100000410000000002414571064670021324 0ustar www-datawww-data1c1 < aX --- > bXaX diff-lcs-1.5.1/spec/fixtures/ldiff/output.diff.chef-c0000644000004100000410000000050214571064670022451 0ustar www-datawww-data*** spec/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400 --- spec/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400 *************** *** 1,4 **** { "name": "x", ! "description": "hi" } \ No newline at end of file --- 1,4 ---- { "name": "x", ! "description": "lo" } \ No newline at end of file diff-lcs-1.5.1/spec/fixtures/bXaX0000644000004100000410000000000514571064670016632 0ustar www-datawww-databXaX diff-lcs-1.5.1/spec/fixtures/old-chef0000644000004100000410000000005014571064670017451 0ustar www-datawww-data{ "name": "x", "description": "hi" }diff-lcs-1.5.1/spec/fixtures/ds2.csv0000644000004100000410000000054714571064670017265 0ustar www-datawww-data 1,3 2,7 3,13 4,21 5,31 6,42 7,57 8,73 9,91 10,111 11,133 12,157 13,183 14,211 15,241 16,273 17,307 18,343 19,200 20,421 21,463 22,507 23,553 24,601 25,651 26,703 27,757 28,813 29,871 30,931 31,123 32,1057 33,1123 34,1000 35,1261 36,1333 37,1407 38,1483 39,1561 40,1641 41,1723 42,1807 43,1893 44,1981 45,2071 46,2163 47,1524 48,2353 49,2451 50,2500 51,2520 diff-lcs-1.5.1/spec/fixtures/new-chef20000644000004100000410000000046314571064670017556 0ustar www-datawww-datarecipe[a::default] recipe[c::default] recipe[d::default] recipe[e::default] recipe[f::default] recipe[g::default] recipe[h::default] recipe[i::default] recipe[j::default] recipe[k::default] recipe[l::default] recipe[m::default] recipe[n::default] recipe[o::new] recipe[p::new] recipe[q::new] recipe[r::new] diff-lcs-1.5.1/spec/fixtures/ds1.csv0000644000004100000410000000053414571064670017260 0ustar www-datawww-data1,3 2,7 3,13 4,21 5,31 6,43 7,57 8,73 9,91 10,111 11,133 12,157 13,183 14,211 15,241 16,273 17,307 18,343 19,381 20,421 21,463 22,507 23,553 24,601 25,651 26,703 27,757 28,813 29,871 30,931 31,993 32,1057 33,1123 34,1191 35,1261 36,1333 37,1407 38,1483 39,1561 40,1641 41,1723 42,1807 43,1893 44,1981 45,2071 46,2163 47,2257 48,2353 49,2451 50,2500diff-lcs-1.5.1/spec/fixtures/aX0000644000004100000410000000000314571064670016336 0ustar www-datawww-dataaX diff-lcs-1.5.1/spec/fixtures/old-chef20000644000004100000410000000041214571064670017535 0ustar www-datawww-datarecipe[a::default] recipe[b::default] recipe[c::default] recipe[d::default] recipe[e::default] recipe[f::default] recipe[g::default] recipe[h::default] recipe[i::default] recipe[j::default] recipe[k::default] recipe[l::default] recipe[m::default] recipe[n::default] diff-lcs-1.5.1/spec/diff_spec.rb0000644000004100000410000000246414571064670016456 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe Diff::LCS, ".diff" do include Diff::LCS::SpecHelper::Matchers it "correctly diffs seq1 to seq2" do diff_s1_s2 = Diff::LCS.diff(seq1, seq2) expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2) end it "correctly diffs seq2 to seq1" do diff_s2_s1 = Diff::LCS.diff(seq2, seq1) expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1) end it "correctly diffs against an empty sequence" do diff = Diff::LCS.diff(word_sequence, []) correct_diff = [ [ ["-", 0, "abcd"], ["-", 1, "efgh"], ["-", 2, "ijkl"], ["-", 3, "mnopqrstuvwxyz"] ] ] expect(change_diff(correct_diff)).to eq(diff) diff = Diff::LCS.diff([], word_sequence) correct_diff.each do |hunk| hunk.each { |change| change[0] = "+" } end expect(change_diff(correct_diff)).to eq(diff) end it "correctly diffs 'xx' and 'xaxb'" do left = "xx" right = "xaxb" expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right) end it "returns an empty diff with (hello, hello)" do expect(Diff::LCS.diff(hello, hello)).to be_empty end it "returns an empty diff with (hello_ary, hello_ary)" do expect(Diff::LCS.diff(hello_ary, hello_ary)).to be_empty end end diff-lcs-1.5.1/spec/patch_spec.rb0000644000004100000410000003511114571064670016640 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe "Diff::LCS.patch" do include Diff::LCS::SpecHelper::Matchers shared_examples "patch sequences correctly" do it "correctly patches left-to-right (patch autodiscovery)" do expect(Diff::LCS.patch(s1, patch_set)).to eq(s2) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(s1, patch_set, :patch)).to eq(s2) expect(Diff::LCS.patch!(s1, patch_set)).to eq(s2) end it "correctly patches right-to-left (unpatch autodiscovery)" do expect(Diff::LCS.patch(s2, patch_set)).to eq(s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(s2, patch_set, :unpatch)).to eq(s1) expect(Diff::LCS.unpatch!(s2, patch_set)).to eq(s1) end end describe "using a Diff::LCS.diff patchset" do describe "an empty patchset returns the source" do it "works on a string (hello)" do diff = Diff::LCS.diff(hello, hello) expect(Diff::LCS.patch(hello, diff)).to eq(hello) end it "works on an array %W(h e l l o)" do diff = Diff::LCS.diff(hello_ary, hello_ary) expect(Diff::LCS.patch(hello_ary, diff)).to eq(hello_ary) end end describe "with default diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1) } end end end describe "with context diff callbacks (ContextDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1, Diff::LCS::ContextDiffCallbacks) } end end end describe "with sdiff callbacks (SDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2, Diff::LCS::SDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1, Diff::LCS::SDiffCallbacks) } end end end end describe "using a Diff::LCS.sdiff patchset" do describe "an empty patchset returns the source" do it "works on a string (hello)" do expect(Diff::LCS.patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello) end it "works on an array %W(h e l l o)" do expect(Diff::LCS.patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary))).to eq(hello_ary) end end describe "with default diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2, Diff::LCS::DiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1, Diff::LCS::DiffCallbacks) } end end end describe "with context diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1, Diff::LCS::ContextDiffCallbacks) } end end end describe "with sdiff callbacks (SDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1) } end end end end # Note: because of the error in autodiscovery ("does not autodiscover s1 # to s2 patches"), this cannot use the "patch sequences correctly" shared # set. Once the bug in autodiscovery is fixed, this can be converted as # above. describe "fix bug 891: patchsets do not contain the last equal part" do before :each do @s1 = %w[a b c d e f g h i j k] # rubocop:disable Layout/SpaceInsideArrayPercentLiteral @s2 = %w[a b c d D e f g h i j k] end describe "using Diff::LCS.diff with default diff callbacks" do before :each do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.diff with context diff callbacks" do before :each do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::ContextDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::ContextDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.diff with sdiff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::SDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::SDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with default sdiff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with context diff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::ContextDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::ContextDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with default diff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::DiffCallbacks) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end end end diff-lcs-1.5.1/spec/change_spec.rb0000644000004100000410000000473614571064670016777 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe Diff::LCS::Change do describe "an add" do subject { described_class.new("+", 0, "element") } it { should_not be_deleting } it { should be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a delete" do subject { described_class.new("-", 0, "element") } it { should be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "an unchanged" do subject { described_class.new("=", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a changed" do subject { described_class.new("!", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a finished_a" do subject { described_class.new(">", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should be_finished_a } it { should_not be_finished_b } end describe "a finished_b" do subject { described_class.new("<", 0, "element") } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should be_finished_b } end describe "as array" do it "should be converted" do action, position, element = described_class.new("!", 0, "element") expect(action).to eq "!" expect(position).to eq 0 expect(element).to eq "element" end end end describe Diff::LCS::ContextChange do describe "as array" do it "should be converted" do action, (old_position, old_element), (new_position, new_element) = described_class.new("!", 1, "old_element", 2, "new_element") expect(action).to eq "!" expect(old_position).to eq 1 expect(old_element).to eq "old_element" expect(new_position).to eq 2 expect(new_element).to eq "new_element" end end end diff-lcs-1.5.1/spec/traverse_balanced_spec.rb0000644000004100000410000001613014571064670021205 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe "Diff::LCS.traverse_balanced" do include Diff::LCS::SpecHelper::Matchers shared_examples "with a #change callback" do |s1, s2, result| it "traverses s1 -> s2 correctly" do traversal = balanced_traversal(s1, s2, :balanced_callback) expect(traversal.result).to eq(result) end it "traverses s2 -> s1 correctly" do traversal = balanced_traversal(s2, s1, :balanced_callback) expect(traversal.result).to eq(balanced_reverse(result)) end end shared_examples "without a #change callback" do |s1, s2, result| it "traverses s1 -> s2 correctly" do traversal = balanced_traversal(s1, s2, :balanced_callback_no_change) expect(traversal.result).to eq(map_to_no_change(result)) end it "traverses s2 -> s1 correctly" do traversal = balanced_traversal(s2, s1, :balanced_callback_no_change) expect(traversal.result).to eq(map_to_no_change(balanced_reverse(result))) end end describe "identical string sequences ('abc')" do s1 = s2 = "abc" result = [ ["=", 0, 0], ["=", 1, 1], ["=", 2, 2] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "identical array sequences %w(a b c)" do s1 = s2 = %w[a b c] result = [ ["=", 0, 0], ["=", 1, 1], ["=", 2, 2] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a b c) & %w(a x c)" do s1 = %w[a b c] s2 = %w[a x c] result = [ ["=", 0, 0], ["!", 1, 1], ["=", 2, 2] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a x y c) & %w(a v w c)" do s1 = %w[a x y c] s2 = %w[a v w c] result = [ ["=", 0, 0], ["!", 1, 1], ["!", 2, 2], ["=", 3, 3] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(x y c) & %w(v w c)" do s1 = %w[x y c] s2 = %w[v w c] result = [ ["!", 0, 0], ["!", 1, 1], ["=", 2, 2] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a x y z) & %w(b v w)" do s1 = %w[a x y z] s2 = %w[b v w] result = [ ["!", 0, 0], ["!", 1, 1], ["!", 2, 2], ["<", 3, 3] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a z) & %w(a)" do s1 = %w[a z] s2 = %w[a] result = [ ["=", 0, 0], ["<", 1, 1] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(z a) & %w(a)" do s1 = %w[z a] s2 = %w[a] result = [ ["<", 0, 0], ["=", 1, 0] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a b c) & %w(x y z)" do s1 = %w[a b c] s2 = %w[x y z] result = [ ["!", 0, 0], ["!", 1, 1], ["!", 2, 2] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []" do s1 = %w[abcd efgh ijkl mnopqrstuvwxyz] s2 = [] result = [ ["<", 0, 0], ["<", 1, 0], ["<", 2, 0], ["<", 3, 0] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(a b c) & %q(a x c)" do s1 = "a b c" s2 = "a x c" result = [ ["=", 0, 0], ["=", 1, 1], ["!", 2, 2], ["=", 3, 3], ["=", 4, 4] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(a x y c) & %q(a v w c)" do s1 = "a x y c" s2 = "a v w c" result = [ ["=", 0, 0], ["=", 1, 1], ["!", 2, 2], ["=", 3, 3], ["!", 4, 4], ["=", 5, 5], ["=", 6, 6] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(x y c) & %q(v w c)" do s1 = "x y c" s2 = "v w c" result = [ ["!", 0, 0], ["=", 1, 1], ["!", 2, 2], ["=", 3, 3], ["=", 4, 4] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(a x y z) & %q(b v w)" do s1 = "a x y z" s2 = "b v w" result = [ ["!", 0, 0], ["=", 1, 1], ["!", 2, 2], ["=", 3, 3], ["!", 4, 4], ["<", 5, 5], ["<", 6, 5] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(a z) & %q(a)" do s1 = "a z" s2 = "a" result = [ ["=", 0, 0], ["<", 1, 1], ["<", 2, 1] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(z a) & %q(a)" do s1 = "z a" s2 = "a" result = [ ["<", 0, 0], ["<", 1, 0], ["=", 2, 0] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(a b c) & %q(x y z)" do s1 = "a b c" s2 = "x y z" result = [ ["!", 0, 0], ["=", 1, 1], ["!", 2, 2], ["=", 3, 3], ["!", 4, 4] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %q(abcd efgh ijkl mnopqrstuvwxyz) & %q()" do s1 = "abcd efgh ijkl mnopqrstuvwxyz" s2 = "" # standard:disable Layout/ExtraSpacing result = [ ["<", 0, 0], ["<", 1, 0], ["<", 2, 0], ["<", 3, 0], ["<", 4, 0], ["<", 5, 0], ["<", 6, 0], ["<", 7, 0], ["<", 8, 0], ["<", 9, 0], ["<", 10, 0], ["<", 11, 0], ["<", 12, 0], ["<", 13, 0], ["<", 14, 0], ["<", 15, 0], ["<", 16, 0], ["<", 17, 0], ["<", 18, 0], ["<", 19, 0], ["<", 20, 0], ["<", 21, 0], ["<", 22, 0], ["<", 23, 0], ["<", 24, 0], ["<", 25, 0], ["<", 26, 0], ["<", 27, 0], ["<", 28, 0] ] # standard:enable Layout/ExtraSpacing it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end end diff-lcs-1.5.1/spec/hunk_spec.rb0000644000004100000410000000452614571064670016514 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" if String.method_defined?(:encoding) require "diff/lcs/hunk" describe Diff::LCS::Hunk do let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] } let(:new_data) { ["Tu a un carte avec {count} items".encode("UTF-16LE")] } let(:pieces) { Diff::LCS.diff old_data, new_data } let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) } it "produces a unified diff from the two pieces" do expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1 @@ -Tu a un carté avec {count} itéms +Tu a un carte avec {count} items EXPECTED expect(hunk.diff(:unified)).to eq(expected) end it "produces a unified diff from the two pieces (last entry)" do expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1 @@ -Tu a un carté avec {count} itéms +Tu a un carte avec {count} items \\ No newline at end of file EXPECTED expect(hunk.diff(:unified, true)).to eq(expected) end it "produces a context diff from the two pieces" do expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp *************** *** 1 **** ! Tu a un carté avec {count} itéms --- 1 ---- ! Tu a un carte avec {count} items EXPECTED expect(hunk.diff(:context)).to eq(expected) end it "produces an old diff from the two pieces" do expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp 1c1 < Tu a un carté avec {count} itéms --- > Tu a un carte avec {count} items EXPECTED expect(hunk.diff(:old)).to eq(expected) end it "produces a reverse ed diff from the two pieces" do expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp c1 Tu a un carte avec {count} items . EXPECTED expect(hunk.diff(:reverse_ed)).to eq(expected) end context "with empty first data set" do let(:old_data) { [] } it "produces a unified diff" do expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp @@ -1 +1,2 @@ +Tu a un carte avec {count} items EXPECTED expect(hunk.diff(:unified)).to eq(expected) end end end end diff-lcs-1.5.1/spec/ldiff_spec.rb0000644000004100000410000000413514571064670016627 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" RSpec.describe "bin/ldiff" do include CaptureSubprocessIO # standard:disable Style/HashSyntax fixtures = [ {:name => "output.diff", :left => "aX", :right => "bXaX"}, {:name => "output.diff.chef", :left => "old-chef", :right => "new-chef"}, {:name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2"} ].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)| fixture = fixture.dup fixture[:flag] = flag fixture } # standard:enable Style/HashSyntax def self.test_ldiff(fixture) desc = [ fixture[:flag], "spec/fixtures/#{fixture[:left]}", "spec/fixtures/#{fixture[:right]}", "#", "=>", "spec/fixtures/ldiff/#{fixture[:name]}#{fixture[:flag]}" ].join(" ") it desc do expect(run_ldiff(fixture)).to eq(read_fixture(fixture)) end end fixtures.each do |fixture| test_ldiff(fixture) end def read_fixture(options) fixture = options.fetch(:name) flag = options.fetch(:flag) name = "spec/fixtures/ldiff/#{fixture}#{flag}" data = IO.__send__(IO.respond_to?(:binread) ? :binread : :read, name) clean_data(data, flag) end def clean_data(data, flag) data = case flag when "-c", "-u" clean_output_timestamp(data) else data end data.gsub(/\r\n?/, "\n") end def clean_output_timestamp(data) data.gsub( %r{ ^ [-+*]{3} \s* spec/fixtures/(\S+) \s* \d{4}-\d\d-\d\d \s* \d\d:\d\d:\d\d(?:\.\d+) \s* (?:[-+]\d{4}|Z) }x, '*** spec/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000' ) end def run_ldiff(options) flag = options.fetch(:flag) left = options.fetch(:left) right = options.fetch(:right) stdout, stderr = capture_subprocess_io do system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/fixtures/#{right}") end expect(stderr).to be_empty if RUBY_VERSION >= "1.9" expect(stdout).not_to be_empty clean_data(stdout, flag) end end diff-lcs-1.5.1/spec/lcs_spec.rb0000644000004100000410000000330014571064670016315 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" describe Diff::LCS::Internals, ".lcs" do include Diff::LCS::SpecHelper::Matchers it "returns a meaningful LCS array with (seq1, seq2)" do res = Diff::LCS::Internals.lcs(seq1, seq2) # The result of the LCS (less the +nil+ values) must be as long as the # correct result. expect(res.compact.size).to eq(correct_lcs.size) expect(res).to correctly_map_sequence(seq1).to_other_sequence(seq2) # Compact these transformations and they should be the correct LCS. x_seq1 = (0...res.size).map { |ix| res[ix] ? seq1[ix] : nil }.compact x_seq2 = (0...res.size).map { |ix| res[ix] ? seq2[res[ix]] : nil }.compact expect(x_seq1).to eq(correct_lcs) expect(x_seq2).to eq(correct_lcs) end it "returns all indexes with (hello, hello)" do expect(Diff::LCS::Internals.lcs(hello, hello)).to \ eq((0...hello.size).to_a) end it "returns all indexes with (hello_ary, hello_ary)" do expect(Diff::LCS::Internals.lcs(hello_ary, hello_ary)).to \ eq((0...hello_ary.size).to_a) end end describe Diff::LCS, ".LCS" do include Diff::LCS::SpecHelper::Matchers it "returns the correct compacted values from Diff::LCS.LCS" do res = Diff::LCS.LCS(seq1, seq2) expect(res).to eq(correct_lcs) expect(res.compact).to eq(res) end it "is transitive" do res = Diff::LCS.LCS(seq2, seq1) expect(res).to eq(correct_lcs) expect(res.compact).to eq(res) end it "returns %W(h e l l o) with (hello, hello)" do expect(Diff::LCS.LCS(hello, hello)).to eq(hello.chars) end it "returns hello_ary with (hello_ary, hello_ary)" do expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary) end end diff-lcs-1.5.1/spec/issues_spec.rb0000644000004100000410000001053414571064670017056 0ustar www-datawww-data# frozen_string_literal: true require "spec_helper" require "diff/lcs/hunk" describe "Diff::LCS Issues" do include Diff::LCS::SpecHelper::Matchers describe "issue #1" do shared_examples "handles simple diffs" do |s1, s2, forward_diff| before do @diff_s1_s2 = Diff::LCS.diff(s1, s2) end it "creates the correct diff" do expect(change_diff(forward_diff)).to eq(@diff_s1_s2) end it "creates the correct patch s1->s2" do expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2) end it "creates the correct patch s2->s1" do expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1) end end describe "string" do it_has_behavior "handles simple diffs", "aX", "bXaX", [ [ ["+", 0, "b"], ["+", 1, "X"] ] ] it_has_behavior "handles simple diffs", "bXaX", "aX", [ [ ["-", 0, "b"], ["-", 1, "X"] ] ] end describe "array" do it_has_behavior "handles simple diffs", %w[a X], %w[b X a X], [ [ ["+", 0, "b"], ["+", 1, "X"] ] ] it_has_behavior "handles simple diffs", %w[b X a X], %w[a X], [ [ ["-", 0, "b"], ["-", 1, "X"] ] ] end end describe "issue #57" do it "should fail with a correct error" do # standard:disable Style/HashSyntax expect { actual = {:category => "app.rack.request"} expected = {:category => "rack.middleware", :title => "Anonymous Middleware"} expect(actual).to eq(expected) }.to raise_error(RSpec::Expectations::ExpectationNotMetError) # standard:enable Style/HashSyntax end end describe "issue #60" do it "should produce unified output with correct context" do # standard:disable Layout/HeredocIndentation old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp) { "name": "x", "description": "hi" } DATA_OLD new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp) { "name": "x", "description": "lo" } DATA_NEW diff = ::Diff::LCS.diff(old_data, new_data) hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0) expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp) @@ -1,5 +1,5 @@ { "name": "x", - "description": "hi" + "description": "lo" } EXPECTED # standard:enable Layout/HeredocIndentation end end describe "issue #65" do def diff_lines(old_lines, new_lines) file_length_difference = 0 previous_hunk = nil output = [] Diff::LCS.diff(old_lines, new_lines).each do |piece| hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, 3, file_length_difference) file_length_difference = hunk.file_length_difference maybe_contiguous_hunks = previous_hunk.nil? || hunk.merge(previous_hunk) output << "#{previous_hunk.diff(:unified)}\n" unless maybe_contiguous_hunks previous_hunk = hunk end output << "#{previous_hunk.diff(:unified, true)}\n" unless previous_hunk.nil? output.join end it "should not misplace the new chunk" do old_data = [ "recipe[a::default]", "recipe[b::default]", "recipe[c::default]", "recipe[d::default]", "recipe[e::default]", "recipe[f::default]", "recipe[g::default]", "recipe[h::default]", "recipe[i::default]", "recipe[j::default]", "recipe[k::default]", "recipe[l::default]", "recipe[m::default]", "recipe[n::default]" ] new_data = [ "recipe[a::default]", "recipe[c::default]", "recipe[d::default]", "recipe[e::default]", "recipe[f::default]", "recipe[g::default]", "recipe[h::default]", "recipe[i::default]", "recipe[j::default]", "recipe[k::default]", "recipe[l::default]", "recipe[m::default]", "recipe[n::default]", "recipe[o::new]", "recipe[p::new]", "recipe[q::new]", "recipe[r::new]" ] # standard:disable Layout/HeredocIndentation expect(diff_lines(old_data, new_data)).to eq(<<-EODIFF) @@ -1,5 +1,4 @@ recipe[a::default] -recipe[b::default] recipe[c::default] recipe[d::default] recipe[e::default] @@ -12,3 +11,7 @@ recipe[l::default] recipe[m::default] recipe[n::default] +recipe[o::new] +recipe[p::new] +recipe[q::new] +recipe[r::new] EODIFF # standard:enable Layout/HeredocIndentation end end end diff-lcs-1.5.1/.rspec0000644000004100000410000000001114571064670014354 0ustar www-datawww-data--colour diff-lcs-1.5.1/Rakefile0000644000004100000410000000624114571064670014717 0ustar www-datawww-data# frozen_string_literal: true require "rubygems" require "rspec" require "rspec/core/rake_task" require "hoe" # This is required until https://github.com/seattlerb/hoe/issues/112 is fixed class Hoe def with_config config = Hoe::DEFAULT_CONFIG rc = File.expand_path("~/.hoerc") homeconfig = load_config(rc) config = config.merge(homeconfig) localconfig = load_config(File.expand_path(File.join(Dir.pwd, ".hoerc"))) config = config.merge(localconfig) yield config, rc end def load_config(name) File.exist?(name) ? safe_load_yaml(name) : {} end def safe_load_yaml(name) return safe_load_yaml_file(name) if YAML.respond_to?(:safe_load_file) data = IO.binread(name) YAML.safe_load(data, permitted_classes: [Regexp]) rescue YAML.safe_load(data, [Regexp]) end def safe_load_yaml_file(name) YAML.safe_load_file(name, permitted_classes: [Regexp]) rescue YAML.safe_load_file(name, [Regexp]) end end Hoe.plugin :bundler Hoe.plugin :doofus Hoe.plugin :gemspec2 Hoe.plugin :git if RUBY_VERSION < "1.9" class Array # :nodoc: def to_h Hash[*flatten(1)] end end class Gem::Specification # :nodoc: def metadata=(*) end def default_value(*) end end class Object # :nodoc: def caller_locations(*) [] end end end _spec = Hoe.spec "diff-lcs" do developer("Austin Ziegler", "halostatue@gmail.com") require_ruby_version ">= 1.8" self.history_file = "History.md" self.readme_file = "README.rdoc" self.licenses = ["MIT", "Artistic-2.0", "GPL-2.0-or-later"] spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" } extra_dev_deps << ["hoe", ">= 3.0", "< 5"] extra_dev_deps << ["hoe-doofus", "~> 1.0"] extra_dev_deps << ["hoe-gemspec2", "~> 1.1"] extra_dev_deps << ["hoe-git2", "~> 1.7"] extra_dev_deps << ["hoe-rubygems", "~> 1.0"] extra_dev_deps << ["rspec", ">= 2.0", "< 4"] extra_dev_deps << ["rake", ">= 10.0", "< 14"] extra_dev_deps << ["rdoc", ">= 6.3.1", "< 7"] end desc "Run all specifications" RSpec::Core::RakeTask.new(:spec) do |t| rspec_dirs = %w[spec lib].join(":") t.rspec_opts = ["-I#{rspec_dirs}"] end Rake::Task["spec"].actions.uniq! { |a| a.source_location } # standard:disable Style/HashSyntax task :default => :spec unless Rake::Task["default"].prereqs.include?("spec") task :test => :spec unless Rake::Task["test"].prereqs.include?("spec") # standard:enable Style/HashSyntax if RUBY_VERSION >= "2.0" && RUBY_ENGINE == "ruby" namespace :spec do desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed." task :coverage do ENV["COVERAGE"] = "yes" Rake::Task["spec"].execute end end end task :ruby18 do # standard:disable Layout/HeredocIndentation puts <<-MESSAGE You are starting a barebones Ruby 1.8 docker environment. You will need to do the following: - mv Gemfile.lock{,.v2} - gem install bundler --version 1.17.2 --no-ri --no-rdoc - ruby -S bundle - rake Don't forget to restore your Gemfile.lock after testing. MESSAGE # standard:enable Layout/HeredocIndentation sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l" end diff-lcs-1.5.1/docs/0000755000004100000410000000000014571064670014177 5ustar www-datawww-datadiff-lcs-1.5.1/docs/COPYING.txt0000644000004100000410000004325414571064670016060 0ustar www-datawww-data GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. diff-lcs-1.5.1/docs/artistic.txt0000644000004100000410000001372714571064670016574 0ustar www-datawww-dataThe "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End diff-lcs-1.5.1/Code-of-Conduct.md0000644000004100000410000000623614571064670016451 0ustar www-datawww-data# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ diff-lcs-1.5.1/Contributing.md0000644000004100000410000000610514571064670016242 0ustar www-datawww-data## Contributing I value any contribution to Diff::LCS you can provide: a bug report, a feature request, or code contributions. Code contributions to Diff::LCS are especially welcomeencouraged. Because Diff::LCS is a complex codebase, there are a few guidelines: - Code changes _will not_ be accepted without tests. The test suite is written with [RSpec][]. - Match my coding style. - Use a thoughtfully-named topic branch that contains your change. Rebase your commits into logical chunks as necessary. - Use [quality commit messages][]. - Do not change the version number; when your patch is accepted and a release is made, the version will be updated at that point. - Submit a GitHub pull request with your changes. - New or changed behaviours require appropriate documentation. ### Test Dependencies Diff::LCS uses Ryan Davis’s [Hoe][] to manage the release process, and it adds a number of rake tasks. You will mostly be interested in: ```sh $ rake ``` which runs the tests the same way that: ```sh $ rake spec ``` will do. To assist with the installation of the development dependencies, I have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file. This will permit you to do: ```sh $ bundle install ``` to get the development dependencies. If you aleady have `hoe` installed, you can accomplish the same thing with: ```sh $ rake newb ``` This task will install any missing dependencies, run the tests/specs, and generate the RDoc. You can run tests with code coverage analysis by running: ```sh $ rake spec:coverage ``` ### Workflow Here's the most direct way to get your work merged into the project: - Fork the project. - Clone down your fork (`git clone git://github.com//diff-lcs.git`). - Create a topic branch to contain your change (`git checkout -b my_awesome_feature`). - Hack away, add tests. Not necessarily in that order. - Make sure everything still passes by running `rake`. - If necessary, rebase your commits into logical chunks, without errors. - Push the branch up (`git push origin my_awesome_feature`). - Create a pull request against halostatue/diff-lcs and describe what your change does and the why you think it should be merged. ### Contributors - Austin Ziegler created Diff::LCS. Thanks to everyone else who has contributed code or bug reports to Diff::LCS: - @ginriki - @joshbronson - @kevinmook - @mckaz - Akinori Musha - Artem Ignatyev - Brandon Fish - Camille Drapier - Cédric Boutillier - Gregg Kellogg - Jagdeep Singh - Jason Gladish - Jon Rowe - Josef Strzibny - Josep (@apuratepp) - Josh Bronson - Jun Aruga - Justin Steele - Kenichi Kamiya - Kensuke Nagae - Kevin Ansfield - Koichi Ito - Mark Friedgan - Michael Granger - Myron Marston - Nicolas Leger - Oleg Orlov - Paul Kunysch - Pete Higgins - Peter Goldstein - Peter Wagenet - Philippe Lafoucrière - Ryan Lovelett - Scott Steele - Simon Courtois - Tien (@tiendo1011) - Tomas Jura - Vít Ondruch [rspec]: http://rspec.info/documentation/ [quality commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html [hoe]: https://github.com/seattlerb/hoe diff-lcs-1.5.1/License.md0000644000004100000410000000344614571064670015162 0ustar www-datawww-data# License This software is available under three licenses: the GNU GPL version 2 (or at your option, a later version), the Perl Artistic license, or the MIT license. Note that my preference for licensing is the MIT license, but Algorithm::Diff was dually originally licensed with the Perl Artistic and the GNU GPL ("the same terms as Perl itself") and given that the Ruby implementation originally hewed pretty closely to the Perl version, I must maintain the additional licensing terms. * Copyright 2004–2013 Austin Ziegler. * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by Mario I. Wolczko. ## MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ## Perl Artistic License See the file docs/artistic.txt in the main distribution. ## GNU GPL version 2 See the file docs/COPYING.txt in the main distribution. diff-lcs-1.5.1/History.md0000644000004100000410000003722114571064670015237 0ustar www-datawww-data# History ## 1.5.1 / 2024-01-31 - Peter Goldstein updated CI configuration to add Ruby 3.1 and Masato Nakamura added Ruby 3.2 and 3.3. [#82][], [#89][] - Updated the CI configuration, resolving [#82][] to add Ruby 3.1. Masato - Switched to [standard ruby][] formatting. - Justin Steele converted the licence file to Markdown. [#84][] - Updated the gem SPDX identifier for GPL 2.0 or later, resolving [#86][] by Vit Ondruch. - Resolve a potential security issue with `ldiff` in its use of `IO.read` instead of `File.read`. [#91][] - Added MFA authentication requirement for release to RubyGems. [#90][] - Added dependabot management for actions and gems. [#90][] - Updated CodeQL coniguration. [#90][] ## 1.5.0 / 2021-12-23 - Updated the CI configuration and monkey-patch Hoe. - Kenichi Kamiya fixed a test configuration deprecation in SimpleCov. [#69][] - Tien introduced several corrections and code improvements: - Removed an off-by-one error when calculating an index value by embracing Ruby iteration properly. This had a side-effect of fixing a long-standing bug in `#traverse_sequences` where the traversal would not be transitive. That is, `LCS(s2, s1)` should produce a sequence that is transitive with `LCS(s1, s2)` on traversal, and applying the diff computed from those results would result in equivalent changes that could be played forward or backward as appropriate. [#71][], [#75][] - The above fix resulted in a changed order of the longest common subsequence when callbacks were applied. After analysis, it was determined that the computed subsequence was _equivalent_ to the prior version, so the test was updated. This also resulted in the clarification of documentation when traversing the subsequences. [#79][] - An infinite loop case in the case where Diff::LCS would be included into an enumerable class has been fixed. [#73][] - Clarified the purpose of a threshold test in calculation of LCS. [#72][], [#80][] - Removed autotest directory ## 1.4.4 / 2020-07-01 - Fixed an issue reported by Jun Aruga in the Diff::LCS::Ldiff binary text detection. [#44][] - Fixed a theoretical issue reported by Jun Aruga in Diff::LCS::Hunk to raise a more useful exception. [#43][] - Added documentation that should address custom object issues as reported in [#35][]. - Fixed more diff errors, in part reported in [#65][]. - The use of `Numeric#abs` is incorrect in `Diff::LCS::Block#diff_size`. The diff size _must_ be accurate for correct change placement. - When selecting @max_diff_size in Diff::LCS::Hunk, choose it based on `block.diff_size.abs`. - Made a number of changes that will, unfortunately, increase allocations at the cost of being safe with frozen strings. - Add some knowledge that when `Diff::LCS::Hunk#diff` is called, that we are processing the _last_ hunk, so some changes will be made to how the output is generated. - `old`, `ed`, and `reverse_ed` formats have no differences. - `unified` format will report `\ No newline at end of file` given the correct conditions, at most once. Unified range reporting also differs for the last hunk such that the `length` of the range is reduced by one. - `context` format will report `\No newline at end of file` given the correct conditions, up to once per "file". Context range reporting also differs for the last hunk such that the `end` part of the range is reduced by one to a minimum of one. - Added a bunch more tests for the cases above, and fixed `hunk_spec.rb` so that the phrase being compared isn't nonsense French. - Updated formatting. - Added a Rake task to assist with manual testing on Ruby 1.8. ## 1.4.3 / 2020-06-29 - Fixed several issues with the 1.4 on Rubies older than 2.0. Some of this was providing useful shim functions to Hoe 3.x (which dropped these older Rubies a while ago). Specifically: - Removed Array#lazy from a method in Diff::LCS::Hunk. - Changed some unit tests to use old-style Symbol-keyed hashes. - Changed some unit test helper functions to no longer use keyword parameters, but only a trailing options hash. - Made the use of `psych` dependent on `RUBY_VERSION >= 1.9`. Resolves [#63][]. ## 1.4.2 / 2020-06-23 - Camille Drapier fixed a small issue with RuboCop configuration. [#59][] - Applied another fix (and unit test) to fix an issue for the Chef team. [#60][], [#61][] ## 1.4.1 / 2020-06-23 - Fix an issue where diff sizes could be negative, and they should be. [#57][], [#58][] ## 1.4 / 2020-06-23 - Ruby versions lower than 2.4 are soft-deprecated and will not be run as part of the CI process any longer. - Akinora MUSHA (knu) added the ability for Diff::LCS::Change objects to be implicitly treated arrays. Originally provided as pull request [#47][], but it introduced a number of test failures as documented in [#48][], and remediation of Diff::LCS itself was introduced in [#49][]. - Resolved [#5][] with some tests comparing output from `system` calls to `bin/ldiff` with some pre-generated output. Resolved [#6][] with these tests. - Resolved a previously undetected `bin/ldiff` issue with `--context` output not matching `diff --context` output. - Resolved an issue with later versions of Ruby not working with an `OptParse` specification of `Numeric`; this has been changed to `Integer`. - Brandon Fish added truffleruby in [#52][]. - Fixed two missing classes as reported in [#53][]. ## 1.3 / 2017-01-18 - Bugs fixed: - Fixed an error for bin/ldiff --version. Fixes issue [#21][]. - Force Diff::LCS::Change and Diff::LCS::ContextChange to only perform equality comparisons against themselves. Provided by Kevin Mook in pull request [#29][]. - Fix tab expansion in htmldiff, provided by Mark Friedgan in pull request [#25][]. - Silence Ruby 2.4 Fixnum deprecation warnings. Fixes issue [#38][] and pull request [#36][]. - Ensure that test dependencies are loaded properly. Fixes issue [#33][] and pull request [#34][]. - Fix issue [#1][] with incorrect intuition of patch direction. Tentative fix, but the previous failure cases pass now. - Tooling changes: - Added SimpleCov and Coveralls support. - Change the homepage (temporarily) to the GitHub repo. - Updated testing and gem infrastructure. - Modernized the specs. - Cleaned up documentation. - Added a Code of Conduct. ## 1.2.5 / 2013-11-08 - Bugs fixed: - Comparing arrays flattened them too far, especially with Diff::LCS.sdiff. Fixed by Josh Bronson in pull request [#23][]. ## 1.2.4 / 2013-04-20 - Bugs fixed: - A bug was introduced after 1.1.3 when pruning common sequences at the start of comparison. Paul Kunysch (@pck) fixed this in pull request [#18][]. Thanks! - The Rubinius (1.9 mode) bug in [rubinius/rubinius#2268][] has been fixed by the Rubinius team two days after it was filed. Thanks for fixing this so quickly! - Switching to Raggi's hoe-gemspec2 for gemspec generation. ## 1.2.3 / 2013-04-11 - Bugs Fixed: - The new encoding detection for diff output generation (added in 1.2.2) introduced a bug if the left side of the comparison was the empty set. Originally found in [rspec/rspec-expectations#238][] and [rspec/rspec-expectations#239][]. Jon Rowe developed a reasonable heuristic (left side, right side, empty string literal) to avoid this bug. - There is a known issue with Rubinius in 1.9 mode reported in [rubinius/rubinius#2268][] and demonstrated in the Travis CI builds. For all other tested platforms, diff-lcs is considered stable. As soon as a suitably small test-case can be created for the Rubinius team to examine, this will be added to the Rubinius issue around this. ## 1.2.2 / 2013-03-30 - Bugs Fixed: - Diff::LCS::Hunk could not properly generate a difference for comparison sets that are not US-ASCII-compatible because of the use of literal regular expressions and strings. Jon Rowe found this in [rspec/rspec-expectations#219][] and provided a first pass implementation in pull request [#15][]. I've reworked it because of test failures in Rubinius when running in Ruby 1.9 mode. This coerces the added values to the encoding of the old dataset (as determined by the first piece of the old dataset). - Adding Travis CI testing for Ruby 2.0. ## 1.2.1 / 2013-02-09 - Bugs Fixed: - As seen in [rspec/rspec-expectations#200][], the release of Diff::LCS 1.2 introduced an unnecessary public API change to Diff::LCS::Hunk (see the change at [rspec/rspec-expectations@3d6fc82c][] for details). The new method name (and behaviour) is more correct, but I should not have renamed the function or should have at least provided an alias. This release restores Diff::LCS::Hunk#unshift as an alias to #merge. Note that the old #unshift behaviour was incorrect and will not be restored. ## 1.2.0 / 2013-01-21 - Minor Enhancements: - Added special case handling for Diff::LCS.patch so that it handles patches that are empty or contain no changes. - Added two new methods (#patch_me and #unpatch_me) to the includable module. - Bugs Fixed: - Fixed issue [#1][] patch direction detection. - Resolved issue [#2][] by handling `string[string.size, 1]` properly (it returns `""` not `nil`). - Michael Granger (ged) fixed an implementation error in Diff::LCS::Change and added specs in pull request [#8][]. Thanks! - Made the code auto-testable. - Vít Ondruch (voxik) provided the latest version of the GPL2 license file in pull request [#10][]. Thanks! - Fixed a documentation issue with the includable versions of #patch! and #unpatch! where they implied that they would replace the original value. Given that Diff::LCS.patch always returns a copy, the documentation was incorrect and has been corrected. To provide the behaviour that was originally documented, two new methods were added to provide this behaviour. Found by scooter-dangle in issue [#12][]. Thanks! - Code Style Changes: - Removed trailing spaces. - Calling class methods using `.` instead of `::`. - Vít Ondruch (voxik) removed unnecessary shebangs in pull request [#9][]. Thanks! - Kenichi Kamiya (kachick) removed some warnings of an unused variable in lucky pull request [#13][]. Thanks! - Embarked on a major refactoring to make the files a little more manageable and understand the code on a deeper level. - Adding to http://travis-ci.org. ## 1.1.3 / 2011-08-27 - Converted to 'hoe' for release. - Converted tests to RSpec 2. - Extracted the body of htmldiff into a class available from diff/lcs/htmldiff. - Migrated development and issue tracking to GitHub. - Bugs fixed: - Eliminated the explicit use of RubyGems in both bin/htmldiff and bin/ldiff. Resolves issue [#4][]. - Eliminated Ruby warnings. Resolves issue [#3][]. ## 1.1.2 / 2004-10-20 - Fixed a problem reported by Mauricio Fernandez in htmldiff. ## 1.1.1 / 2004-09-25 - Fixed bug #891 (Set returned from patch command does not contain last equal part). - Fixed a problem with callback initialisation code (it assumed that all callbacks passed as classes can be initialised; now, it rescues NoMethodError in the event of private :new being called). - Modified the non-initialisable callbacks to have a private #new method. - Moved ldiff core code to Diff::LCS::Ldiff (diff/lcs/ldiff.rb). ## 1.1.0 - Eliminated the need for Diff::LCS::Event and removed it. - Added a contextual diff callback, Diff::LCS::ContextDiffCallback. - Implemented patching/unpatching for standard Diff callback output formats with both #diff and #sdiff. - Extensive documentation changes. ## 1.0.4 - Fixed a problem with bin/ldiff output, especially for unified format. Newlines that should have been present weren't. - Changed the .tar.gz installer to generate Windows batch files if ones do not exist already. Removed the existing batch files as they didn't work. ## 1.0.3 - Fixed a problem with #traverse_sequences where the first difference from the left sequence might not be appropriately captured. ## 1.0.2 - Fixed an issue with ldiff not working because actions were changed from symbols to strings. ## 1.0.1 - Minor modifications to the gemspec, the README. - Renamed the diff program to ldiff (as well as the companion batch file) so as to not collide with the standard diff program. - Fixed issues with RubyGems. Requires RubyGems > 0.6.1 or >= 0.6.1 with the latest CVS version. ## 1.0 - Initial release based mostly on Perl's Algorithm::Diff. [#1]: https://github.com/halostatue/diff-lcs/issues/1 [#2]: https://github.com/halostatue/diff-lcs/issues/2 [#3]: https://github.com/halostatue/diff-lcs/issues/3 [#4]: https://github.com/halostatue/diff-lcs/issues/4 [#5]: https://github.com/halostatue/diff-lcs/issues/5 [#6]: https://github.com/halostatue/diff-lcs/issues/6 [#8]: https://github.com/halostatue/diff-lcs/pull/8 [#9]: https://github.com/halostatue/diff-lcs/pull/9 [#10]: https://github.com/halostatue/diff-lcs/pull/10 [#12]: https://github.com/halostatue/diff-lcs/issues/12 [#13]: https://github.com/halostatue/diff-lcs/pull/13 [#15]: https://github.com/halostatue/diff-lcs/pull/15 [#18]: https://github.com/halostatue/diff-lcs/pull/18 [#21]: https://github.com/halostatue/diff-lcs/issues/21 [#23]: https://github.com/halostatue/diff-lcs/pull/23 [#25]: https://github.com/halostatue/diff-lcs/pull/25 [#29]: https://github.com/halostatue/diff-lcs/pull/29 [#33]: https://github.com/halostatue/diff-lcs/issues/33 [#34]: https://github.com/halostatue/diff-lcs/pull/34 [#35]: https://github.com/halostatue/diff-lcs/issues/35 [#36]: https://github.com/halostatue/diff-lcs/pull/36 [#38]: https://github.com/halostatue/diff-lcs/issues/38 [#43]: https://github.com/halostatue/diff-lcs/issues/43 [#44]: https://github.com/halostatue/diff-lcs/issues/44 [#47]: https://github.com/halostatue/diff-lcs/pull/47 [#48]: https://github.com/halostatue/diff-lcs/issues/48 [#49]: https://github.com/halostatue/diff-lcs/pull/49 [#52]: https://github.com/halostatue/diff-lcs/pull/52 [#53]: https://github.com/halostatue/diff-lcs/issues/53 [#57]: https://github.com/halostatue/diff-lcs/issues/57 [#58]: https://github.com/halostatue/diff-lcs/pull/58 [#59]: https://github.com/halostatue/diff-lcs/pull/59 [#60]: https://github.com/halostatue/diff-lcs/issues/60 [#61]: https://github.com/halostatue/diff-lcs/pull/61 [#63]: https://github.com/halostatue/diff-lcs/issues/63 [#65]: https://github.com/halostatue/diff-lcs/issues/65 [#69]: https://github.com/halostatue/diff-lcs/issues/69 [#71]: https://github.com/halostatue/diff-lcs/issues/71 [#72]: https://github.com/halostatue/diff-lcs/issues/72 [#73]: https://github.com/halostatue/diff-lcs/issues/73 [#75]: https://github.com/halostatue/diff-lcs/issues/75 [#79]: https://github.com/halostatue/diff-lcs/issues/79 [#80]: https://github.com/halostatue/diff-lcs/issues/80 [#82]: https://github.com/halostatue/diff-lcs/pull/82 [#84]: https://github.com/halostatue/diff-lcs/pull/84 [#86]: https://github.com/halostatue/diff-lcs/pull/86 [#89]: https://github.com/halostatue/diff-lcs/pull/89 [#90]: https://github.com/halostatue/diff-lcs/pull/90 [#91]: https://github.com/halostatue/diff-lcs/issues/91 [rspec/rspec-expectations#200]: https://github.com/rspec/rspec-expectations/pull/200 [rspec/rspec-expectations#219]: https://github.com/rspec/rspec-expectations/issues/219 [rspec/rspec-expectations#238]: https://github.com/rspec/rspec-expectations/issues/238 [rspec/rspec-expectations#239]: https://github.com/rspec/rspec-expectations/issues/239 [rspec/rspec-expectations@3d6fc82c]: https://github.com/rspec/rspec-expectations/commit/3d6fc82c [rubinius/rubinius#2268]: https://github.com/rubinius/rubinius/issues/2268 [standard ruby]: https://github.com/standardrb/standard