Rakefile in tzinfo-0.3.37 vs Rakefile in tzinfo-0.3.38

- old
+ new

@@ -38,16 +38,17 @@ orig_sh(*cmd, &block) end -PKG_VERSION = "0.3.37" +PKG_VERSION = "0.3.38" PKG_FILES = FileList[ 'CHANGES', 'LICENSE', 'Rakefile', 'README', + '.yardopts', 'lib', 'lib/**/*' ].delete_if {|f| f.include?('.svn')} PKG_TEST_FILES = FileList['test', 'test/**/*'].delete_if {|f| f.include?('.svn')} @@ -59,11 +60,11 @@ SPEC = Gem::Specification.new do |s| s.name = "tzinfo" s.version = PKG_VERSION s.author = "Philip Ross" s.email = "phil.ross@gmail.com" - s.homepage = "http://tzinfo.rubyforge.org/" + s.homepage = "http://tzinfo.github.io" s.platform = Gem::Platform::RUBY s.summary = "Daylight-savings aware timezone library" s.description = "TZInfo is a Ruby library that uses the standard tz (Olson) database to provide daylight savings aware transformations between times in different time zones." s.files = PKG_FILES s.test_files = PKG_TEST_FILES @@ -146,84 +147,155 @@ FileUtils.mkdir_p(BUILD_TZ_CLASSES_DIR) begin p = TZInfo::TZDataParser.new('../data', BUILD_TZ_CLASSES_DIR) p.execute - ['indexes', 'definitions'].each {|dir| - sync_svn("#{BUILD_TZ_CLASSES_DIR}/#{dir}", "lib/tzinfo/#{dir}") - } + scm = Scm.create(File.join(File.dirname(__FILE__), '..')) + + ['indexes', 'definitions'].each do |dir| + scm.sync("#{BUILD_TZ_CLASSES_DIR}/#{dir}", "lib/tzinfo/#{dir}") + end ensure FileUtils.rm_rf(BUILD_TZ_CLASSES_DIR) end end -def sync_svn(source_dir, target_dir) - puts "SVN Sync from #{source_dir} to #{target_dir}" +class Scm + def self.create(dir) + if File.directory?(File.join(dir, '.git')) + GitScm.new(dir) + elsif File.directory?(File.join(dir, '.svn')) + SvnScm.new(dir) + else + NullScm.new(dir) + end + end - # Assumes a directory will never turn into a file and vice-versa - # (files will all end in .rb, directories won't). - # SVN wouldn't allow the change in a single commit anyway. + def initialize(dir) + end - source_entries, target_entries = [source_dir, target_dir].collect {|dir| - Dir.entries(dir).delete_if {|entry| entry =~ /^\.(\.?|svn)$/}.sort - } + def sync(source_dir, target_dir) + puts "Sync from #{source_dir} to #{target_dir}#{command ? " using #{command}" : ''}" + sync_dirs(source_dir, target_dir) + end + + protected + + def exec_scm(params) + puts "#{command} #{params}" + `#{command} #{params}` + raise "#{command} exited with status #$?" if $? != 0 + end + + private - until source_entries.empty? || target_entries.empty? - if source_entries.last == target_entries.last - source_file = "#{source_dir}/#{source_entries.last}" - target_file = "#{target_dir}/#{target_entries.last}" + def sync_dirs(source_dir, target_dir) + # Assumes a directory will never turn into a file and vice-versa + # (files will all end in .rb, directories won't). + + source_entries, target_entries = [source_dir, target_dir].collect do |dir| + Dir.entries(dir).delete_if {|entry| entry =~ /\A\./}.sort + end - if File.directory?(source_file) - sync_svn(source_file, target_file) - else - FileUtils.cp(source_file, target_file) - end + until source_entries.empty? || target_entries.empty? + last_source = source_entries.last + last_target = target_entries.last - source_entries.pop - target_entries.pop - elsif source_entries.last < target_entries.last - sync_svn_only_in_target(target_dir, target_entries) - else - sync_svn_only_in_source(source_dir, target_dir, source_entries) - end + if last_source == last_target + source_file = File.join(source_dir, last_source) + target_file = File.join(target_dir, last_target) + + if File.directory?(source_file) + sync_dirs(source_file, target_file) + else + FileUtils.cp(source_file, target_file) + end + + source_entries.pop + target_entries.pop + elsif source_entries.last < target_entries.last + sync_only_in_target(target_dir, target_entries) + else + sync_only_in_source(source_dir, target_dir, source_entries) + end + end + + until target_entries.empty? + sync_only_in_target(target_dir, target_entries) + end + + until source_entries.empty? + sync_only_in_source(source_dir, target_dir, source_entries) + end end + + def sync_only_in_target(target_dir, target_entries) + target_file = File.join(target_dir, target_entries.last) + delete(target_file) + target_entries.pop + end + + def sync_only_in_source(source_dir, target_dir, source_entries) + source_file = File.join(source_dir, source_entries.last) + target_file = File.join(target_dir, source_entries.last) + + if File.directory?(source_file) + Dir.mkdir(target_file) + add(target_file) + sync_dirs(source_file, target_file) + else + FileUtils.cp(source_file, target_file) + add(target_file) + end + + source_entries.pop + end +end + +class NullScm < Scm + def command + nil + end - until target_entries.empty? - sync_svn_only_in_target(target_dir, target_entries) + def add(file) end - until source_entries.empty? - sync_svn_only_in_source(source_dir, target_dir, source_entries) + def delete(file) + puts "rm -rf \"#{file}\"" + FileUtils.rm_rf(file) end end -def sync_svn_only_in_target(target_dir, target_entries) - target_file = "#{target_dir}/#{target_entries.last}" - exec_svn "delete \"#{target_file}\"" - target_entries.pop +class GitScm < Scm + def command + 'git' + end + + def add(file) + unless File.directory?(file) + exec_scm "add \"#{file}\"" + end + end + + def delete(file) + exec_scm "rm -rf \"#{file}\"" + end end -def sync_svn_only_in_source(source_dir, target_dir, source_entries) - source_file = "#{source_dir}/#{source_entries.last}" - target_file = "#{target_dir}/#{source_entries.last}" - - if File.directory?(source_file) - Dir.mkdir(target_file) - exec_svn "add \"#{target_file}\"" - sync_svn(source_file, target_file) - else - FileUtils.cp(source_file, target_file) - exec_svn "add \"#{target_file}\"" +class SvnScm < Scm + def command + 'svn' end - source_entries.pop + def add(file) + exec_scm "add \"#{file}\"" + end + + def delete(file) + exec_scm "delete --force \"#{file}\"" + end end -def exec_svn(params) - puts "svn #{params}" - `svn #{params}` - raise "SVN exited with status #$?" if $? != 0 -end task :build_tz_module do require 'lib/tzinfo/tzdataparser' p = TZInfo::TZDataParser.new('../data', 'lib/tzinfo') p.generate_countries = false