summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2019-02-02 22:52:28 -0500
committerAustin Ziegler <austin@zieglers.ca>2019-02-04 10:33:18 -0500
commit15169228be42559f98fa6729d5f6bb32edad44e3 (patch)
tree0fe1626255811fae6b3c85ce406f0dc02c4987a2 /lib
parent3a89de07745fea52f611e6955f61c11ffd68c754 (diff)
downloaddiff-lcs-15169228be42559f98fa6729d5f6bb32edad44e3.tar.gz
Resolve multiple issues for 1.4
- Resolve ldiff output issues: Resolves #5 and #6 by adding system-output comparison calls to `bin/ldiff` compared against some pre-generated output. There is some timestamp manipulation involved with the output comparison, as the timestamps are unstable because of the way that git clone works. - Resolved a problem with bin/ldiff --context output. - Resolved a Numeric/Integer OptParse issue: later versions of Ruby had problems working with an `OptParse` option specification of `Numeric`; this has been changed to `Integer`.
Diffstat (limited to 'lib')
-rw-r--r--lib/diff/lcs/hunk.rb7
-rw-r--r--lib/diff/lcs/ldiff.rb15
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb
index 58a68db..4ec5123 100644
--- a/lib/diff/lcs/hunk.rb
+++ b/lib/diff/lcs/hunk.rb
@@ -20,6 +20,7 @@ class Diff::LCS::Hunk
before = after = file_length_difference
after += @blocks[0].diff_size
@file_length_difference = after # The caller must get this manually
+ @max_diff_size = @blocks.lazy.map { |e| e.diff_size }.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
@@ -70,6 +71,8 @@ class Diff::LCS::Hunk
context
end
+ add_end = @max_diff_size if add_end > @max_diff_size
+
@end_old += add_end
@end_new += add_end
end
@@ -190,7 +193,7 @@ class Diff::LCS::Hunk
removes.each do |block|
block.remove.each do |item|
- outlist[item.position - lo][0, 1] = encode(block.op) # - or !
+ outlist[item.position - lo].insert(0, encode(block.op)) # - or !
end
end
s << outlist.join("\n")
@@ -203,7 +206,7 @@ class Diff::LCS::Hunk
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 !
+ outlist[item.position - lo].insert(0, encode(block.op)) # - or !
end
end
s << outlist.join("\n")
diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb
index d385f72..2862267 100644
--- a/lib/diff/lcs/ldiff.rb
+++ b/lib/diff/lcs/ldiff.rb
@@ -30,14 +30,14 @@ class << Diff::LCS::Ldiff
o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile"
o.separator ''
o.on(
- '-c', '-C', '--context [LINES]', Numeric,
+ '-c', '-C', '--context [LINES]', Integer,
'Displays a context diff with LINES lines', 'of context. Default 3 lines.'
) do |ctx|
@format = :context
@lines = ctx || 3
end
o.on(
- '-u', '-U', '--unified [LINES]', Numeric,
+ '-u', '-U', '--unified [LINES]', Integer,
'Displays a unified diff with LINES lines', 'of context. Default 3 lines.'
) do |ctx|
@format = :unified
@@ -134,9 +134,9 @@ class << Diff::LCS::Ldiff
end
if (@format == :unified) or (@format == :context)
- ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
+ ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.000000000 %z')
output << "#{char_old} #{file_old}\t#{ft}\n"
- ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
+ ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.000000000 %z')
output << "#{char_new} #{file_new}\t#{ft}\n"
end
@@ -155,7 +155,7 @@ class << Diff::LCS::Ldiff
file_length_difference = hunk.file_length_difference
next unless oldhunk
- next if @lines.postive? and hunk.merge(oldhunk)
+ next if @lines.positive? and hunk.merge(oldhunk)
output << oldhunk.diff(@format) << "\n"
ensure
@@ -163,7 +163,10 @@ class << Diff::LCS::Ldiff
end
end
- output << oldhunk.diff(@format) << "\n"
+ last = oldhunk.diff(@format)
+ last << "\n" if last.respond_to?(:end_with?) && !last.end_with?("\n")
+
+ output << last
output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed