Guest User

Untitled

a guest
May 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #! /usr/bin/env ruby
  2.  
  3. # Fetches every revision of a file from subversion.
  4. # Usage: svn_explode [file...]
  5.  
  6. require 'yaml'
  7. require 'open3'
  8.  
  9. def capture_output(*args)
  10. output = ""
  11. Open3.popen3(*args) do |stdin, stdout, stderr|
  12. output = stdout.read
  13. $stderr.print stderr.read
  14. end
  15. return output
  16. end
  17.  
  18. def get_url(file)
  19. url = ""
  20. capture_output("svn", "info", file).each_line do |line|
  21. next unless line =~ /^URL: (.*)/
  22. return $1
  23. end
  24. raise "Couldn't get the URL for #{file}"
  25. end
  26.  
  27. def get_version_history(file)
  28. versions = []
  29. capture_output("svn", "log", "-q", file).each_line do |line|
  30. next unless line =~ /r(\d+)/
  31. versions.push $1.to_i
  32. end
  33. return versions
  34. end
  35.  
  36. def checkout_file(file, revision)
  37. url = get_url file
  38. puts "Getting r#{revision}"
  39. contents = capture_output "svn", "cat", "-r", revision.to_s, url
  40. open("#{file}.r#{revision}", "w+") {|f| f.write contents}
  41. end
  42.  
  43. ARGV.each do |file|
  44. puts "Examining #{file}"
  45. versions = get_version_history(file)
  46. versions.each do |version|
  47. checkout_file file, version
  48. end
  49. end
Add Comment
Please, Sign In to add comment