module FileHelper
Public Instance Methods
compare(commit, file_name, lines, context=nil, diff=nil)
click to toggle source
# File lib/file_helper.rb, line 23 def compare(commit, file_name, lines, context=nil, diff=nil) if diff.nil? Loggr.instance.info("COMPARE COMMIT: #{commit.id}") else Loggr.instance.info("COMPARE fdiff: #{fdiff_stat(diff)}") end real_file = `git show #{commit.id}:#{file_name}` .encode("UTF-8", invalid: :replace) .lines .map(&:chomp) return if real_file.length == 0 if real_file.length != lines.length && diff.nil? puts "FILE SIZE MISMATCH:" puts "REAL: #{real_file.length}" puts "RECONSTRUCT: #{lines.length}" byebug 1 end lines .each_with_index .map do |line, line_number| if real_file[line_number] != line.gsub(/\r$/, "") puts "MISMATCH: #{commit.id}:#{file_name}" puts "REAL:" print_context(real_file, line_number) puts "RECONSTRUCT" print_context(lines, line_number) byebug 1 end end end
fdiff_stat(diff)
click to toggle source
# File lib/file_helper.rb, line 6 def fdiff_stat(diff) "@@ -#{diff.delete_start},#{diff.delete_count} +#{diff.insert_start},#{diff.insert_count} @@" end
print_context(lines, from, to=nil)
click to toggle source
# File lib/file_helper.rb, line 10 def print_context(lines, from, to=nil) if to.nil? to = from + 3 from -= 4 end (from...to).each do |i| line = lines[i] line = "nil" if line.nil? puts "#{i + 1}: #{line}" end nil end