background-color: #fef;
}
-.Line.add {
+.Line.add, .FileDiff .add {
background-color: #dfd;
}
text-decoration: none;
}
-.Line.remove {
+.Line.remove, .FileDiff .remove {
background-color: #fdd;
}
@sections = DiffSection.parse(lines_with_contents) unless @binary
if @image
@image_url = "data:image/png;base64," + lines_with_contents.join
+ @image_checksum = FileDiff.read_checksum_from_png(lines_with_contents.join.unpack("m").join)
elsif @git_image
begin
raise "index line is missing" unless @git_indexes
raise "no binary chunks" unless chunks
- @image_urls = chunks.zip(@git_indexes).collect do |chunk, git_index|
+ binary_contents = chunks.zip(@git_indexes).collect do |chunk, git_index|
FileDiff.extract_contents_from_git_binary_chunk(chunk, git_index)
end
+
+ @image_urls = binary_contents.collect { |content| "data:image/png;base64," + [content].pack("m") }
+ @image_checksums = binary_contents.collect { |content| FileDiff.read_checksum_from_png(content) }
rescue
@image_error = "Exception raised during decoding git binary patch:<pre>#{CGI.escapeHTML($!.to_s + "\n" + $!.backtrace.join("\n"))}</pre>"
end
str = "<div class='FileDiff'>\n"
str += "<h1>#{PrettyPatch.linkifyFilename(@filename)}</h1>\n"
if @image then
+ if @image_checksum then
+ str += "<p>" + @image_checksum + "</p>"
+ end
str += "<img class='image' src='" + @image_url + "' />"
elsif @git_image then
if @image_error
else
for i in (0...2)
image_url = @image_urls[i]
+ image_checksum = @image_checksums[i]
+
style = ["remove", "add"][i]
str += "<p class=\"#{style}\">"
+
+ if image_checksum
+ str += image_checksum + "<br>"
+ end
if image_url
str += "<img class='image' src='" + image_url + "' />"
else
linesForDiffs.collect { |lines| FileDiff.new(lines) }
end
+ def self.read_checksum_from_png(png_bytes)
+ match = png_bytes.match(/tEXtchecksum\0([a-fA-F0-9]{32})/)
+ match ? match[1] : nil
+ end
+
def self.git_new_file_binary_patch(filename, encoded_chunk, git_index)
return <<END
diff --git a/#{filename} b/#{filename}
end
return nil if contents.empty?
- return "data:image/png;base64," + [contents].pack("m")
+ return contents
end
end