2011-04-12 Tony Chang <tony@chromium.org>
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 18:04:30 +0000 (18:04 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 18:04:30 +0000 (18:04 +0000)
        Reviewed by Adam Roben.

        make PrettyPatch.rb aware of checksums in png files
        https://bugs.webkit.org/show_bug.cgi?id=58387

        * PrettyPatch/PrettyPatch.rb:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83750 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/bugs.webkit.org/ChangeLog
Websites/bugs.webkit.org/PrettyPatch/PrettyPatch.rb

index f6492c4..c88567c 100644 (file)
@@ -1,3 +1,12 @@
+2011-04-12  Tony Chang  <tony@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        make PrettyPatch.rb aware of checksums in png files
+        https://bugs.webkit.org/show_bug.cgi?id=58387
+
+        * PrettyPatch/PrettyPatch.rb:
+
 2011-04-12  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Eric Seidel.
index 8f960a9..d8d9361 100644 (file)
@@ -228,7 +228,7 @@ h1 :hover {
     background-color: #fef;
 }
 
-.Line.add {
+.Line.add, .FileDiff .add {
     background-color: #dfd;
 }
 
@@ -237,7 +237,7 @@ h1 :hover {
     text-decoration: none;
 }
 
-.Line.remove {
+.Line.remove, .FileDiff .remove {
     background-color: #fdd;
 }
 
@@ -516,6 +516,7 @@ EOF
             @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
@@ -530,9 +531,12 @@ EOF
 
                     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
@@ -544,6 +548,9 @@ EOF
             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
@@ -551,8 +558,14 @@ EOF
                 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
@@ -590,6 +603,11 @@ EOF
             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}
@@ -632,7 +650,7 @@ END
             end
 
             return nil if contents.empty?
-            return "data:image/png;base64," + [contents].pack("m")
+            return contents
         end
     end