annotate extra/soundsoftware/export-git.sh @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents 6074fffd8a1d
children
rev   line source
Chris@1543 1 #!/bin/bash
Chris@1543 2
Chris@1543 3 set -e
Chris@1543 4
Chris@1543 5 progdir=$(dirname $0)
Chris@1543 6 case "$progdir" in
Chris@1543 7 /*) ;;
Chris@1543 8 *) progdir="$(pwd)/$progdir" ;;
Chris@1543 9 esac
Chris@1543 10
Chris@1543 11 rails_scriptdir="$progdir/../../script"
Chris@1543 12 rails="$rails_scriptdir/rails"
Chris@1543 13
Chris@1543 14 if [ ! -x "$rails" ]; then
Chris@1543 15 echo "Expected to find rails executable at $rails"
Chris@1543 16 exit 2
Chris@1543 17 fi
Chris@1543 18
Chris@1543 19 fastexport="$progdir/../fast-export/hg-fast-export.sh"
Chris@1543 20 if [ ! -x "$fastexport" ]; then
Chris@1543 21 echo "Expected to find hg-fast-export.sh executable at $fastexport"
Chris@1543 22 exit 2
Chris@1543 23 fi
Chris@1543 24
Chris@1546 25 environment="$1"
Chris@1546 26 hgdir="$2"
Chris@1546 27 gitdir="$3"
Chris@1543 28
Chris@1543 29 if [ -z "$hgdir" ] || [ -z "$gitdir" ]; then
Chris@1546 30 echo "Usage: $0 <environment> <hgdir> <gitdir>"
Chris@1546 31 echo " where"
Chris@1546 32 echo " - environment is the Rails environment (development or production)"
Chris@1546 33 echo " - hgdir is the directory containing project Mercurial repositories"
Chris@1546 34 echo " - gitdir is the directory in which output git repositories are to be"
Chris@1546 35 echo " created or updated"
Chris@1543 36 exit 2
Chris@1543 37 fi
Chris@1543 38
Chris@1543 39 if [ ! -d "$hgdir" ]; then
Chris@1543 40 echo "Mercurial repository directory $hgdir not found"
Chris@1543 41 exit 1
Chris@1543 42 fi
Chris@1543 43
Chris@1543 44 if [ ! -d "$gitdir" ]; then
Chris@1543 45 echo "Target git repository dir $gitdir not found (please create at least the empty directory)"
Chris@1543 46 exit 1
Chris@1543 47 fi
Chris@1543 48
Chris@1543 49 set -u
Chris@1543 50
Chris@1550 51 authordir="$gitdir/__AUTHORMAPS"
Chris@1543 52 mkdir -p "$authordir"
Chris@1543 53
Chris@1550 54 wastedir="$gitdir/__WASTE"
Chris@1550 55 mkdir -p "$wastedir"
Chris@1550 56
Chris@1557 57 echo
Chris@1557 58 echo "$0 starting at $(date)"
Chris@1557 59
Chris@1547 60 echo "Extracting author maps..."
Chris@1546 61
Chris@1550 62 # Delete any existing authormap files, because we want to ensure we
Chris@1550 63 # don't have an authormap for any project that was exportable but has
Chris@1550 64 # become non-exportable (e.g. has gone private)
Chris@1551 65 rm -f "$authordir/*"
Chris@1550 66
Chris@1546 67 "$rails" runner -e "$environment" "$progdir/create-repo-authormaps.rb" \
Chris@1543 68 -s "$hgdir" -o "$authordir"
Chris@1543 69
Chris@1543 70 for hgrepo in "$hgdir"/*; do
Chris@1543 71
Chris@1543 72 if [ ! -d "$hgrepo/.hg" ]; then
Chris@1543 73 echo "Directory $hgrepo does not appear to be a Mercurial repo, skipping"
Chris@1543 74 continue
Chris@1543 75 fi
Chris@1543 76
Chris@1543 77 reponame=$(basename "$hgrepo")
Chris@1543 78 authormap="$authordir/authormap_$reponame"
Chris@1559 79
Chris@1559 80 git_repodir="$gitdir/$reponame"
Chris@1543 81
Chris@1543 82 if [ ! -f "$authormap" ]; then
Chris@1547 83 echo "No authormap file was created for repo $reponame, skipping"
Chris@1550 84
Chris@1550 85 # If there is no authormap file, then we should not have a git
Chris@1550 86 # mirror -- this is a form of access control, not just an
Chris@1550 87 # optimisation (authormap files are expected to exist for all
Chris@1550 88 # exportable projects, even if empty). So if a git mirror
Chris@1550 89 # exists, we move it away
Chris@1560 90 if [ -d "$git_repodir" ]; then
Chris@1560 91 mv "$git_repodir" "$wastedir/$(date +%s).$reponame"
Chris@1550 92 fi
Chris@1550 93
Chris@1543 94 continue
Chris@1543 95 fi
Chris@1543 96
Chris@1559 97 if [ ! -d "$git_repodir" ]; then
Chris@1561 98 git init --bare "$git_repodir"
Chris@1543 99 fi
Chris@1543 100
Chris@1547 101 echo
Chris@1546 102 echo "About to run fast export for repo $reponame..."
Chris@1543 103
Chris@1543 104 (
Chris@1561 105 cd "$git_repodir"
Chris@1549 106
Chris@1549 107 # Force is necessary because git-fast-import (or git) can't handle
Chris@1549 108 # branches having more than one head ("Error: repository has at
Chris@1549 109 # least one unnamed head"), which happens from time to time in
Chris@1549 110 # valid Hg repos. With --force apparently it will just pick one
Chris@1549 111 # of the two heads arbitrarily, which is also alarming but is
Chris@1549 112 # more likely to be useful
Chris@1558 113 "$fastexport" --quiet -r "$hgrepo" --hgtags -A "$authormap" --force
Chris@1555 114
Chris@1555 115 git update-server-info
Chris@1543 116 )
Chris@1543 117
Chris@1543 118 echo "Fast export done"
Chris@1543 119
Chris@1543 120 done
Chris@1543 121
Chris@1557 122 echo "$0 finishing at $(date)"
Chris@1543 123