Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: felipec/pidgin-git-import
base: 46f42fc9fe
...
head fork: felipec/pidgin-git-import
compare: 2678e8282f
  • 7 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 29, 2012
Felipe Contreras fix: trivial cleanups
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
11fc1fc
Felipe Contreras fix: no point in saving missing marks
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
f8615de
Felipe Contreras util: improve run_query
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2895fda
Felipe Contreras fix: filter branch manually
Much more efficient, and we have better over what's going on.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
dace034
Felipe Contreras fix: fix messages correctly
So mtn information is not lost.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
5aae88a
Felipe Contreras fix: convert mtn ids to git ids in msgs
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
53c1ef6
Felipe Contreras Rename files
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2678e82
6 .gitignore
View
@@ -1,9 +1,7 @@
pidgin.git
pidgin.mtn
-marks-git.txt
-marks-mtn.txt
+marks-git
+marks-mtn
pidgin-fix.git
pidgin-trim.git
-commit_authors
-messages
split-repos
0  authors_map.txt → authors-map
View
File renamed without changes
0  branches_map.txt → branches-map
View
File renamed without changes
2  check
View
@@ -15,7 +15,7 @@ run_query %{select b.branch,lower(hex(b.revision_id)) from branch_leaves b} do |
end
branches_map = {}
-File.open('branches_map.txt').each do |l|
+File.open('branches-map').each do |l|
orig, map = l.split(" = ")
branches_map[orig] = map
end
204 fix
View
@@ -1,34 +1,33 @@
#!/usr/bin/env ruby
require 'fileutils'
+require 'date'
require './util'
-@fwd = File.expand_path(File.dirname(__FILE__))
-@messages = File.join(@fwd, "messages")
+$commit_authors = {}
+$commit_messages = {}
+$commit_map_git = {}
+$commit_map_mtn = {}
-FileUtils.mkdir_p(@messages)
-
-ENV['GIT_DIR'] = "pidgin.git"
-
-@commit_authors = File.open("commit_authors", "w")
@svn_map = {}
@map = {}
@marks = {}
@mtn_map = {}
-File.open('marks-mtn.txt').each do |l|
+File.open('marks-mtn').each do |l|
mark, id = l.split
@marks[mark] = id
end
-File.open('marks-git.txt').each do |l|
+File.open('marks-git').each do |l|
mark, git_id = l.split
mtn_id = @marks[mark]
+ next if not mtn_id
@mtn_map[mtn_id] = git_id
end
-File.open('svn_authors_map.txt').each do |l|
+File.open('svn-authors-map').each do |l|
l.scan(/(.*) = (.*) <(.*)>/) do |id,name,email|
@map[id] = [name, email]
end
@@ -43,8 +42,8 @@ File.open('svn-revisions').each do |l|
end
# convert svn path authors to something useful
-File.open("svn_authors.txt").each do |l|
- rev, author = l.chomp.split(" ", 2)
+File.open('svn-authors').each do |l|
+ rev, author = l.chomp.split(' ', 2)
mark = author[0] == '#'[0]
if not mark
author.gsub!(/ ?\(.*/,'')
@@ -59,31 +58,27 @@ File.open("svn_authors.txt").each do |l|
name, email = author, 'unknown'
end
@svn_map[rev].each do |id|
- @commit_authors.puts([id, name, email].join(":"))
+ $commit_authors[id] = [name, email]
end
end
-def fix_commit(rev, author = "")
+def fix_commit(rev, author = '')
id = @mtn_map[rev]
author.scan(/(.*) <(.*)>/) do |name, email|
- @commit_authors.puts([id, name, email].join(":"))
+ $commit_authors[id] = [name, email]
end
return if not block_given?
- File.open("#{@messages}/#{id}", 'w') do |f|
- f.puts(yield)
- end
+ $commit_messages[id] = yield
end
-require './fix_commits'
+require './fix-commits'
-@commit_authors.fsync
+FileUtils.rm_rf('pidgin-fix.git')
+system 'git clone --bare pidgin.git pidgin-fix.git'
-FileUtils.rm_rf("pidgin-fix.git")
-system "git clone --bare pidgin.git pidgin-fix.git"
-
-ENV['GIT_DIR'] = "pidgin-fix.git"
+ENV['GIT_DIR'] = 'pidgin-fix.git'
# check for lingering heads
@@ -103,26 +98,155 @@ end
end
end
-env_filter = <<EOF
-line=$(grep "^$GIT_COMMIT:" "#{@fwd}/commit_authors")
-if [ "$line" ]; then
- IFS=':' read __ GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL <<< "$line"
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
-fi
-EOF
+class Commit
+
+ attr_reader :id, :parents, :msg
+
+ def initialize(data)
+ @parents = []
+ msg = nil
+
+ data.each_line do |l|
+ if not msg
+ case l
+ when /^commit (.*)$/
+ @id = $1
+ when /^tree (.*)$/
+ @tree = $1
+ when /^author (.*) (<.*>) (.*)$/
+ @author = [$1, $2]
+ @author_date = DateTime.strptime($3, '%s %z')
+ when /^committer (.*) (<.*>) (.*)$/
+ @committer = [$1, $2]
+ @committer_date = DateTime.strptime($3, '%s %z')
+ when /^parents (.*)$/
+ @parents = $1.split(" ")
+ when /^$/
+ msg = ""
+ end
+ else
+ msg << l
+ end
+ end
+
+ @author = $commit_authors[@id] if $commit_authors[@id]
+
+ msg = msg.force_encoding('ascii-8bit')
+ if msg =~ /\A(.*?)\n(Monotone-\S+: .*\n*)+\Z/m
+ msg, mtn_msg = $1, $2
+ mtn_msg.gsub!(/^Monotone-Date: .*\n/, '')
+ @mtn_id = mtn_msg.match(/^Monotone-Revision: (.*)$/)[1]
+ @mtn_msg = mtn_msg
+ end
+
+ msg = $commit_messages[@id] if $commit_messages[@id]
+
+ @msg = msg
+
+ end
+
+ def export()
+
+ ENV['GIT_AUTHOR_NAME'] = @author[0]
+ ENV['GIT_AUTHOR_EMAIL'] = @author[1]
+ ENV['GIT_AUTHOR_DATE'] = @author_date.strftime('%s %z')
+ ENV['GIT_COMMITTER_NAME'] = @committer[0]
+ ENV['GIT_COMMITTER_EMAIL'] = @committer[1]
+ ENV['GIT_COMMITTER_DATE'] = @committer_date.strftime('%s %z')
+
+ msg = @msg
-msg_filter = <<EOF
-if [ -f "#{@messages}/$GIT_COMMIT" ]; then
- cat "#{@messages}/$GIT_COMMIT"
-else
- cat -
-fi
-EOF
+ # convert mtn ids
+ ids = {}
+ msg.scan(/\h{40}/).each do |mtn_id|
+ ids[mtn_id] = $commit_map_mtn[mtn_id] if $commit_map_mtn[mtn_id]
+ end
+ ids.each do |mtn_id, new_id|
+ msg.gsub!(/#{mtn_id}/, new_id)
+ end
+
+ msg = msg + "\n" + @mtn_msg
+ new_id = nil
+
+ parents = @parents.map { |e| ['-p', $commit_map_git[e]] }.flatten
+ IO.popen(['git', 'commit-tree', @tree] + parents, "w+") do |pipe|
+ pipe.write(msg)
+ pipe.close_write
+ new_id = pipe.read().chomp()
+ end
+
+ $commit_map_mtn[@mtn_id] = new_id
+ $commit_map_git[@id] = new_id
+
+ end
+
+end
+
+stack = []
+
+heads = `git rev-parse --no-flags --revs-only --symbolic-full-name --all`.split
+
+format = [
+ 'commit %H',
+ 'tree %T',
+ 'author %an <%ae> %ad',
+ 'committer %cn <%ce> %cd',
+ 'parents %P',
+ '', '%B' ].join('%n')
+args = %w[--reverse --topo-order --parents --simplify-merges --all]
+command = %W[git log -z -s --date=raw --format=format:#{format}] + args
+IO.popen(command).each("\0") do |data|
+ c = Commit.new(data.chomp("\0"))
+ stack << c
+end
-system "git filter-branch -d /tmp/git-rewrite/ --env-filter '#{env_filter}' --msg-filter '#{msg_filter}' --tag-name-filter cat -- --all"
+count = 0
+total = stack.size
+pending = {}
+
+def show(str)
+ $stdout.print str if $stdout.isatty
+end
+
+def is_ready(c)
+ c.parents.each do |e|
+ return false if not $commit_map_git[e]
+ end
+
+ c.msg.scan(/\h{40}/).each do |mtn_id|
+ git_id = @mtn_map[mtn_id]
+ next if not git_id or git_id == c.id
+ return false if not $commit_map_git[git_id]
+ end
+
+ return true
+end
+
+until stack.empty? do
+ c = stack.shift
+
+ next if $commit_map_git[c.id]
+
+ if not is_ready(c)
+ stack.unshift(c)
+ next_index = stack.index { |e| is_ready(e) }
+ stack.rotate!(next_index)
+ next
+ end
+
+ c.export
+ show "\rRewrite #{c.id} (#{count += 1}/#{total})"
+
+end
+
+heads.each do |e|
+ id = `git rev-parse #{e}^0`.chomp
+ new_id = $commit_map_git[id]
+ system('git', 'update-ref', e, new_id, id)
+ puts "%s %s -> %s" % [e, id, new_id]
+end
# cleanup old stuff
system 'git remote rm origin'
-system 'rm -rf pidgin-fix.git/refs/original'
system 'git reflog expire --expire=now --all'
system 'git prune --expire=now'
0  fix_commits.rb → fix-commits.rb
View
File renamed without changes
6 import
View
@@ -4,8 +4,8 @@ export GIT_DIR=pidgin.git
git init
-git_marks="marks-git.txt"
-mtn_marks="marks-mtn.txt"
+git_marks="marks-git"
+mtn_marks="marks-mtn"
touch $git_marks $mtn_marks
@@ -16,6 +16,6 @@ touch $git_marks $mtn_marks
options="--log-revids --log-certs"
mtn --db pidgin.mtn pull
-mtn --rcfile mtn-hooks.lua git_export --db pidgin.mtn --authors-file=authors_map.txt --branches-file=branches_map.txt \
+mtn --rcfile mtn-hooks.lua git_export --db pidgin.mtn --authors-file=authors-map --branches-file=branches-map \
--refs=revs --import-marks=$mtn_marks --export-marks=$mtn_marks $options |
git fast-import --import-marks=$git_marks --export-marks=$git_marks
0  svn_authors.txt → svn-authors
View
File renamed without changes
0  svn_authors_map.txt → svn-authors-map
View
File renamed without changes
10 util.rb
View
@@ -1,8 +1,8 @@
def run_query(query)
- result = `mtn db --db pidgin.mtn execute '#{query}'`
- result.split($/)[2..-1].each do |a|
- next if a.empty?
- yield a.split(" | ")
+ pipe = IO.popen(%W[mtn db --db pidgin.mtn execute #{query}])
+ pipe.each_with_index($/) do |a, i|
+ next if a.empty? or i < 2
+ yield a.chomp.split(" | ")
end
end
@@ -17,7 +17,7 @@ def for_each_author()
def load_authors_map
map = {}
- File.open('authors_map.txt').each do |l|
+ File.open('authors-map').each do |l|
l.scan(/(.*) = (.*) <(.*)>/) do |id,name,email|
map[id] = name
end

No commit comments for this range

Something went wrong with that request. Please try again.