To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / export-git.sh @ 1571:4c2b25b7e85f

History | View | Annotate | Download (3.1 KB)

1
#!/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
environment="$1"
26
hgdir="$2"
27
gitdir="$3"
28

    
29
if [ -z "$hgdir" ] || [ -z "$gitdir" ]; then
30
    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
    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
authordir="$gitdir/__AUTHORMAPS"
52
mkdir -p "$authordir"
53

    
54
wastedir="$gitdir/__WASTE"
55
mkdir -p "$wastedir"
56

    
57
echo
58
echo "$0 starting at $(date)"
59

    
60
echo "Extracting author maps..."
61

    
62
# 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
rm -f "$authordir/*"
66

    
67
"$rails" runner -e "$environment" "$progdir/create-repo-authormaps.rb" \
68
	 -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

    
80
    git_repodir="$gitdir/$reponame"
81

    
82
    if [ ! -f "$authormap" ]; then
83
	echo "No authormap file was created for repo $reponame, skipping"
84

    
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
	if [ -d "$git_repodir" ]; then
91
	    mv "$git_repodir" "$wastedir/$(date +%s).$reponame"
92
	fi
93
	    
94
	continue
95
    fi
96
    
97
    if [ ! -d "$git_repodir" ]; then
98
	git init --bare "$git_repodir"
99
    fi
100

    
101
    echo
102
    echo "About to run fast export for repo $reponame..."
103
    
104
    (
105
	cd "$git_repodir"
106

    
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
	"$fastexport" --quiet -r "$hgrepo" --hgtags -A "$authormap" --force
114

    
115
        git update-server-info
116
    )
117

    
118
    echo "Fast export done"
119
    
120
done
121

    
122
echo "$0 finishing at $(date)"
123