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