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