Skip to content
This repository
Newer
Older
100755 138 lines (117 sloc) 3.758 kb
7743f0d6 »
2008-08-23 so close to fully working
1 #! /usr/bin/env ruby
2
3 require 'fileutils'
4 require 'tempfile'
5 require 'pp'
6
7 class SubSucka
8
9 attr_accessor :repo, :svn_url
10
11 def initialize(repo, svn_url)
12 @repo = repo
13 @svn_url = svn_url
14 end
15
16 def build
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
17 build_repo_log
18 build_tree_rev_shas
19 write_commits
7743f0d6 »
2008-08-23 so close to fully working
20 finish_repo
c33099cd »
2008-08-25 lame exit for now, but its a start
21 register_finish
7743f0d6 »
2008-08-23 so close to fully working
22 end
23
c33099cd »
2008-08-25 lame exit for now, but its a start
24 def register_finish
25 File.open("/tmp/projects", 'a') do |f|
26 f.write([@repo, @svn_url].join(',') + "\n")
27 end
28 end
29
7743f0d6 »
2008-08-23 so close to fully working
30 def get_branch_list(br)
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
31 branches = `svn list #{@svn_url}/#{br}`.split("\n").map { |b| b.gsub('/', '') }
7743f0d6 »
2008-08-23 so close to fully working
32 end
33
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
34 def write_commits
35 last_commits = {}
7743f0d6 »
2008-08-23 so close to fully working
36 Dir.chdir(@repo) do
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
37 @repo_log.reverse.each do |commit|
38 next if !(commit_sha = @tree_rev_shas[commit[0]])
7743f0d6 »
2008-08-23 so close to fully working
39 ENV['GIT_AUTHOR_NAME'] = ENV['GIT_COMMITTER_NAME'] = commit[1]
40 ENV['GIT_AUTHOR_EMAIL'] = ENV['GIT_COMMITTER_EMAIL'] = commit[1] + '@email.com'
41 ENV['GIT_AUTHOR_DATE'] = ENV['GIT_COMMITTER_DATE'] = commit[2]
42 comment = Tempfile.new('comment') # |
43 comment.write(commit[4]) # |
44 comment.close # `-- prepare commit meta-data
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
45
46 ref = commit[5]
47 name = commit[6]
0653bae0 »
2008-08-25 really actually working now - just need to figure out how to get that…
48 next if !(ref == 'trunk' || ref == 'tags' || ref == 'branches')
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
49 ref = File.join(ref, name) if ref != 'trunk'
50
7743f0d6 »
2008-08-23 so close to fully working
51 parent = ''
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
52 last_commit = last_commits[ref] || last_commits['trunk']
7743f0d6 »
2008-08-23 so close to fully working
53 parent = "-p #{last_commit}" if last_commit
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
54
55 tree_sha = `git rev-parse #{commit_sha}:#{ref}`.strip
56
0653bae0 »
2008-08-25 really actually working now - just need to figure out how to get that…
57 tc = `git commit-tree #{tree_sha} #{parent} < #{comment.path}`.strip
58 last_commits[ref] = tc if tc != ''
7743f0d6 »
2008-08-23 so close to fully working
59 end
0653bae0 »
2008-08-25 really actually working now - just need to figure out how to get that…
60
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
61 # write the last commits heads
62 last_commits.each do |ref, sha|
63 if ref == 'trunk'
64 ref = 'heads/master'
65 else
66 ref = ref.gsub('branches', 'heads')
67 end
68 `git update-ref refs/#{ref} #{sha}`
69 end
70
7743f0d6 »
2008-08-23 so close to fully working
71 end
72 end
73
74 def build_tree_rev_shas
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
75 tree_exists = true
7743f0d6 »
2008-08-23 so close to fully working
76 @tree_rev_shas = {}
77 @remotes = []
78 Dir.chdir(@repo) do
79 remotes = `git remote`.split("\n")
80 remotes.each do |remote|
81 @remotes << remote
82 branch = "#{remote}/master"
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
83 commits = `git log --reverse --pretty=format:"%H:%s" #{branch}`.split("\n")
7743f0d6 »
2008-08-23 so close to fully working
84 commits = commits.map { |line| line.split(":") }
85 commits.each do |tree_sha, rev_id|
86 @tree_rev_shas[rev_id] = tree_sha
87 end
88 end
89 end
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
90 @tree_rev_shas
7743f0d6 »
2008-08-23 so close to fully working
91 end
92
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
93 def build_repo_log(branch = '')
94 @repo_log = []
95 log = `svn log --verbose #{@svn_url}`
7743f0d6 »
2008-08-23 so close to fully working
96 commits = log.split('------------------------------------------------------------------------')
97 commits.each do |commit|
98 lines = commit.split("\n")
99 next if !lines.shift
100 info = lines.shift.split("|").map { |e| e.strip }
101 rev, author, date, ln = info
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
102 line = lines.shift # Changed paths:
103 ref = ''
104 while ((line = lines.shift.chomp) != '') do
105 ign, ref, name = line.split('/')
106 end rescue nil
7743f0d6 »
2008-08-23 so close to fully working
107 message = lines.join("\n")
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
108 if (ref == 'trunk')
109 name = nil
110 else
111 name = name.split(' ').first if name
112 end
113 @repo_log << [rev, author, date, ln, message, ref, name]
7743f0d6 »
2008-08-23 so close to fully working
114 end
9c9abaef »
2008-08-24 this basically works now - mostly just need to change the repo urls t…
115 @repo_log
7743f0d6 »
2008-08-23 so close to fully working
116 end
117
118 def finish_repo
119 Dir.chdir(@repo) do
120 # remove all the temporary remote branches we were using
121 @remotes.each do |remote|
122 `git remote rm #{remote}`
123 end
124
125 # pack up the repository and remove any unreferenced objects we've left behind
126 `git prune`
127 `git pack-refs`
128 `git gc --aggressive`
129 end
130 end
131
132 end
133
134 repo_dir = ARGV[0]
135 svn_url = ARGV[1]
136
137 sk = SubSucka.new(repo_dir, svn_url)
138 sk.build
139
140
Something went wrong with that request. Please try again.