Skip to content

Instantly share code, notes, and snippets.

@patearl
Created August 5, 2011 19:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patearl/1128347 to your computer and use it in GitHub Desktop.
Save patearl/1128347 to your computer and use it in GitHub Desktop.
NHibernate GIT Transform
#!/bin/bash
# To use this, git svn clone the NHibernate repo into an nh-git folder. Use the -s option and no other options.
# Patrick has a current synced copy on his system.
# These people don't seem to appear in any commits. For whatever reason, we are missing hundreds of commits.
# Use this command to get a new list when we find our missing branches.
# git log --format "%aN" | sort -u
# johntmorris=John Morris <johntmorris@users.sourceforge.net>
# jimcool=Jakub MArsik <jimcool@users.sourceforge.net>
# luggage=Donald L Mull Jr. <luggage@users.sourceforge.net>
# jerryshea2=Jerry Shea <jerryshea2@users.sourceforge.net>
# Another e-mail address:
# Sergey : sergey.p.k@gmail.com
# Exit on any error.
set -e
function phase1 {
echo ""
echo "*************************************************************************"
echo "* Copying repository before starting work."
echo "*************************************************************************"
rm -rf nh-git2
cp -r nh-git nh-git2
cd nh-git2
echo ""
echo "*************************************************************************"
echo "* Converting remotes into tags and branches"
echo "*************************************************************************"
git for-each-ref --format='%(refname)' refs/remotes/tags | cut -d / -f 4 | while read ref; do git tag "$ref" "refs/remotes/tags/$ref"; git branch -r -D "tags/$ref"; done
git for-each-ref --format='%(refname)' refs/remotes | cut -d / -f 3 | while read ref; do git branch "$ref" "refs/remotes/$ref"; git branch -r -D "$ref"; done
# Remove trunk since we have master.
git branch -D trunk
echo ""
echo "*************************************************************************"
echo "* Cloning bare repository"
echo "*************************************************************************"
cd ..
rm -rf NHibernate.git
git clone --bare nh-git2 NHibernate.git
cd NHibernate.git
echo ""
echo "*************************************************************************"
echo "* Fixing branches that came from src folder instead of nhibernate folder"
echo "*************************************************************************"
git filter-branch --tree-filter "if test -d src; then mkdir nhibernate; ls | grep -v nhibernate | xargs -i mv '{}' nhibernate; fi" -- --all
cd ..
} # End phase1. We now have NHibernate.git, a bare repository.
function rebasebranches {
rm -rf NHibernate.working
git clone NHibernate.git NHibernate.working
cd NHibernate.working
########### Record of branches with "src" folders.
# Ref 'refs/heads/LazyProps' was rewritten
# Ref 'refs/heads/LazyProps@4916' was rewritten
# Ref 'refs/heads/Linq%20to%20Nhibernate' was rewritten
# Ref 'refs/heads/Linq%20to%20Nhibernate@4455' was rewritten
# Ref 'refs/heads/static-proxies' was rewritten
# Ref 'refs/heads/static-proxis' was rewritten
# Ref 'refs/heads/static-proxis@3822' was rewritten
# Ref 'refs/tags/1.2.0.Beta1' was rewritten
# Ref 'refs/tags/1.2.0.Beta1@2281' was rewritten
# Rebase from 676a2fa550c0eb3c020b89cff149ac572d91135d (exclusive) to ead9f1a166f5d721b2206e17bad34317f5d7577c
# as static-proxies onto 95fa87e1d3d7acd6eccef959be0fa9c671a6683a
# 2008-10-09
git branch static-proxies-branch 95fa87e1d3d7acd6eccef959be0fa9c671a6683a
git checkout static-proxies-branch
git cherry-pick ce10fe6fefedf008c5d4b0889890c4287920f824
git cherry-pick ead9f1a166f5d721b2206e17bad34317f5d7577c
git branch -rd "origin/static-proxies"
git branch -rd "origin/static-proxis"
git branch -rd "origin/static-proxis@3822"
git checkout master
# Fix up 1.2.0.Beta1 tag that was based on a "src" tree.
git tag -d "1.2.0.Beta1@2281"
git tag -f 1.2.0.Beta1 f3e4c37d56b6b24951af9804963af6b033422a53
# Remove erroneous 1.2.x tag.
git tag -d 1.2.x
# Remember the end of a few branches.
git tag end-of-branch-alpha_avalon-proxy origin/alpha_avalon-proxy
git branch -rd origin/alpha_avalon-proxy
git tag end-of-branch-ReadOnlyEntities origin/ReadOnlyEntities
git branch -rd origin/ReadOnlyEntities
git tag end-of-branch-static-proxies static-proxies-branch
git branch -D static-proxies-branch
# Remove branches that are included elsewhere or have no content.
git branch -rd "origin/Linq%20to%20Nhibernate"
git branch -rd "origin/Linq%20to%20Nhibernate@4455"
git branch -rd "origin/HibernatePortOfReadOnlyCriteria"
git branch -rd "origin/ReadOnlyCriteria"
git branch -rd "origin/v10branch"
git branch -rd "origin/query-translator"
git branch -rd "origin/LazyProps"
git branch -rd "origin/LazyProps@4916"
# Create local branches for remaining tracking branches.
git branch 1.2.x origin/1.2.x
git branch 2.0.x origin/2.0.x
git branch 2.1.x origin/2.1.x
cd ..
}
function retag {
cd NHibernate.working
# Retag to remove empty commits.
git tag -f 3.2.0GA 38e940a8deb2ea18732def9f7f9ffdfddd729b0e
git tag -f 3.2.0.Alpha2 f90358fd8b9e6ca948305ece19d2952d4e8fdf01
git tag -f 3.2.0.Alpha1 273a753e54af961cfd59602d468a981d5a0e8363
git tag -f 3.1.0GA 7d80fe1139baed12bb35127d83fad680d8b68a0f
git tag -f 3.0.0GA 61adbc010d707c88247e324280467b8c258bba20
git tag -f 3.0.0.Alpha1 d9d112890732fa0a1ddfc16daab50a3759e36a86
git tag -f 2.1.1GA 03b5ccb2aadb3239b01469b8abc2960481f01a8f
git tag -f 2.1.0GA 1e3f44260d6c8a7f721babd39cb09577d531bb96
git tag -f 2.0.0.Alpha1 63787149e7b9633604950fba1e33579a8aaa184f
git tag -f 1.2.1.GA 072dce857433b670e47831d577cf3fcd65836e78
git tag -f 1.2.0.GA b145adfc3cd3677b843b6fdb9e64aa162a4c3201
git tag -f 1.2.0.CR2 1def2692e7b7aaa80864de0d06a772dee2d4a295
git tag -f 1.2.0.CR1 5039666b6e7811eb9037d4c30c947450f9c749a3
git tag -f 1.2.0.Beta3 80ca1da5e0d70ce5facdbc539df29493ac74dcba
git tag -f 1.2.0.Beta2 cc403efbcad812d26314327433273930a6cac631
git tag -f 1.2.0.Alpha1 df10d864a709bbd81d77928fde9cdd6a17cea3ad
git tag -f 1.0.4 ee7ff68312d0eb2a53aafe5736d154e258ffea37
git tag -f 1.0.3 2fb610a7bf387951852d5a77b430b2da9b369419
git tag -f rc_0-99-1-0 bdbab65b3c39b259603f3f22fb13701950685860
git tag -f beta_0-9-1-0 3ea855f641438eb1879e9b4f246d3f5875fc0597
git tag -f beta_0-9-0-0 46a3afc40a486f1aae0ab25e3c9d8cf6a34f8eab
git tag -f beta_0-8-4-0 f0368f393ba34d173cda975de95397397f835868
git tag -f beta_0-8-3-0 6949a58cb072c4e9efe9827b63c145f8fa60bd13
git tag -f beta_0-8-2-0 5d605d390d1cb4622f6f02f40ba3753c7b9663fc
git tag -f beta_0-8-1-0 978f13732ebc822e18654874a3be03a7c40d71c2
git tag -f beta_0-8-0-0 bf90c2a0adb952fba86a3f06d3c98253c9e30f84
git tag -f Pre_2-1_Refactor e752e2a8df06aca42d660422deae12c729ca98d4
git tag -f beta_0-6-0-0 41babe7c8941b3fd7f757f90f01c2ab4871c7073
git tag -f alpha_0-4-0-0 3bbc3ed3e88878af40be8880a20a670a39ab0366
git tag -f alpha_0-3-0-0_pre-avalon-proxy b42b4953564e95041df84890d928a801af394edb
git tag -f alpha_0-3-0-0 2c044594682f0308867bdf56933b6488c7a7c34c
git tag -f alpha_0-2-0-0 b28784618eea72b6757ec46bd640ac371f546271
git tag -f prealpha_0-1-0-0 f8b978b3e1845daec77c513a8aecb338c29b653e
cd ..
}
function rewriteauthors {
rm -rf NHibernate-Authors.git
git clone --bare NHibernate.working NHibernate-Authors.git
cd NHibernate-Authors.git
echo ""
echo "*************************************************************************"
echo "* Rewriting all author names and e-mail addresses."
echo "*************************************************************************"
# Typo present in converted repository.
#if [ "$GIT_AUTHOR_NAME" = "(no author)" ]; then am="(no auunknown)"$suffix; fi
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
suffix="@users.sourceforge.net"
if [ "$GIT_AUTHOR_NAME" = "(no author)" ]; then am="(no author)"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "RicBrown" ]; then an="Richard Brown"; am="flukefan@googlemail.com"; fi
if [ "$GIT_AUTHOR_NAME" = "ayenderahien" ]; then an="Ayende Rahien"; am="ayende@ayende.com"; fi
if [ "$GIT_AUTHOR_NAME" = "billhawes" ]; then an="Bill Hawes"; am="billhawes"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "chadly69" ]; then an="Chad Lee"; am="chadly69"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "crowdozer" ]; then an="Jim Bolla"; am="crowdozer"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "darioquintana" ]; then an="Dario Quintana"; am="darioquintana"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "davybrion" ]; then an="Davy Brion"; am="davybrion"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "demanic" ]; then an="Demetris Manikas"; am="demanic"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "edgarsanchez" ]; then an="Edgar Sanchez"; am="edgarsanchez"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "fabiomaulo" ]; then an="Fabio Maulo"; am="fabiomaulo@gmail.com"; fi
if [ "$GIT_AUTHOR_NAME" = "ifof" ]; then an="ifof"; am="ifof"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "julian-maughan" ]; then an="Julian Maughan"; am="julian.maughan@gmail.com"; fi
if [ "$GIT_AUTHOR_NAME" = "justme84" ]; then an="Sergey Koshcheyev"; am="justme84"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "karlchu" ]; then an="Karl Chu"; am="karlchu"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "kevinwilliams" ]; then an="Kevin Williams"; am="kevinwilliams"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "kpixel" ]; then an="Pierre Henri Kuate"; am="kpixel"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "mikedoerfler" ]; then an="Mike Doerfler"; am="mikedoerfler"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "mthird" ]; then an="Michael Third"; am="mthird"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "patearl" ]; then an="Patrick Earl"; am="patearl@patearl.net"; fi
if [ "$GIT_AUTHOR_NAME" = "phatcher" ]; then an="Paul Hatcher"; am="phatcher"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "pwistrand" ]; then an="Paul Wistrand"; am="pwistrand"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "ricbrown" ]; then an="Richard Brown"; am="flukefan@googlemail.com"; fi
if [ "$GIT_AUTHOR_NAME" = "sbohlen" ]; then an="Steve Bohlen"; am="sbohlen@gmail.com"; fi
if [ "$GIT_AUTHOR_NAME" = "steverstrong" ]; then an="Steve Strong"; am="steverstrong"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "szoke" ]; then an="Peter Smulovics"; am="szoke"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "tehlike" ]; then an="Tuna Toksoz"; am="tehlike"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "theoalbers" ]; then an="theoalbers"; am="theoalbers"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "tjb300" ]; then an="Tom Barrett"; am="tjb300"$suffix; fi
if [ "$GIT_AUTHOR_NAME" = "woil" ]; then an="Will Shaver"; am="woil"$suffix; fi
export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$an"
export GIT_COMMITTER_EMAIL="$am"
' -- --all
cd ..
}
function rewritelogs {
cd NHibernate-Authors.git
git filter-branch -f --msg-filter "sed 's/ c763bc11-fa2b-4e64-94e3-9b040f81b1a0//g'" -- --all
git filter-branch -f --msg-filter "sed 's,git-svn-id: file:///home/patearl/nh/,SVN: ,g'" -- --all
cd ..
}
function changeroot {
cd NHibernate-Authors.git
echo ""
echo "*************************************************************************"
echo "* Removing root level nhibernate folder."
echo "*************************************************************************"
git filter-branch -f --tree-filter "if test -d nhibernate; then find nhibernate -maxdepth 1 -mindepth 1 -exec mv {} . \\;; rmdir nhibernate; fi" -- --all
cd ..
}
function cleanup {
cd NHibernate-Authors.git
echo ""
echo "*************************************************************************"
echo "* Collect garbage."
echo "*************************************************************************"
git gc
echo ""
echo "*************************************************************************"
echo "* Checking out source for examination into NHibernate.converted."
echo "*************************************************************************"
cd ..
rm -rf NHibernate.converted
git clone NHibernate-Authors.git NHibernate.converted
}
function recreatebranches {
cd NHibernate.converted
git for-each-ref --format='%(refname)' | grep remotes | grep -v HEAD | grep -v master | cut -d / -f 4 | while read ref; do git branch $ref origin/$ref; done
cd ..
}
######## MAIN EXECUTION
phase1
rebasebranches
retag
rewriteauthors
rewritelogs
changeroot
cleanup
recreatebranches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment