Skip to content

Instantly share code, notes, and snippets.

@abtris
Created March 21, 2011 12:15
Show Gist options
  • Select an option

  • Save abtris/879373 to your computer and use it in GitHub Desktop.

Select an option

Save abtris/879373 to your computer and use it in GitHub Desktop.
Automatic conversion from SVN to GIT
function getEmailFromLdap($username)
{
# company specific get from LDAP
$ldap_con = ldap_connect($ldap_server) or die("Could not connect to server. Error is " . ldap_error($ldap_con));
$ldap_bd = ldap_bind($ldap_con, $ldap_bind_dn, $ldap_bind_pass) or die("Could not bind to server. Error is " .ldap_error($ldap_con));
$result = ldap_search($ldap_con, $ldap_base_dn, "(sAMAccountName=$username)") or die ("Error in query");
$data = ldap_get_entries($ldap_con, $result);
return strtolower($data[0]['mail'][0]);
}
$authors = file_get_contents('authors-sorted.txt');
$authors = explode("\n", $authors);
$out = "";
foreach ($authors as $a) {
if (!empty($a)) {
echo $a . "\n";
$email = getEmailFromLdap($a);
$out .=trim($a).' = '. $a ."<$email>\n";
}
}
file_put_contents("authors.git.txt", $out);
svn log --xml http://svn.example.com/svn/Shared -r {2011-01-01}:HEAD | grep \<author | sort -u | sed -e :a -e 's/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}' >> authors.txt
svn log --xml http://svn.example.com/svn/project -r {2011-01-01}:HEAD | grep \<author | sort -u | sed -e :a -e 's/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}' >> authors.txt
cat authors.txt | sort | uniq > authors-sorted.txt
git init $1.git --bare --shared=true
echo "Created repository: $1"
chmod -Rf 775 $1
}
N=0
cat repos.list | while read LINE ; do
N=$((N+1))
crep $LINE
done
#!/bin/bash
function crep() {
# create repository
REV=`svn log --xml http://svn.example.com/svn/$1 -r {2011-01-01} | grep revision | awk -F \" '{print $2}'`
git svn clone -r $REV:HEAD -s -A authors.git.txt http://svn.example.com/svn/$1
cd $1
cp -Rf .git/refs/remotes/* .git/refs/heads/
rm -Rf .git/refs/remotes
git remote add origin ssh://git@gitserver.example.com/$1.git
git push origin --all
cd ..
echo "Cloned repository: $1"
}
N=0
cat repos.list | while read LINE ; do
N=$((N+1))
crep $LINE
done
ssh svn.example.com ls /srv/svn > repos.list.full
grep -v -f repos.blacklist repos.list.full > repos.list
@abtris

abtris commented Mar 21, 2011

Copy link
Copy Markdown
Author

git-svn-clone.sh is used or use gitolite for creating new repositories

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