Created
July 17, 2010 22:51
-
-
Save jamesu/479916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract_patches - Extracts patches from an .mbox | |
# USAGE: | |
# extract_patches [file] | |
# | |
# Will create "<revision>.log" containing the commit log, and "<revision>.patch" containing the actual diff. | |
# Assumes SVN-style commit log. | |
# | |
require 'rubygems' | |
require 'tmail' | |
mailbox = TMail::UNIXMbox.new(ARGV[0], nil, true) | |
@emails = [] | |
mailbox.each_port { |m| @emails << TMail::Mail.new(m) } | |
@emails.each do |email| | |
io = StringIO.new(email.body, 'r') | |
current_parse = nil | |
revision = email.subject.match(/r[0-9]+/)[0] | |
out_log = File.open("#{revision}.log", "w") | |
out_diff = File.open("#{revision}.patch", "w") | |
puts "#{revision}..." | |
begin | |
parse_mode = :header | |
wait_for_change = false | |
while line = io.readline | |
case parse_mode | |
when :header | |
words = line.split(' ') | |
if wait_for_change | |
if words.length > 0 and words[0].match(/[A-Za-z]+:/) | |
parse_mode = :changes | |
wait_for_change = false | |
out_diff.write line | |
else | |
out_log.write line | |
end | |
elsif words[0] == 'Log:' | |
wait_for_change = true | |
out_log.write line | |
else | |
out_log.write line | |
end | |
when :changes | |
out_diff.write line | |
end | |
end | |
rescue Exception => o | |
puts o.to_s | |
end | |
out_log.close | |
out_diff.close | |
io.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment