summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2020-06-23 22:15:28 -0400
committerAustin Ziegler <austin@zieglers.ca>2020-06-23 22:15:28 -0400
commit9aabe2f63fcb1d15c80e26e00ddea12189dc9547 (patch)
treebe5f7ba9fe54a3453eb20df62f60b8c4912c4589 /lib
parentcef2f827c7d93cfcddc1ea64dfaab8c7ed784d41 (diff)
downloaddiff-lcs-9aabe2f63fcb1d15c80e26e00ddea12189dc9547.tar.gz
Change when max_diff_size is applied
- This appears to satisfy the issues found in #60 as well as providing the additional fixes required to properly test ldiff. Resolves #60
Diffstat (limited to 'lib')
-rw-r--r--lib/diff/lcs.rb2
-rw-r--r--lib/diff/lcs/hunk.rb19
2 files changed, 12 insertions, 9 deletions
diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb
index b6d0a86..1fce946 100644
--- a/lib/diff/lcs.rb
+++ b/lib/diff/lcs.rb
@@ -49,7 +49,7 @@ module Diff; end unless defined? Diff # rubocop:disable Style/Documentation
# a x b y c z p d q
# a b c a x b y c z
module Diff::LCS
- VERSION = '1.4.1'
+ VERSION = '1.4.2'
end
require 'diff/lcs/callbacks'
diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb
index 4ec5123..c6b3b25 100644
--- a/lib/diff/lcs/hunk.rb
+++ b/lib/diff/lcs/hunk.rb
@@ -2,12 +2,12 @@
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).
+# A Hunk is a group of Blocks which overlap because of the context surrounding
+# each block. (So if we're not using context, every hunk will contain one
+# block.) Used in the diff program (bin/ldiff).
class Diff::LCS::Hunk
- # Create a hunk using references to both the old and new data, as well as
- # the piece of data.
+ # 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)]
@@ -61,17 +61,20 @@ class Diff::LCS::Hunk
return if context.nil? or context.zero?
add_start = context > @start_old ? @start_old : context
+
@start_old -= add_start
@start_new -= add_start
+ old_size = @data_old.size
+
add_end =
- if (@end_old + context) > @data_old.size
- @data_old.size - @end_old
+ if (@end_old + context) > old_size
+ old_size - @end_old
else
context
end
- add_end = @max_diff_size if add_end > @max_diff_size
+ add_end = @max_diff_size if add_end >= old_size
@end_old += add_end
@end_new += add_end