Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 142 lines (118 sloc) 3.814 kb
7743f0d Scott Chacon so close to fully working
authored
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
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
17 build_repo_log
18 build_tree_rev_shas
19 write_commits
7743f0d Scott Chacon so close to fully working
authored
20 finish_repo
c33099c Scott Chacon lame exit for now, but its a start
authored
21 register_finish
7743f0d Scott Chacon so close to fully working
authored
22 end
23
c33099c Scott Chacon lame exit for now, but its a start
authored
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
7743f0d Scott Chacon so close to fully working
authored
30 def get_branch_list(br)
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
31 branches = `svn list #{@svn_url}/#{br}`.split("\n").map { |b| b.gsub('/', '') }
7743f0d Scott Chacon so close to fully working
authored
32 end
33
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
34 def write_commits
35 last_commits = {}
7743f0d Scott Chacon so close to fully working
authored
36 Dir.chdir(@repo) do
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
37 @repo_log.reverse.each do |commit|
38 next if !(commit_sha = @tree_rev_shas[commit[0]])
7743f0d Scott Chacon so close to fully working
authored
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
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
45
46 ref = commit[5]
47 name = commit[6]
0653bae Scott Chacon really actually working now - just need to figure out how to get that la...
authored
48 next if !(ref == 'trunk' || ref == 'tags' || ref == 'branches')
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
49 ref = File.join(ref, name) if ref != 'trunk'
50
7743f0d Scott Chacon so close to fully working
authored
51 parent = ''
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
52 last_commit = last_commits[ref] || last_commits['trunk']
7743f0d Scott Chacon so close to fully working
authored
53 parent = "-p #{last_commit}" if last_commit
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
54
55 tree_sha = `git rev-parse #{commit_sha}:#{ref}`.strip
56
0653bae Scott Chacon really actually working now - just need to figure out how to get that la...
authored
57 tc = `git commit-tree #{tree_sha} #{parent} < #{comment.path}`.strip
58 last_commits[ref] = tc if tc != ''
7743f0d Scott Chacon so close to fully working
authored
59 end
0653bae Scott Chacon really actually working now - just need to figure out how to get that la...
authored
60
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
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
7743f0d Scott Chacon so close to fully working
authored
71 end
72 end
73
74 def build_tree_rev_shas
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
75 tree_exists = true
7743f0d Scott Chacon so close to fully working
authored
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"
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
83 commits = `git log --reverse --pretty=format:"%H:%s" #{branch}`.split("\n")
7743f0d Scott Chacon so close to fully working
authored
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
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
90 @tree_rev_shas
7743f0d Scott Chacon so close to fully working
authored
91 end
92
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
93 def build_repo_log(branch = '')
94 @repo_log = []
95 log = `svn log --verbose #{@svn_url}`
7743f0d Scott Chacon so close to fully working
authored
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
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
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
7743f0d Scott Chacon so close to fully working
authored
107 message = lines.join("\n")
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
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]
7743f0d Scott Chacon so close to fully working
authored
114 end
9c9abae Scott Chacon this basically works now - mostly just need to change the repo urls to b...
authored
115 @repo_log
7743f0d Scott Chacon so close to fully working
authored
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]
93c6c51 Scott Chacon got some successful imports - about a 2-3x increase on a 5-6 node array
authored
136 repo_dir = repo_dir.gsub(/http:\/\/(.*?)\@/, 'http://')
7743f0d Scott Chacon so close to fully working
authored
137
138 sk = SubSucka.new(repo_dir, svn_url)
139 sk.build
140
141
Something went wrong with that request. Please try again.