summaryrefslogtreecommitdiff
path: root/lib/diff/lcs/ldiff.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/diff/lcs/ldiff.rb')
-rw-r--r--lib/diff/lcs/ldiff.rb49
1 files changed, 27 insertions, 22 deletions
diff --git a/lib/diff/lcs/ldiff.rb b/lib/diff/lcs/ldiff.rb
index c789f46..d385f72 100644
--- a/lib/diff/lcs/ldiff.rb
+++ b/lib/diff/lcs/ldiff.rb
@@ -1,4 +1,4 @@
-# -*- ruby encoding: utf-8 -*-
+# frozen_string_literal: true
require 'optparse'
require 'ostruct'
@@ -7,7 +7,7 @@ require 'diff/lcs/hunk'
module Diff::LCS::Ldiff #:nodoc:
BANNER = <<-COPYRIGHT
ldiff #{Diff::LCS::VERSION}
- Copyright 2004-2014 Austin Ziegler
+ Copyright 2004-2019 Austin Ziegler
Part of Diff::LCS.
https://github.com/halostatue/diff-lcs
@@ -15,7 +15,7 @@ ldiff #{Diff::LCS::VERSION}
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
+ COPYRIGHT
end
class << Diff::LCS::Ldiff
@@ -23,33 +23,42 @@ class << Diff::LCS::Ldiff
attr_reader :file_old, :file_new #:nodoc:
attr_reader :data_old, :data_new #:nodoc:
- def run(args, input = $stdin, output = $stdout, error = $stderr) #: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|
+ 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|
+ 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|
+ 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|
+ 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|
+ 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|
+ 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|
+ 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
@@ -60,7 +69,7 @@ class << Diff::LCS::Ldiff
error << Diff::LCS::Ldiff::BANNER
return 0
end
- o.on_tail ""
+ o.on_tail ''
o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.'
o.parse!
end
@@ -97,8 +106,7 @@ class << Diff::LCS::Ldiff
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
+ @binary = !old_txt or !new_txt
end
unless @binary
@@ -143,12 +151,11 @@ class << Diff::LCS::Ldiff
diffs.each do |piece|
begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines,
- file_length_difference)
+ 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)
+ next if @lines.postive? and hunk.merge(oldhunk)
output << oldhunk.diff(@format) << "\n"
ensure
@@ -158,10 +165,8 @@ class << Diff::LCS::Ldiff
output << oldhunk.diff(@format) << "\n"
- if @format == :ed
- output.reverse_each { |e| real_output << e.diff(:ed_finish) }
- end
+ output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed
- return 1
+ 1
end
end