Chris@1543: #!/bin/bash Chris@1543: Chris@1543: set -e Chris@1543: Chris@1543: progdir=$(dirname $0) Chris@1543: case "$progdir" in Chris@1543: /*) ;; Chris@1543: *) progdir="$(pwd)/$progdir" ;; Chris@1543: esac Chris@1543: Chris@1543: rails_scriptdir="$progdir/../../script" Chris@1543: rails="$rails_scriptdir/rails" Chris@1543: Chris@1543: if [ ! -x "$rails" ]; then Chris@1543: echo "Expected to find rails executable at $rails" Chris@1543: exit 2 Chris@1543: fi Chris@1543: Chris@1543: fastexport="$progdir/../fast-export/hg-fast-export.sh" Chris@1543: if [ ! -x "$fastexport" ]; then Chris@1543: echo "Expected to find hg-fast-export.sh executable at $fastexport" Chris@1543: exit 2 Chris@1543: fi Chris@1543: Chris@1546: environment="$1" Chris@1546: hgdir="$2" Chris@1546: gitdir="$3" Chris@1543: Chris@1543: if [ -z "$hgdir" ] || [ -z "$gitdir" ]; then Chris@1546: echo "Usage: $0 " Chris@1546: echo " where" Chris@1546: echo " - environment is the Rails environment (development or production)" Chris@1546: echo " - hgdir is the directory containing project Mercurial repositories" Chris@1546: echo " - gitdir is the directory in which output git repositories are to be" Chris@1546: echo " created or updated" Chris@1543: exit 2 Chris@1543: fi Chris@1543: Chris@1543: if [ ! -d "$hgdir" ]; then Chris@1543: echo "Mercurial repository directory $hgdir not found" Chris@1543: exit 1 Chris@1543: fi Chris@1543: Chris@1543: if [ ! -d "$gitdir" ]; then Chris@1543: echo "Target git repository dir $gitdir not found (please create at least the empty directory)" Chris@1543: exit 1 Chris@1543: fi Chris@1543: Chris@1543: set -u Chris@1543: Chris@1550: authordir="$gitdir/__AUTHORMAPS" Chris@1543: mkdir -p "$authordir" Chris@1543: Chris@1550: wastedir="$gitdir/__WASTE" Chris@1550: mkdir -p "$wastedir" Chris@1550: Chris@1557: echo Chris@1557: echo "$0 starting at $(date)" Chris@1557: Chris@1547: echo "Extracting author maps..." Chris@1546: Chris@1550: # Delete any existing authormap files, because we want to ensure we Chris@1550: # don't have an authormap for any project that was exportable but has Chris@1550: # become non-exportable (e.g. has gone private) Chris@1551: rm -f "$authordir/*" Chris@1550: Chris@1546: "$rails" runner -e "$environment" "$progdir/create-repo-authormaps.rb" \ Chris@1543: -s "$hgdir" -o "$authordir" Chris@1543: Chris@1543: for hgrepo in "$hgdir"/*; do Chris@1543: Chris@1543: if [ ! -d "$hgrepo/.hg" ]; then Chris@1543: echo "Directory $hgrepo does not appear to be a Mercurial repo, skipping" Chris@1543: continue Chris@1543: fi Chris@1543: Chris@1543: reponame=$(basename "$hgrepo") Chris@1543: authormap="$authordir/authormap_$reponame" Chris@1559: Chris@1559: git_repodir="$gitdir/$reponame" Chris@1543: Chris@1543: if [ ! -f "$authormap" ]; then Chris@1547: echo "No authormap file was created for repo $reponame, skipping" Chris@1550: Chris@1550: # If there is no authormap file, then we should not have a git Chris@1550: # mirror -- this is a form of access control, not just an Chris@1550: # optimisation (authormap files are expected to exist for all Chris@1550: # exportable projects, even if empty). So if a git mirror Chris@1550: # exists, we move it away Chris@1560: if [ -d "$git_repodir" ]; then Chris@1560: mv "$git_repodir" "$wastedir/$(date +%s).$reponame" Chris@1550: fi Chris@1550: Chris@1543: continue Chris@1543: fi Chris@1543: Chris@1559: if [ ! -d "$git_repodir" ]; then Chris@1561: git init --bare "$git_repodir" Chris@1543: fi Chris@1543: Chris@1547: echo Chris@1546: echo "About to run fast export for repo $reponame..." Chris@1543: Chris@1543: ( Chris@1561: cd "$git_repodir" Chris@1549: Chris@1549: # Force is necessary because git-fast-import (or git) can't handle Chris@1549: # branches having more than one head ("Error: repository has at Chris@1549: # least one unnamed head"), which happens from time to time in Chris@1549: # valid Hg repos. With --force apparently it will just pick one Chris@1549: # of the two heads arbitrarily, which is also alarming but is Chris@1549: # more likely to be useful Chris@1558: "$fastexport" --quiet -r "$hgrepo" --hgtags -A "$authormap" --force Chris@1555: Chris@1555: git update-server-info Chris@1543: ) Chris@1543: Chris@1543: echo "Fast export done" Chris@1543: Chris@1543: done Chris@1543: Chris@1557: echo "$0 finishing at $(date)" Chris@1543: