Skip to content

Instantly share code, notes, and snippets.

@nathandaly
Forked from cebe/.gitignore
Created December 7, 2017 12:36
Show Gist options
  • Save nathandaly/3253f69060bea81ca83366f68741b65d to your computer and use it in GitHub Desktop.
Save nathandaly/3253f69060bea81ca83366f68741b65d to your computer and use it in GitHub Desktop.
script to mirror svn repository
# subversion
.subversion
# mirror dirs
/mirror/*
/tmp/*
<?php
$authors = `svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq`;
$known = array(
'(no author)' => 'nobody <[email protected]>',
);
$found = array();
$authors = explode("\n", $authors);
foreach($authors as $author) {
$author = trim($author);
if (empty($author)) {
continue;
}
$key = $author;
if (substr($author, -10, 10) == '@gmail.com') {
$author = substr($author, 0, -10);
}
if (isset($known[$author])) {
$found[$key] = $known[$author];
} elseif (($pos = strpos($author, '@')) !== false) {
$found[$key] = substr($author, 0, $pos) . ' <' . $author . '>';
} else {
$found[$key] = $author . ' <' . $author . '@gmail.com>';
}
}
foreach($found as $old => $new) {
echo $old . ' = ' . $new . "\n";
}
#!/bin/sh
#
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "git > svn mirror script by CeBe <[email protected]>"
echo ""
echo "usage: $0 svnurl [giturl]"
echo ""
echo " svnurl base url to svn repo, NOT url to trunk! must end with /"
echo " giturl url of git repo to push code to. this repo should be empty"
echo " if not specified, you have to push repo in ./mirror yourself"
echo ""
echo "requires git, svn, php and svn2git (https://github.com/nirvdrum/svn2git)"
echo ""
exit 1;
fi
# create empty tmp dir
if [ -d ./tmp ] ; then
rm -rf ./tmp
fi
mkdir ./tmp
cd ./tmp
svn checkout $1 svn
# generate authors file
touch authors.txt
cd svn
php ../../authors.php > ../authors.txt
cd ../../
mkdir mirror
cd mirror
svn2git $1 -m -v --authors ../tmp/authors.txt
if ! [ "$2" = "" ] ; then
git remote add gitmirror $2
git push -u --all gitmirror
git push --tags gitmirror
fi
cd ..
#!/bin/sh
#
cd mirror
svn2git --rebase
ret=$?
if [ $ret -eq 0 ] ; then
git push -u --all gitmirror
ret=$?
fi
if [ $ret -eq 0 ] ; then
git push --tags gitmirror
ret=$?
fi
cd ..
exit $ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment