60 lines
2.1 KiB
Ruby
60 lines
2.1 KiB
Ruby
|
#!/usr/bin/env ruby
|
||
|
# git_dir_projects[0] clone_path[1] owner[2] project_name[3]
|
||
|
|
||
|
require 'fileutils'
|
||
|
require 'digest'
|
||
|
|
||
|
token = '[CENSORED]'
|
||
|
|
||
|
owners = ARGF.argv[2] || '[a-z0-9_]*'
|
||
|
project_names = ARGF.argv[3] || '[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"
|
||
|
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}"
|
||
|
path = "#{ARGF.argv[1].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
|
||
|
%w(tar.bz2 tar.gz bz2 rar gz tar tbz2 tgz zip Z 7z).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 !!!
|
||
|
system "rm -rf #{project_path} && git clone --bare #{path} #{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
|
||
|
`rm -rf #{path}`
|
||
|
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')}"
|