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 @ 1553:baac54711ee9
History | View | Annotate | Download (2.98 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 | 1547:bca3b5e5bbf2 | Chris | echo "Extracting author maps..." |
| 58 | 1546:248c402992ba | Chris | |
| 59 | 1550:7d825cbd76c8 | Chris | # Delete any existing authormap files, because we want to ensure we |
| 60 | # don't have an authormap for any project that was exportable but has |
||
| 61 | # become non-exportable (e.g. has gone private) |
||
| 62 | 1551:36dddb6755f6 | Chris | rm -f "$authordir/*" |
| 63 | 1550:7d825cbd76c8 | Chris | |
| 64 | 1546:248c402992ba | Chris | "$rails" runner -e "$environment" "$progdir/create-repo-authormaps.rb" \ |
| 65 | 1543:05d639e5d59b | Chris | -s "$hgdir" -o "$authordir" |
| 66 | |||
| 67 | for hgrepo in "$hgdir"/*; do |
||
| 68 | |||
| 69 | if [ ! -d "$hgrepo/.hg" ]; then |
||
| 70 | echo "Directory $hgrepo does not appear to be a Mercurial repo, skipping" |
||
| 71 | continue |
||
| 72 | fi |
||
| 73 | |||
| 74 | reponame=$(basename "$hgrepo") |
||
| 75 | authormap="$authordir/authormap_$reponame" |
||
| 76 | gitrepo="$gitdir/$reponame" |
||
| 77 | |||
| 78 | if [ ! -f "$authormap" ]; then |
||
| 79 | 1547:bca3b5e5bbf2 | Chris | echo "No authormap file was created for repo $reponame, skipping" |
| 80 | 1550:7d825cbd76c8 | Chris | |
| 81 | # If there is no authormap file, then we should not have a git |
||
| 82 | # mirror -- this is a form of access control, not just an |
||
| 83 | # optimisation (authormap files are expected to exist for all |
||
| 84 | # exportable projects, even if empty). So if a git mirror |
||
| 85 | # exists, we move it away |
||
| 86 | if [ -d "$gitrepo" ]; then |
||
| 87 | mv "$gitrepo" "$wastedir/$(date +%s).$reponame" |
||
| 88 | fi |
||
| 89 | |||
| 90 | 1543:05d639e5d59b | Chris | continue |
| 91 | fi |
||
| 92 | |||
| 93 | if [ ! -d "$gitrepo" ]; then |
||
| 94 | git init "$gitrepo" |
||
| 95 | fi |
||
| 96 | |||
| 97 | 1547:bca3b5e5bbf2 | Chris | echo |
| 98 | 1546:248c402992ba | Chris | echo "About to run fast export for repo $reponame..." |
| 99 | 1543:05d639e5d59b | Chris | |
| 100 | ( |
||
| 101 | cd "$gitrepo" |
||
| 102 | 1549:28cde511f312 | Chris | |
| 103 | # Force is necessary because git-fast-import (or git) can't handle |
||
| 104 | # branches having more than one head ("Error: repository has at
|
||
| 105 | # least one unnamed head"), which happens from time to time in |
||
| 106 | # valid Hg repos. With --force apparently it will just pick one |
||
| 107 | # of the two heads arbitrarily, which is also alarming but is |
||
| 108 | # more likely to be useful |
||
| 109 | "$fastexport" --quiet -r "$hgrepo" -A "$authormap" --hg-hash --force |
||
| 110 | 1543:05d639e5d59b | Chris | ) |
| 111 | |||
| 112 | echo "Fast export done" |
||
| 113 | |||
| 114 | done |
||
| 115 | |||
| 116 | echo "All done" |