diff options
Diffstat (limited to 'extract-ruby-svn')
-rwxr-xr-x | extract-ruby-svn | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/extract-ruby-svn b/extract-ruby-svn new file mode 100755 index 0000000..63bedb9 --- /dev/null +++ b/extract-ruby-svn @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +sha1_to_rev() { git show -s --format=format:%B $1 | tail -n1 | grep -Po '(?<=@)[0-9]+'; } +rev_to_sha1() { git log --format=format:%H -n1 --grep '^git-svn-id: .*@'$2' ' $1; } + +BRANCH_EXTRACT=trunk-origin +[ "$(git branch --list $BRANCH_EXTRACT)" ] || + git branch $BRANCH_EXTRACT ruby-src/trunk + +[ ! -f trunk-work/.git ] && + git worktree add trunk-work $BRANCH_EXTRACT + +cd trunk-work +git checkout $BRANCH_EXTRACT + +# HEAD==ruby-src/trunk: first run; rewrite everything +if [ $(git rev-parse HEAD) = $(git rev-parse ruby-src/trunk) ]; then + filter_range= +else + old_head=$(git rev-parse HEAD) + echo "Updating '$BRANCH_EXTRACT'... HEAD was $old_head." + graftpoint="$(rev_to_sha1 ruby-src/trunk $(sha1_to_rev $old_head)) $old_head" + grep "^$graftpoint$" $(git rev-parse --git-common-dir)/info/grafts >/dev/null 2>&1 || + echo "$graftpoint" >> $(git rev-parse --git-common-dir)/info/grafts + git reset -q --hard ruby-src/trunk + filter_range=$old_head..$BRANCH_EXTRACT +fi + +echo "## Remove unrelated commits" +git filter-branch -f --prune-empty --index-filter ' + git rm --cached -qr --ignore-unmatch . && + git reset -q $GIT_COMMIT -- ext/openssl test/openssl sample/openssl && + git rm --cached -q --ignore-unmatch ext/openssl/depend ext/openssl/openssl.gemspec +' -- $filter_range ||: + +echo "## Adjust path" +git filter-branch -f --prune-empty --index-filter ' + git ls-files --stage | \ + sed "s:\ttest/openssl:\ttest:" | \ + sed "s:\text/openssl/lib:\tlib:" | \ + sed "s:\text/openssl/sample:\tsample/openssl:" | \ + sed "s:\tsample/openssl:\tsample:" | \ + GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && + mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" + : +' -- $filter_range ||: + +echo "## Fix author/committer email" +git filter-branch -f --env-filter ' + export GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL/b2dd03c8-39d4-4d8f-98ff-823fe69b080e/ruby-lang.org} + export GIT_COMMITTER_EMAIL=${GIT_COMMITTER_EMAIL/b2dd03c8-39d4-4d8f-98ff-823fe69b080e/ruby-lang.org} +' -- $filter_range ||: + +[ "$graftpoint" ] && + sed -ie "/^$graftpoint$/d" $(git rev-parse --git-common-dir)/info/grafts |