Skip to content

Commit

Permalink
Resolve #43
Browse files Browse the repository at this point in the history
  • Loading branch information
halostatue committed Jul 1, 2020
1 parent e5cbee7 commit 17bdff5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/diff/lcs/hunk.rb
Expand Up @@ -16,9 +16,15 @@ class Diff::LCS::Hunk
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[1].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

Expand All @@ -27,10 +33,11 @@ def initialize(data_old, data_new, piece, flag_context, file_length_difference)
@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.
# 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
Expand Down

0 comments on commit 17bdff5

Please sign in to comment.