Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- # Fetches every revision of a file from subversion.
- # Usage: svn_explode [file...]
- require 'yaml'
- require 'open3'
- def capture_output(*args)
- output = ""
- Open3.popen3(*args) do |stdin, stdout, stderr|
- output = stdout.read
- $stderr.print stderr.read
- end
- return output
- end
- def get_url(file)
- url = ""
- capture_output("svn", "info", file).each_line do |line|
- next unless line =~ /^URL: (.*)/
- return $1
- end
- raise "Couldn't get the URL for #{file}"
- end
- def get_version_history(file)
- versions = []
- capture_output("svn", "log", "-q", file).each_line do |line|
- next unless line =~ /r(\d+)/
- versions.push $1.to_i
- end
- return versions
- end
- def checkout_file(file, revision)
- url = get_url file
- puts "Getting r#{revision}"
- contents = capture_output "svn", "cat", "-r", revision.to_s, url
- open("#{file}.r#{revision}", "w+") {|f| f.write contents}
- end
- ARGV.each do |file|
- puts "Examining #{file}"
- versions = get_version_history(file)
- versions.each do |version|
- checkout_file file, version
- end
- end
Add Comment
Please, Sign In to add comment