blob: fcb17afbcad6624cd29d95712867a5da22b24bf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/usr/bin/env ruby
def eqon(a,b)
(yield a) == (yield b)
end
s = ARGF.read
def section start; /#{start}.+?(?=(?:#{start}|\z))/m; end
def line start; /^#{start}.+/; end
def lines start; /(?:#{line start}\n)+/m; end
hunks = section /^diff/
hunk = section /^@@[^\n]*@@/
minus = lines /-/
plus = lines /\+/
minusplus = /(?:#{minus }|#{plus})+/m
s.gsub!(hunks) { |hs|
r = hs.gsub(hunk) { |h|
h.scan(minusplus).reject { |c|
eqon(minus, plus) { |r|
c.scan(r).map{ |l|
l.gsub(/^./,"").gsub(/\s+/m,"")
}
}
}.empty? ? "" : h
# }.empty? ? h : "" # uncomment this to see what nitpicking would get removed
}
r.scan(hunk).empty? ? "" : r
}
puts s
|