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
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]', Numeric, '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]', Numeric, '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 << 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
if @binary.nil? or @binary
data_old = IO::read(file_old)
data_new = IO::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 = (not old_txt) or (not new_txt)
old_txt = new_txt = nil
end
unless @binary
data_old = data_old.split($/).map { |e| e.chomp }
data_new = data_new.split($/).map { |e| e.chomp }
end
else
data_old = IO::readlines(file_old).map { |e| e.chomp }
data_new = IO::readlines(file_new).map { |e| e.chomp }
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) or (@format == :context)
ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
puts "#{char_old} #{file_old}\t#{ft}"
ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
puts "#{char_new} #{file_new}\t#{ft}"
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
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 > 0) and hunk.merge(oldhunk)
output << oldhunk.diff(@format) << "\n"
ensure
oldhunk = hunk
end
end
output << oldhunk.diff(@format) << "\n"
if @format == :ed
output.reverse_each { |e| real_output << e.diff(:ed_finish) }
end
return 1
end
end
diff-lcs-1.2.5/lib/diff/lcs/change.rb 0000644 0000041 0000041 00000010121 12261202401 017230 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
# 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
# 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(+ - = ! > <)
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
unless Diff::LCS::Change.valid_action?(@action)
raise "Invalid Change Action '#{@action}'"
end
raise "Invalid Position Type" unless @position.kind_of? Fixnum
end
def inspect
to_a.inspect
end
def to_a
[ @action, @position, @element ]
end
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
raise "Invalid change array format provided."
end
end
include Comparable
def ==(other)
(self.action == other.action) and
(self.position == other.position) and
(self.element == other.element)
end
def <=>(other)
r = self.action <=> other.action
r = self.position <=> other.position if r.zero?
r = self.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
unless Diff::LCS::Change.valid_action?(@action)
raise "Invalid Change Action '#{@action}'"
end
unless @old_position.nil? or @old_position.kind_of? Fixnum
raise "Invalid (Old) Position Type"
end
unless @new_position.nil? or @new_position.kind_of? Fixnum
raise "Invalid (New) Position Type"
end
end
def to_a
[ @action,
[ @old_position, @old_element ],
[ @new_position, @new_element ]
]
end
def inspect(*args)
to_a.inspect
end
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)
(@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.2.5/lib/diff/lcs/internals.rb 0000644 0000041 0000041 00000020331 12261202401 020006 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
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.kind_of? 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 = []
# Prune off any common elements at the beginning...
while ((a_start <= a_finish) and (b_start <= b_finish) and
(a[a_start] == b[b_start]))
vector[a_start] = b_start
a_start += 1
b_start += 1
end
b_start = a_start
# Now the end...
while ((a_start <= a_finish) and (b_start <= b_finish) and
(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.
b_matches = position_hash(b, b_start..b_finish)
thresh = []
links = []
string = a.kind_of?(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|
if k and (thresh[k] > j) and (thresh[k - 1] < j)
thresh[k] = j
else
k = replace_next_larger(thresh, j, k)
end
links[k] = [ (k > 0) ? links[k - 1] : nil, i, j ] unless k.nil?
end
end
unless thresh.empty?
link = links[thresh.size - 1]
while not 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)
raise "Patchset too complex" if depth > 1
has_changes = false
# Format:
# [ # patchset
# # hunk (change)
# [ # hunk
# # change
# ]
# ]
patchset = patchset.map do |hunk|
case hunk
when Diff::LCS::Change
has_changes ||= !hunk.unchanged?
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?
hunk
else
with_changes, hunk = analyze_patchset(hunk, depth + 1)
has_changes ||= with_changes
hunk.flatten
end
else
raise ArgumentError, "Cannot normalise a hunk of class #{hunk.class}."
end
end
[ has_changes, patchset.flatten(1) ]
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.
#
# Note: This will be deprecated as a public function in a future release.
def intuit_diff_direction(src, patchset, limit = nil)
string = src.kind_of?(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
else
if re == change.new_element
right_match += 1
else
left_miss += 1
right_miss += 1
end
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 (not limit.nil?) && (count > limit)
end
no_left = (left_match == 0) && (left_miss > 0)
no_right = (right_match == 0) && (right_miss > 0)
case [no_left, no_right]
when [false, true]
:patch
when [true, false]
:unpatch
else
case left_match <=> right_match
when 1
:patch
when -1
:unpatch
else
raise "The provided patchset does not appear to apply to the provided value 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? or (value > enum[-1])
enum << value
return enum.size - 1
end
# Binary search for the insertion point
last_index ||= enum.size
first_index = 0
while (first_index <= last_index)
i = (first_index + last_index) >> 1
found = enum[i]
if value == found
return nil
elsif 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
return 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.kind_of?(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.2.5/lib/diff/lcs/block.rb 0000644 0000041 0000041 00000001372 12261202401 017105 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
# 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.2.5/lib/diff/lcs/array.rb 0000644 0000041 0000041 00000000130 12261202401 017120 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'diff/lcs'
class Array
include Diff::LCS
end
diff-lcs-1.2.5/lib/diff/lcs/callbacks.rb 0000644 0000041 0000041 00000024467 12261202401 017744 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
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 = []
if block_given?
begin
yield self
ensure
self.finish
end
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
#
# 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
#
# 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.2.5/lib/diff/lcs/hunk.rb 0000644 0000041 0000041 00000020616 12261202401 016762 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
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/diff).
class Diff::LCS::Hunk
# 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 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
# 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:
return if context.nil? or context.zero?
add_start = (context > @start_old) ? @start_old : context
@start_old -= add_start
@start_new -= add_start
if (@end_old + context) > @data_old.size
add_end = @data_old.size - @end_old
else
add_end = context
end
@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)
if overlaps?(hunk)
@start_old = hunk.start_old
@start_new = hunk.start_new
blocks.unshift(*hunk.blocks)
else
nil
end
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)
case format
when :old
old_diff
when :unified
unified_diff
when :context
context_diff
when :ed
self
when :reverse_ed, :ed_finish
ed_diff(format)
else
raise "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
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
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)}#{op_act[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.
@data_old[@start_old .. @end_old].each { |e| s << encode("< ") + e + encode("\n") } unless block.remove.empty?
s << encode("---\n") if block.op == "!"
@data_new[@start_new .. @end_new].each { |e| s << encode("> ") + e + encode("\n") } unless block.insert.empty?
s
end
private :old_diff
def unified_diff
# Calculate item number range.
s = encode("@@ -#{unified_range(:old)} +#{unified_range(:new)} @@\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
outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) }
@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
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]
num_added += 1
end
end
s << outlist.join(encode("\n"))
end
private :unified_diff
def context_diff
s = encode("***************\n")
s << encode("*** #{context_range(:old)} ****\n")
r = context_range(:new)
# 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.select { |e| not e.remove.empty? }
if removes
outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) }
removes.each do |block|
block.remove.each do |item|
outlist[item.position - lo][0, 1] = encode(block.op) # - or !
end
end
s << outlist.join("\n")
end
s << encode("\n--- #{r} ----\n")
lo, hi = @start_new, @end_new
inserts = @blocks.select { |e| not e.insert.empty? }
if inserts
outlist = @data_new[lo .. hi].collect { |e| e.insert(0, encode(' ')) }
inserts.each do |block|
block.insert.each do |item|
outlist[item.position - lo][0, 1] = encode(block.op) # + or !
end
end
s << outlist.join("\n")
end
s
end
private :context_diff
def ed_diff(format)
op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
if format == :reverse_ed
s = encode("#{op_act[@blocks[0].op]}#{context_range(:old)}\n")
else
s = encode("#{context_range(:old, ' ')}#{op_act[@blocks[0].op]}\n")
end
unless @blocks[0].insert.empty?
@data_new[@start_new .. @end_new].each { |e| s << e + encode("\n") }
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 = ',')
case mode
when :old
s, e = (@start_old + 1), (@end_old + 1)
when :new
s, e = (@start_new + 1), (@end_new + 1)
end
(s < e) ? "#{s}#{op}#{e}" : "#{e}"
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)
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 + 1
first = (length < 2) ? e : s # "strange, but correct"
(length == 1) ? "#{first}" : "#{first},#{length}"
end
private :unified_range
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.2.5/lib/diff/lcs/htmldiff.rb 0000644 0000041 0000041 00000006211 12261202401 017605 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'cgi'
class Diff::LCS::HTMLDiff
class << self
attr_accessor :can_expand_tabs #:nodoc:
end
self.can_expand_tabs = true
class Callbacks
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?
%Q|#{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
DEFAULT_OPTIONS = {
:expand_tabs => nil,
:output => nil,
:css => nil,
:title => nil,
}
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
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] < 0
@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] > 0 && self.class.can_expand_tabs
formatter = Text::Format.new
formatter.tabstop = @options[:expand_tabs]
@left = left.map { |line| formatter.expand(line.chomp) }
@right = right.map { |line| formatter.expand(line.chomp) }
end
@left.map! { |line| CGI.escapeHTML(line.chomp) }
@right.map! { |line| CGI.escapeHTML(line.chomp) }
@options[:output] << <<-OUTPUT
#{@options[:title]}
#{@options[:title]}
Legend: Only in Old
Only in New
OUTPUT
callbacks = Callbacks.new(@options[:output])
Diff::LCS.traverse_sequences(@left, @right, callbacks)
@options[:output] << <<-OUTPUT
OUTPUT
end
end
diff-lcs-1.2.5/lib/diff/lcs.rb 0000644 0000041 0000041 00000070435 12261202401 016021 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
module Diff; end unless defined? Diff
# = Diff::LCS 1.2.5
#
# Computes "intelligent" differences between two sequenced Enumerables. This
# is an implementation of the McIlroy-Hunt "diff" algorithm for Enumerable
# objects that include Diffable.
#
# Based on Mario I. Wolczko's Smalltalk version (1.2, 1993) and Ned Konz's
# Perl version (Algorithm::Diff 1.15).
#
# == Synopsis
# 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)
# seq2 == Diff::LCS.patch!(seq1, diffs)
# seq1 == Diff::LCS.unpatch(seq2, diffs)
# seq1 == Diff::LCS.unpatch!(seq2, diffs)
# seq2 == Diff::LCS.patch(seq1, sdiff)
# seq2 == Diff::LCS.patch!(seq1, sdiff)
# seq1 == Diff::LCS.unpatch(seq2, sdiff)
# seq1 == Diff::LCS.unpatch!(seq2, sdiff)
#
# Alternatively, 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)
# seq2 == seq1.patch!(diffs)
# seq1 == seq2.unpatch(diffs)
# seq1 == seq2.unpatch!(diffs)
# seq2 == seq1.patch(sdiff)
# seq2 == seq1.patch!(sdiff)
# seq1 == seq2.unpatch(sdiff)
# seq1 == seq2.unpatch!(sdiff)
#
# Default extensions are provided for Array and String objects through the
# use of 'diff/lcs/array' and 'diff/lcs/string'.
#
# == Introduction (by Mark-Jason Dominus)
#
# The following text is from the Perl documentation. The only changes
# have been to make the text appear better in Rdoc.
#
# 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
#
# == Author
# This version is by Austin Ziegler .
#
# It is based on the Perl Algorithm::Diff (1.15) by Ned Konz , copyright
# © 2000–2002 and the Smalltalk diff version by Mario I.
# Wolczko, copyright © 1993. Documentation includes work by
# Mark-Jason Dominus.
#
# == Licence
# Copyright © 2004–2013 Austin Ziegler
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Ruby, or alternatively under the Perl Artistic
# licence.
#
# == Credits
# Much of the documentation is taken directly from the Perl Algorithm::Diff
# implementation and was written originally by Mark-Jason Dominus and later
# by Ned Konz. The basic Ruby implementation was re-ported from the
# Smalltalk implementation, available at
# ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
#
# #sdiff and #traverse_balanced were 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."
module Diff::LCS
VERSION = '1.2.5'
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)
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)
traverse_sequences(self, other, callbacks ||
Diff::LCS.YieldingCallbacks, &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)
traverse_balanced(self, other, callbacks ||
Diff::LCS.YieldingCallbacks, &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.kind_of? String
matches.each_with_index do |e, i|
unless matches[i].nil?
v = string ? seq1[i, 1] : seq1[i]
v = block[v] if block
ret << v
end
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.
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 one of them and call
# the appropriate callback, but it is not specified which it will call.
#
# 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, &block) #:yields change events:
callbacks ||= Diff::LCS::SequenceCallbacks
matches = Diff::LCS::Internals.lcs(seq1, seq2)
run_finished_a = run_finished_b = false
string = seq1.kind_of?(String)
a_size = seq1.size
b_size = seq2.size
ai = bj = 0
(0..matches.size).each do |i|
b_line = matches[i]
ax = string ? seq1[i, 1] : seq1[i]
bx = string ? seq2[bj, 1] : seq2[bj]
if b_line.nil?
unless ax.nil? or (string and ax.empty?)
event = Diff::LCS::ContextChange.new('-', i, ax, bj, bx)
event = yield event if block_given?
callbacks.discard_a(event)
end
else
loop do
break unless bj < b_line
bx = string ? seq2[bj, 1] : seq2[bj]
event = Diff::LCS::ContextChange.new('+', i, 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('=', i, ax, bj, bx)
event = yield event if block_given?
callbacks.match(event)
bj += 1
end
ai = i
end
ai += 1
# 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) or (bj < b_size)
# last A?
if ai == a_size and bj < b_size
if callbacks.respond_to?(:finished_a) and not 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 and ai < a_size
if callbacks.respond_to?(:finished_b) and not 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.kind_of?(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 and matches[ma].nil?
end
break if ma >= matches.size # end of matches?
mb = matches[ma]
# Change(seq2)
while (ai < ma) or (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
bj += 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)
bj += 1
end
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) or (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
bj += 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)
bj += 1
end
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
PATCH_MAP = { #:nodoc:
:patch => { '+' => '+', '-' => '-', '!' => '!', '=' => '=' },
:unpatch => { '+' => '-', '-' => '+', '!' => '!', '=' => '=' }
}
# 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.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)
if not has_changes
return src.dup if src.respond_to? :dup
return src
end
string = src.kind_of?(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.flatten.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
diff-lcs-1.2.5/lib/diff-lcs.rb 0000644 0000041 0000041 00000000063 12261202401 016005 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'diff/lcs'
diff-lcs-1.2.5/metadata.yml 0000644 0000041 0000041 00000020074 12261202401 015532 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: diff-lcs
version: !ruby/object:Gem::Version
version: 1.2.5
platform: ruby
authors:
- Austin Ziegler
autorequire:
bindir: bin
cert_chain:
- !binary |-
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREJCTVE4d0RRWURWUVFEREFaaGRY
TjAKYVc0eEdUQVhCZ29Ka2lhSmsvSXNaQUVaRmdseWRXSjVabTl5WjJVeEV6
QVJCZ29Ka2lhSmsvSXNaQUVaRmdOdgpjbWN3SGhjTk1UTXdNakEwTURNek16
STNXaGNOTVRRd01qQTBNRE16TXpJM1dqQkJNUTh3RFFZRFZRUUREQVpoCmRY
TjBhVzR4R1RBWEJnb0praWFKay9Jc1pBRVpGZ2x5ZFdKNVptOXlaMlV4RXpB
UkJnb0praWFKay9Jc1pBRVoKRmdOdmNtY3dnZ0VpTUEwR0NTcUdTSWIzRFFF
QkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDMm1QTmY0TDM3R2hLSQpTUENZc3ZZ
V1hBMi9SOXU1K3B5VW5iSjJSMW8yQ2lScTJaQS9BSXpZNk4zaEduc2dvV25o
NVJ6dmdUTjFMdDA4CkROSXJzSUcyVkRZay9KVnQ2ZjlKNnpaOEVRSGJ6bldh
M2NXWW9DRmFhSUNkazdqVjFuLzQyaGc3MGpFRFlYbDkKZ0RPbDBrNkpteUYv
cnRmRnUvT0lrRkdXZUZZSXVGSHZSdUx5VWJ3NjYrUURUT3pLYjN0OG81NUlo
Z3kxR1Z3VAppNnBrRHM4TGhaV1hkT0QrOTIxbDJaMU5aR1phOUtOYkpJZzZ2
dGdZS1U5OGpRNXFyOWlZM2lrQkFzcEhyRmFzCks2VVN2R2dBZzhmQ0Q1WWlv
dEJFdkNCTVl0ZnFtZnJocGRVMnArZ3ZUZ2VMVzFLYWV2d3FkN25nUW1GVXJG
RzEKZVVKU1VSdjVBZ01CQUFHak9UQTNNQWtHQTFVZEV3UUNNQUF3SFFZRFZS
ME9CQllFRkF0SktNcDZZWU5xbGdSMwo5VGlaTFdxdkxhZ1NNQXNHQTFVZER3
UUVBd0lFc0RBTkJna3Foa2lHOXcwQkFRVUZBQU9DQVFFQXBUUGt2RG04Cjdn
SmxVVDRGZnVtWFB2dHVxUDY3THhVdEdFOHN5dlIwQTRBcyswUC93eWxMSkZV
T3NHVFRkWll0VGhoeENTSkcKKzdLRzJGZkljSDRaejJkOTdhclpHQXpCb2k4
aVBodDIvVXRTbDFmQ2NVSTV2bUphMU1pWFpUMm9xZFc3V3lkcQpyQVpjQlBs
cllZdWl3dEdJMHlxSU9nQmZYU1pDV1dzSnN1eVRLRUxlcDZtQ0xnejBZWlVm
bXZLcjhXL0FiM2F4CkR1THpIOTJMU1JqWkp5anlBVXB3L1ZjMnJNNGdpaVA1
anRCeXJiMVkxZEduUWhIVE1IZjFHZnVjV203TncvVjkKdHdFUFZ3OCswZjg4
SlF1Y3hPVG1URjFOYkxGcGlSd1FVWjF6b1piTmcyZTdtU2hjL2VleG5WTFdL
Rkt4Um9QNgpLUGozV29EK3NwQjhmQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
LS0tLS0K
date: 2013-11-08 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: rubyforge
requirement: !ruby/object:Gem::Requirement
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 2.0.4
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 2.0.4
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '4.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '4.0'
- !ruby/object:Gem::Dependency
name: hoe-bundler
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
- !ruby/object:Gem::Dependency
name: hoe-doofus
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
- !ruby/object:Gem::Dependency
name: hoe-gemspec2
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.1'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.1'
- !ruby/object:Gem::Dependency
name: hoe-git
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
- !ruby/object:Gem::Dependency
name: hoe-rubygems
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
- !ruby/object:Gem::Dependency
name: hoe-travis
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '10.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '10.0'
- !ruby/object:Gem::Dependency
name: rspec
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '2.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '2.0'
- !ruby/object:Gem::Dependency
name: hoe
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '3.7'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '3.7'
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.2.4, fixing a bug introduced after diff-lcs 1.1.3 that did
not properly prune common sequences at the beginning of a comparison set.
Thanks to Paul Kunysch for fixing this issue.
Coincident with the release of diff-lcs 1.2.3, we reported an issue with
Rubinius in 1.9 mode
({rubinius/rubinius#2268}[https://github.com/rubinius/rubinius/issues/2268]).
We are happy to report that this issue has been resolved.'
email:
- austin@rubyforge.org
executables:
- htmldiff
- ldiff
extensions: []
extra_rdoc_files:
- Contributing.rdoc
- History.rdoc
- License.rdoc
- Manifest.txt
- README.rdoc
- docs/COPYING.txt
- docs/artistic.txt
files:
- .autotest
- .gemtest
- .hoerc
- .rspec
- .travis.yml
- Contributing.rdoc
- Gemfile
- History.rdoc
- License.rdoc
- Manifest.txt
- README.rdoc
- Rakefile
- autotest/discover.rb
- 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/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/hunk_spec.rb
- spec/issues_spec.rb
- spec/lcs_spec.rb
- spec/patch_spec.rb
- spec/sdiff_spec.rb
- spec/spec_helper.rb
- spec/traverse_balanced_spec.rb
- spec/traverse_sequences_spec.rb
homepage: http://diff-lcs.rubyforge.org/
licenses:
- MIT
- Perl Artistic v2
- GNU GPL v2
metadata: {}
post_install_message:
rdoc_options:
- --main
- README.rdoc
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project: diff-lcs
rubygems_version: 2.0.7
signing_key:
specification_version: 4
summary: Diff::LCS computes the difference between two Enumerable sequences using
the McIlroy-Hunt longest common subsequence (LCS) algorithm
test_files: []
diff-lcs-1.2.5/autotest/ 0000755 0000041 0000041 00000000000 12261202401 015074 5 ustar www-data www-data diff-lcs-1.2.5/autotest/discover.rb 0000644 0000041 0000041 00000000044 12261202401 017235 0 ustar www-data www-data Autotest.add_discovery { "rspec2" }
diff-lcs-1.2.5/docs/ 0000755 0000041 0000041 00000000000 12261202401 014154 5 ustar www-data www-data diff-lcs-1.2.5/docs/COPYING.txt 0000644 0000041 0000041 00000043254 12261202401 016035 0 ustar www-data www-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.2.5/docs/artistic.txt 0000644 0000041 0000041 00000013727 12261202401 016551 0 ustar www-data www-data The "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.2.5/checksums.yaml.gz.sig 0000444 0000041 0000041 00000000400 12261202401 017265 0 ustar www-data www-data [E
Ne%\Hcxa{f[ fUx>M˿ 5İOq10iEP9-
v'|]+)Z/5Ԟ--!4'h$-k$o .S<36S7x>D{aTA_0a[