|
#!/usr/local/bin/bash |
|
|
|
# Assumes you've already got a SVN server up and running. |
|
# Also assumes that you've converted your commits over already. |
|
|
|
if [ "$#" -ne 3 ]; then |
|
printf 'Usage: %s <svn_url> <svn_repo> <git_dir>\n' "$0" |
|
printf 'Example: %s svn://127.0.0.1/freshports-1 periodics /freshports/periodics\n' "$0" |
|
exit 1 |
|
fi |
|
|
|
SVN_URL="$1" |
|
SVN_REPO="$2" |
|
GIT_LOCAL="$3" |
|
|
|
cd "$GIT_LOCAL" |
|
|
|
svn_tags=($(svn list "${SVN_URL}/${SVN_REPO}/tags" | sed -e 's/\///g')) |
|
for svn_tag in ${svn_tags[@]}; do |
|
svn_rev=$(svn info "${SVN_URL}/${SVN_REPO}/tags/${svn_tag}" | grep -E '^Last Changed Rev:' | cut -d' ' -f4) |
|
svn_log="$(svn log -r $svn_rev "${SVN_URL}" --xml)" |
|
author=$(echo "${svn_log}" | htmlq --text 'author') |
|
svn_date_raw="$(echo "${svn_log}" | htmlq --text 'date')" |
|
svn_date="$(echo "${svn_date_raw}" | sed -E 's/T/ /; s/\..*Z$//') +0000" |
|
svn_msg="$(echo "${svn_log}" | htmlq --text 'msg' | sed "s/^'//;s/'\$//")" |
|
|
|
git_log="$(git log --until="${svn_date}" --max-count=1 --author-date-order --pretty=format:"%h %ad %s" --date=iso)" |
|
git_commit=$(echo $git_log | cut -d' ' -f1) |
|
git_date=$(echo $git_log | cut -d' ' -f2,3,4) |
|
git_msg=$(echo $git_log | cut -d' ' -f5-) |
|
|
|
printf -- '--------------------------\n' |
|
printf 'SVN tag: %s; rev: %s; author: %s; timestamp: %s\n' \ |
|
"${svn_tag}" "${svn_rev}" "${author}" "${svn_date}" |
|
printf 'SVN message: %s\n' "${svn_msg}" |
|
printf 'GIT commit: %s; timestamp: %s\n' "${git_commit}" "${git_date}" |
|
printf 'GIT message: %s\n' "${git_msg}" |
|
|
|
if [ "" == "${svn_msg}" ]; then |
|
GIT_COMMITTER_DATE="${svn_date_raw}" git tag $svn_tag $git_commit |
|
else |
|
GIT_COMMITTER_DATE="${svn_date_raw}" git tag -a $svn_tag $git_commit -m "${svn_msg}" |
|
fi |
|
|
|
# You should review the tags and then `git push --tags` manually. |
|
|
|
done |