comparison extra/soundsoftware/create-repo-authormaps.rb @ 1538:87bea4981d6d live

Script to create authormaps for all repos
author Chris Cannam
date Thu, 21 May 2015 16:59:41 +0100
parents
children 22d57b0e0a77
comparison
equal deleted inserted replaced
1537:e55cbb9ba8bf 1538:87bea4981d6d
1 #!/usr/bin/env ruby
2
3 # Create authormap files for hg repos based on the changeset & project
4 # member info available to Redmine.
5 #
6 # We have a set of hg repos in a given directory:
7 #
8 # /var/hg/repo_1
9 # /var/hg/repo_2
10 # /var/hg/repo_3
11 #
12 # and we want to produce authormap files in another directory:
13 #
14 # /var/repo-export/authormap/authormap_repo_1
15 # /var/repo-export/authormap/authormap_repo_2
16 # /var/repo-export/authormap/authormap_repo_3
17 #
18 # This script does that, if given the two directory names as arguments
19 # to the -s and -o options. In the above example:
20 #
21 # create-repo-authormaps.rb -s /var/hg -o /var/repo-export/authormap
22 #
23 # Note that this script will overwrite any existing authormap
24 # files. (That's why the output files are given an authormap_ prefix,
25 # so we're less likely to clobber something else if the user gets the
26 # arguments wrong.)
27
28 require 'getoptlong'
29
30 opts = GetoptLong.new(
31 ['--scm-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
32 ['--out-dir', '-o', GetoptLong::REQUIRED_ARGUMENT]
33 )
34
35 $repos_base = ''
36 $out_base = ''
37
38 def usage
39 puts "See source code for supported options"
40 exit
41 end
42
43 begin
44 opts.each do |opt, arg|
45 case opt
46 when '--scm-dir'; $repos_base = arg.dup
47 when '--out-dir'; $out_base = arg.dup
48 end
49 end
50 rescue
51 exit 1
52 end
53
54 if ($repos_base.empty? or $out_base.empty?)
55 usage
56 end
57
58 unless File.directory?($repos_base)
59 log("input directory '#{$repos_base}' doesn't exist", :exit => true)
60 end
61
62 unless File.directory?($out_base)
63 log("output directory '#{$out_base}' doesn't exist", :exit => true)
64 end
65
66 projects = Project.find(:all)
67
68 if projects.nil?
69 log('No projects found', :exit => true)
70 end
71
72 projects.each do |proj|
73 next unless proj.respond_to?(:repository)
74
75 repo = proj.repository
76
77 repo_url = repo.url
78 repo_url = repo_url.gsub(/^file:\/*/, "/");
79 if repo_url != File.join($repos_base, proj.identifier)
80 log('Project #{proj.identifier} has repo in unsupported location #{repo_url}, skipping')
81 next
82 end
83
84 csets = repo.changesets
85 committers = csets.map do |c| c.committer end.sort.uniq
86
87 authormap = ""
88 committers.each do |c|
89 if not c =~ /[^<]+<.*@.*>/ then
90 user = repo.find_committer_user c
91 authormap << "#{c}=#{u.name} <#{u.mail}>\n" unless u.nil?
92 end
93 end
94
95 File.open (File.join($out_base, "authormap_#{proj.identifier}"), "w") do |f|
96 f.puts(authormap)
97 end
98
99 end
100