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