Skip to content

Commit 5298695

Browse files
committed
Drop ed & reverse_ed formats
These formats are super old and very unlikely used. Their implementation was broken wor 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
1 parent bc14f1d commit 5298695

10 files changed

+2
-77
lines changed

lib/diff/lcs/hunk.rb

+1-26
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
# block.) Used in the diff program (bin/ldiff).
88
class Diff::LCS::Hunk
99
OLD_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc:
10-
ED_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc:
1110

12-
private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant)
11+
private_constant :OLD_DIFF_OP_ACTION, if respond_to?(:private_constant)
1312

1413
# Create a hunk using references to both the old and new data, as well as the
1514
# piece of data.
@@ -120,10 +119,6 @@ def diff(format, last = false)
120119
unified_diff(last)
121120
when :context
122121
context_diff(last)
123-
when :ed
124-
self
125-
when :reverse_ed, :ed_finish
126-
ed_diff(format, last)
127122
else
128123
fail "Unknown diff format #{format}."
129124
end
@@ -273,26 +268,6 @@ def context_diff(last = false)
273268
end
274269
private :context_diff
275270

276-
def ed_diff(format, _last = false)
277-
warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
278-
279-
s =
280-
if format == :reverse_ed
281-
encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ",")}\n")
282-
else
283-
encode("#{context_range(:old, " ")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n")
284-
end
285-
286-
unless @blocks[0].insert.empty?
287-
@data_new[@start_new..@end_new].each do |e|
288-
s << e.chomp + encode("\n")
289-
end
290-
s << encode(".\n")
291-
end
292-
s
293-
end
294-
private :ed_diff
295-
296271
# Generate a range of item numbers to print. Only print 1 number if the
297272
# range has only one item in it. Otherwise, it's 'start,end'
298273
def context_range(mode, op, last = false)

lib/diff/lcs/ldiff.rb

-13
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
4444
@format = :unified
4545
@lines = ctx || 3
4646
end
47-
o.on("-e", "Creates an 'ed' script to change", "oldfile to newfile.") do |_ctx|
48-
@format = :ed
49-
end
50-
o.on("-f", "Creates an 'ed' script to change", "oldfile to newfile in reverse order.") do |_ctx|
51-
@format = :reverse_ed
52-
end
5347
o.on(
5448
"-a", "--text",
5549
"Treat the files as text and compare them", "line-by-line, even if they do not seem", "to be text."
@@ -140,11 +134,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
140134
# Otherwise, print out the old one.
141135
oldhunk = hunk = nil
142136

143-
if @format == :ed
144-
real_output = output
145-
output = []
146-
end
147-
148137
diffs.each do |piece|
149138
begin # rubocop:disable Style/RedundantBegin
150139
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines, file_length_difference)
@@ -165,8 +154,6 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) # :nodoc:
165154

166155
output << last
167156

168-
output.reverse_each { |e| real_output << e.diff(:ed_finish) } if @format == :ed
169-
170157
1
171158
end
172159
end

spec/fixtures/ldiff/output.diff-e

-3
This file was deleted.

spec/fixtures/ldiff/output.diff-f

-3
This file was deleted.

spec/fixtures/ldiff/output.diff.chef-e

-3
This file was deleted.

spec/fixtures/ldiff/output.diff.chef-f

-3
This file was deleted.

spec/fixtures/ldiff/output.diff.chef2-e

-7
This file was deleted.

spec/fixtures/ldiff/output.diff.chef2-f

-7
This file was deleted.

spec/hunk_spec.rb

-11
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@
5656
expect(hunk.diff(:old)).to eq(expected)
5757
end
5858

59-
it "produces a reverse ed diff from the two pieces" do
60-
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
61-
c1
62-
Tu a un carte avec {count} items
63-
.
64-
65-
EXPECTED
66-
67-
expect(hunk.diff(:reverse_ed)).to eq(expected)
68-
end
69-
7059
context "with empty first data set" do
7160
let(:old_data) { [] }
7261

spec/ldiff_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{:name => "output.diff", :left => "aX", :right => "bXaX"},
1111
{:name => "output.diff.chef", :left => "old-chef", :right => "new-chef"},
1212
{:name => "output.diff.chef2", :left => "old-chef2", :right => "new-chef2"}
13-
].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)|
13+
].product([nil, "-c", "-u"]).map { |(fixture, flag)|
1414
fixture = fixture.dup
1515
fixture[:flag] = flag
1616
fixture

0 commit comments

Comments
 (0)