summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2020-06-23 23:17:37 -0400
committerGitHub <noreply@github.com>2020-06-23 23:17:37 -0400
commit20ea8f2a77b544c4aa8af1522102475ceeb9fff2 (patch)
tree5b07158601a57871d0141b93bcd0eb044c1fb36e /lib
parentce0190b0cdaba128d20d669917d23cd992b3af1d (diff)
parentcaeca628561ecf3c9d9c23b3ea9baf3865b9900d (diff)
downloaddiff-lcs-20ea8f2a77b544c4aa8af1522102475ceeb9fff2.tar.gz
Merge pull request #61 from halostatue/fix-issue-60v1.4.2
Change when max_diff_size is applied
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