rosa-build/bin/remove_archives.rb

61 lines
2.3 KiB
Ruby
Raw Normal View History

#!/usr/bin/env ruby
2012-11-12 09:17:25 +00:00
# git_dir_projects[0] dest_git_path[1] clone_path[2] owner[3] project_name[4]
require 'fileutils'
require 'digest'
token = '[CENSORED]'
2012-11-12 09:17:25 +00:00
owners = ARGF.argv[3] || '[a-z0-9_]*'
project_names = ARGF.argv[4] || '[a-zA-Z0-9_\-\+\.]*'
begin_time = Time.now
pr_count = total_count = 0
Dir.chdir ARGF.argv[0]
Dir.glob(owners).each do |owner|
Dir.chdir "#{ARGF.argv[0]}/#{owner}"
Dir.glob(project_names).each do |project|
name_with_owner = "#{owner}/#{project.chomp('.git')}"
project_path = "#{ARGF.argv[0]}/#{name_with_owner}.git"
2012-11-12 09:17:25 +00:00
dest_project_path = "#{ARGF.argv[1]}/#{name_with_owner}.git"
time, total_count = Time.now, total_count + 1
Dir.chdir project_path
project_stats = "#{name_with_owner}: #{total_count}"
if system('git log -n 1 --oneline > /dev/null 2>&1') == false
p "Skipping empty project #{project_stats}"
else
p "Start working with #{project_stats}"
2012-11-12 09:17:25 +00:00
path = "#{ARGF.argv[2].chomp('/')}/repos/#{name_with_owner}"
FileUtils.rm_rf path
#-- hack for refs/heads (else git branch return only master)
system "git clone --mirror #{project_path} #{path}/.git"
system "cd #{path} && git config --bool core.bare false && git checkout -f HEAD"
#--
Dir.chdir(path)
archives_exists = false
2012-11-12 09:17:25 +00:00
%w(tar.bz2 tar.gz bz2 rar gz tar tbz2 tgz zip Z 7z tar.xz).each do |ext|
archives_exists=true and break unless `git log --all --format='%H' -- *.#{ext}`.empty?
end
if archives_exists
system "git filter-branch -d /dev/shm/git_task --tree-filter \"/home/rosa/git_task/file-store.rb #{token} #{path}\" --prune-empty --tag-name-filter cat -- --all"
#####
# This is dangerous !!!
2012-11-12 09:17:25 +00:00
system "rm -rf #{dest_project_path} && git clone --bare #{path} #{dest_project_path}"
#####
p "Worked with #{name_with_owner}: #{(Time.now - time).truncate} sec."
pr_count +=1
else
p "Skipping project with no archives #{project_stats}"
end
2012-11-12 09:17:25 +00:00
`rm -rf #{path} && cd #{dest_project_path} && git gc --prune=now`
end
p '-------------'
end
end
p '======================='
p "Total count of projects are #{total_count}"
p "Finished work with #{pr_count} project(s) in #{Time.at((Time.now - begin_time).truncate).gmtime.strftime('%R:%S')}"