Changeset 51826 in webkit
- Timestamp:
- Dec 7, 2009 6:50:35 PM (14 years ago)
- Location:
- trunk/BugsSite
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BugsSite/ChangeLog
r51751 r51826 1 2009-12-07 Shinichiro Hamaji <hamaji@chromium.org> 2 3 Reviewed by David Kilzer. 4 5 Bugzilla should show images in git patches 6 https://bugs.webkit.org/show_bug.cgi?id=31395 7 8 Attempt to go r51748 again using --directory option of git-apply. 9 10 * PrettyPatch/PrettyPatch.rb: 11 1 12 2009-12-06 Shinichiro Hamaji <hamaji@chromium.org> 2 13 -
trunk/BugsSite/PrettyPatch/PrettyPatch.rb
r51751 r51826 1 1 require 'cgi' 2 2 require 'diff' 3 require 'open3' 3 4 require 'pp' 4 5 require 'set' 6 require 'tempfile' 5 7 6 8 module PrettyPatch 7 9 8 10 public 11 12 GIT_PATH = "/opt/local/bin/git" 9 13 10 14 def self.prettify(string) … … 39 43 ] 40 44 41 BINARY_FILE_MARKER_FORMAT = /^ (?:Cannot display: file marked as a binary type.)|(?:GIT binary patch)$/45 BINARY_FILE_MARKER_FORMAT = /^Cannot display: file marked as a binary type.$/ 42 46 43 47 IMAGE_FILE_MARKER_FORMAT = /^svn:mime-type = image\/png$/ 48 49 GIT_INDEX_MARKER_FORMAT = /^index ([0-9a-f]{40})\.\.([0-9a-f]{40})/ 50 51 GIT_BINARY_FILE_MARKER_FORMAT = /^GIT binary patch$/ 52 53 GIT_LITERAL_FORMAT = /^literal \d+$/ 44 54 45 55 START_OF_BINARY_DATA_FORMAT = /^[0-9a-zA-Z\+\/=]{20,}/ # Assume 20 chars without a space is base64 binary data. … … 216 226 end 217 227 break 228 when GIT_INDEX_MARKER_FORMAT 229 @git_indexes = [$1, $2] 230 when GIT_BINARY_FILE_MARKER_FORMAT 231 @binary = true 232 if (GIT_LITERAL_FORMAT.match(lines[i + 1]) and PrettyPatch.has_image_suffix(@filename)) then 233 @git_image = true 234 startOfSections = i + 1 235 end 236 break 218 237 end 219 238 end 220 239 lines_with_contents = lines[startOfSections...lines.length] 221 240 @sections = DiffSection.parse(lines_with_contents) unless @binary 222 @image_url = "data:image/png;base64," + lines_with_contents.join if @image 241 if @image 242 @image_url = "data:image/png;base64," + lines_with_contents.join 243 elsif @git_image 244 begin 245 raise "index line is missing" unless @git_indexes 246 247 chunks = nil 248 for i in 0...lines_with_contents.length 249 if lines_with_contents[i] =~ /^$/ 250 chunks = [lines_with_contents[i + 1 .. -1], lines_with_contents[0 .. i]] 251 break 252 end 253 end 254 255 raise "no binary chunks" unless chunks 256 257 @image_urls = chunks.zip(@git_indexes).collect do |chunk, git_index| 258 FileDiff.extract_contents_from_git_binary_chunk(chunk, git_index) 259 end 260 rescue 261 @image_error = "Exception raised during decoding git binary patch:<pre>#{CGI.escapeHTML($!.to_s + "\n" + $!.backtrace.join("\n"))}</pre>" 262 end 263 end 223 264 nil 224 265 end … … 229 270 if @image then 230 271 str += "<img class='image' src='" + @image_url + "' />" 272 elsif @git_image then 273 if @image_error 274 str += @image_error 275 else 276 for i in (0...2) 277 image_url = @image_urls[i] 278 style = ["remove", "add"][i] 279 str += "<p class=\"#{style}\">" 280 if image_url 281 str += "<img class='image' src='" + image_url + "' />" 282 else 283 str += ["Added", "Removed"][i] 284 end 285 end 286 end 231 287 elsif @binary then 232 288 str += "<span class='text'>Binary file, nothing to see here</span>" … … 252 308 253 309 linesForDiffs.collect { |lines| FileDiff.new(lines) } 310 end 311 312 def self.git_new_file_binary_patch(filename, encoded_chunk, git_index) 313 return <<END 314 diff --git a/#{filename} b/#{filename} 315 new file mode 100644 316 index 0000000000000000000000000000000000000000..#{git_index} 317 GIT binary patch 318 #{encoded_chunk.join("")}literal 0 319 HcmV?d00001 320 321 END 322 end 323 324 def self.extract_contents_from_git_binary_chunk(encoded_chunk, git_index) 325 # We use Tempfile we need a unique file among processes. 326 tempfile = Tempfile.new("PrettyPatch") 327 # We need a filename which doesn't exist to apply a patch 328 # which creates a new file. Append a suffix so filename 329 # doesn't exist. 330 filepath = tempfile.path + '.bin' 331 filename = File.basename(filepath) 332 333 patch = FileDiff.git_new_file_binary_patch(filename, encoded_chunk, git_index) 334 335 # Apply the git binary patch using git-apply. 336 cmd = GIT_PATH + " apply --directory=" + File.dirname(filepath) 337 stdin, stdout, stderr = *Open3.popen3(cmd) 338 begin 339 stdin.puts(patch) 340 stdin.close 341 342 error = stderr.read 343 raise error if error != "" 344 345 contents = File.read(filepath) 346 ensure 347 stdin.close unless stdin.closed? 348 stdout.close 349 stderr.close 350 File.unlink(filename) if File.exists?(filename) 351 end 352 353 return nil if contents.empty? 354 return "data:image/png;base64," + [contents].pack("m") 254 355 end 255 356 end
Note: See TracChangeset
for help on using the changeset viewer.