Skip to content

Commit

Permalink
Drop ed & reverse_ed formats
Browse files Browse the repository at this point in the history
These formats are super old and very unlikely used.
Their implementation was broken for a while and no-one reported it.

The GNU doc say that ed format is "almost obsolete". [1]
The reverse_ed (aka forward-ed) is described as "not very useful". [2]

[1]: https://www.gnu.org/software/diffutils/manual/html_node/ed-Scripts.html
[2]: https://www.gnu.org/software/diffutils/manual/html_node/Forward-ed.html
  • Loading branch information
Annih committed Jan 31, 2025
1 parent bc14f1d commit 5716d6f
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 77 deletions.
27 changes: 1 addition & 26 deletions lib/diff/lcs/hunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# block.) Used in the diff program (bin/ldiff).
class Diff::LCS::Hunk
OLD_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc:
ED_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc:

private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant)
private_constant :OLD_DIFF_OP_ACTION, if respond_to?(:private_constant)

# Create a hunk using references to both the old and new data, as well as the
# piece of data.
Expand Down Expand Up @@ -120,10 +119,6 @@ def diff(format, last = false)
unified_diff(last)
when :context
context_diff(last)
when :ed
self
when :reverse_ed, :ed_finish
ed_diff(format, last)
else
fail "Unknown diff format #{format}."
end
Expand Down Expand Up @@ -273,26 +268,6 @@ def context_diff(last = false)
end
private :context_diff

def ed_diff(format, _last = false)
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1

s =
if format == :reverse_ed
encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ",")}\n")
else
encode("#{context_range(:old, " ")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n")
end

unless @blocks[0].insert.empty?
@data_new[@start_new..@end_new].each do |e|
s << e.chomp + encode("\n")
end
s << encode(".\n")
end
s
end
private :ed_diff

# Generate a range of item numbers to print. Only print 1 number if the
# range has only one item in it. Otherwise, it's 'start,end'
def context_range(mode, op, last = false)
Expand Down
13 changes: 0 additions & 13 deletions lib/diff/lcs/ldiff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
@format = :unified
@lines = ctx || 3
end
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|
@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."
Expand Down Expand Up @@ -140,11 +134,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
# Otherwise, print out the old one.
oldhunk = hunk = nil

if @format == :ed
real_output = output
output = []
end

diffs.each do |piece|
begin # rubocop:disable Style/RedundantBegin
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines, file_length_difference)
Expand All @@ -165,8 +154,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:

output << last

output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed

1
end
end
3 changes: 0 additions & 3 deletions spec/fixtures/ldiff/output.diff-e

This file was deleted.

3 changes: 0 additions & 3 deletions spec/fixtures/ldiff/output.diff-f

This file was deleted.

3 changes: 0 additions & 3 deletions spec/fixtures/ldiff/output.diff.chef-e

This file was deleted.

3 changes: 0 additions & 3 deletions spec/fixtures/ldiff/output.diff.chef-f

This file was deleted.

7 changes: 0 additions & 7 deletions spec/fixtures/ldiff/output.diff.chef2-e

This file was deleted.

7 changes: 0 additions & 7 deletions spec/fixtures/ldiff/output.diff.chef2-f

This file was deleted.

11 changes: 0 additions & 11 deletions spec/hunk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@
expect(hunk.diff(:old)).to eq(expected)
end

it "produces a reverse ed diff from the two pieces" do
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
c1
Tu a un carte avec {count} items
.
EXPECTED

expect(hunk.diff(:reverse_ed)).to eq(expected)
end

context "with empty first data set" do
let(:old_data) { [] }

Expand Down
2 changes: 1 addition & 1 deletion spec/ldiff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{:name => "output.diff", :left => "aX", :right => "bXaX"},
{:name => "output.diff.chef", :left => "old-chef", :right => "new-chef"},
{:name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2"}
].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)|
].product([nil, "-c", "-u"]).map { |(fixture, flag)|
fixture = fixture.dup
fixture[:flag] = flag
fixture
Expand Down

0 comments on commit 5716d6f

Please sign in to comment.