2011-04-14 Tony Chang <tony@chromium.org>
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Apr 2011 17:47:48 +0000 (17:47 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Apr 2011 17:47:48 +0000 (17:47 +0000)
        Reviewed by Adam Roben.

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

        Patch v2 with nil checks in the case of file adds and deletes.

        * PrettyPatch/PrettyPatch.rb:

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

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

index ed8a492..1ee7ff2 100644 (file)
@@ -1,3 +1,14 @@
+2011-04-14  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
+
+        Patch v2 with nil checks in the case of file adds and deletes.
+
+        * PrettyPatch/PrettyPatch.rb:
+
 2011-04-13  Simon Fraser  <simon.fraser@apple.com>
 
         Revert http://trac.webkit.org/changeset/83750 because it broke PrettyPatch.
 2011-04-13  Simon Fraser  <simon.fraser@apple.com>
 
         Revert http://trac.webkit.org/changeset/83750 because it broke PrettyPatch.
index 8f960a9..a4e3893 100644 (file)
@@ -228,7 +228,7 @@ h1 :hover {
     background-color: #fef;
 }
 
     background-color: #fef;
 }
 
-.Line.add {
+.Line.add, .FileDiff .add {
     background-color: #dfd;
 }
 
     background-color: #dfd;
 }
 
@@ -237,7 +237,7 @@ h1 :hover {
     text-decoration: none;
 }
 
     text-decoration: none;
 }
 
-.Line.remove {
+.Line.remove, .FileDiff .remove {
     background-color: #fdd;
 }
 
     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
             @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
             elsif @git_image
                 begin
                     raise "index line is missing" unless @git_indexes
@@ -530,9 +531,12 @@ EOF
 
                     raise "no binary chunks" unless chunks
 
 
                     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
                         FileDiff.extract_contents_from_git_binary_chunk(chunk, git_index)
                     end
+
+                    @image_urls = binary_contents.collect { |content| content ? "data:image/png;base64," + [content].pack("m") : nil }
+                    @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
                 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
             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
                 str += "<img class='image' src='" + @image_url + "' />"
             elsif @git_image then
                 if @image_error
@@ -551,12 +558,18 @@ EOF
                 else
                     for i in (0...2)
                         image_url = @image_urls[i]
                 else
                     for i in (0...2)
                         image_url = @image_urls[i]
+                        image_checksum = @image_checksums[i]
+
                         style = ["remove", "add"][i]
                         str += "<p class=\"#{style}\">"
                         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
                         if image_url
                             str += "<img class='image' src='" + image_url + "' />"
                         else
-                            str += ["Added", "Removed"][i]
+                            str += ["</p>Added", "</p>Removed"][i]
                         end
                     end
                 end
                         end
                     end
                 end
@@ -590,6 +603,11 @@ EOF
             linesForDiffs.collect { |lines| FileDiff.new(lines) }
         end
 
             linesForDiffs.collect { |lines| FileDiff.new(lines) }
         end
 
+        def self.read_checksum_from_png(png_bytes)
+            match = png_bytes && 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}
         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?
             end
 
             return nil if contents.empty?
-            return "data:image/png;base64," + [contents].pack("m")
+            return contents
         end
     end
 
         end
     end