Skip to content

Instantly share code, notes, and snippets.

@namelessjon
Created April 2, 2010 00:54
Show Gist options
  • Save namelessjon/352597 to your computer and use it in GitHub Desktop.
Save namelessjon/352597 to your computer and use it in GitHub Desktop.
brute-force history rewriting for dm adapters
#!/usr/bin/ruby
# rewrite_history.rb
# Jonathan D. Stott <jonathan.stott@gmail.com>
require 'fileutils'
adapters = %w{
mysql_adapter.rb
postgres_adapter.rb
sqlite3_adapter.rb
oracle_adapter.rb
sqlserver_adapter.rb
abstract_adapter.rb
data_objects_adapter.rb
in_memory_adapter.rb
yaml_adapter.rb
}
def sh(command)
system command || abort(command)
end
adapters.each do |adapter|
puts adapter
name = adapter.split('_').first
dirname = "/home/jon/tmp/dm-#{name}-adapter" # this is a ramdrive, for speed.
# create a clone
sh "git clone --quiet --no-hardlinks dm-core #{dirname}"
FileUtils.cd dirname do
# rewrite to subdir
sh "git filter-branch --prune-empty --subdirectory-filter lib/dm-core/adapters HEAD -- --all"
# now, successively rewrite by removing all but our adapter
to_go = adapters - [adapter]
sh "git filter-branch --force --prune-empty --index-filter 'git rm --cached --ignore-unmatch #{to_go.join(" ")}' HEAD"
# clean up after our butchery!
sh "git reset --hard"
sh "git prune"
sh "git gc --aggressive"
sh "git prune"
sh "git fsck"
end
FileUtils.mv dirname, Dir.pwd
end
@dkubb
Copy link

dkubb commented Apr 2, 2010

The In-Memory adapter probably doesn't have to be split out, it's the only one staying in dm-core

@namelessjon
Copy link
Author

Oh, I figured that. A slightly less ugly version would have had 'adapters' and 'adapters_to_create'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment