Created
August 21, 2012 09:37
-
-
Save Orangenhain/3413952 to your computer and use it in GitHub Desktop.
Revisions
-
OrangeRaven created this gist
Aug 21, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ #!/usr/bin/env ruby require 'uri' def params_valid? lengthOkay = [2,3].include? ARGV.length revOkay = ARGV[0].to_i.to_s == ARGV[0] lengthOkay && revOkay end def date_for_svn_revision(url, revision) output = `svn log --limit 1 -r #{revision} '#{url}' --xml | grep '<date>.*</date>'` date = output.strip[/^<date>(.*)<\/date>$/, 1].strip rescue nil end def parse_externals(line) # http://svnbook.red-bean.com/en/1.7/svn.advanced.externals.html # good enough(tm) for my purposes name, url = line.split("\s") end def get_svn(url, path, date) output = `svn checkout --ignore-externals --revision '{#{date}}' "#{url}" "#{path}"` puts " -- START --" puts "URL: #{url}", "path: #{path}", "date: #{date}" puts output puts " -- END --" Dir.chdir(path) do output = `svn propget 'svn:externals'`.strip return if output.length == 0 externals = output.lines.collect { |line| parse_externals(line) }.compact externals.each do |name, url| get_svn(url, name, date) end end end unless params_valid? puts "Usage: #{File.basename __FILE__} #revision URL [path]" exit 1 end revision = ARGV[0].to_i url = URI.parse(ARGV[1]) path = ARGV[2] || File.basename(url.path) || "checkout_#{url.host}_#{revision}" date = date_for_svn_revision(url, revision) if date.nil? or date.length == 0 puts "ERROR: could not find date for r#{revision} @ #{url}" puts "\tmost likely the corresponding commit did not touch the provided path" exit 2 end get_svn url, path, date