comparison extra/soundsoftware/update-external-repo.sh @ 242:bde4f47b6427 feature_73

Do more-or-less the right thing to pull in and update external repos
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 24 Feb 2011 15:04:51 +0000
parents 7658d21a1493
children defe55be97b9
comparison
equal deleted inserted replaced
241:7658d21a1493 242:bde4f47b6427
1 #!/bin/sh 1 #!/bin/sh
2
3 mirrordir="/var/mirror"
4 logfile="/var/www/test-cannam/log/update-external-repo.log"
2 5
3 project="$1" 6 project="$1"
4 local_repo="$2" 7 local_repo="$2"
5 remote_repo="$3" 8 remote_repo="$3"
6 9
7 if [ -z "$project" ] || [ -z "$local_repo" ] || [ -z "$remote_repo" ]; then 10 if [ -z "$project" ] || [ -z "$local_repo" ] || [ -z "$remote_repo" ]; then
8 echo "Usage: $0 <project> <local-repo-path> <remote-repo-url>" 11 echo "Usage: $0 <project> <local-repo-path> <remote-repo-url>"
9 exit 2 12 exit 2
10 fi 13 fi
11
12 14
13 # We need to handle different source repository types separately. 15 # We need to handle different source repository types separately.
14 # 16 #
15 # The convert extension cannot convert directly from a remote git 17 # The convert extension cannot convert directly from a remote git
16 # repo; we'd have to mirror to a local repo first. Incremental 18 # repo; we'd have to mirror to a local repo first. Incremental
30 # One other thing -- we can't actually tell the difference between 32 # One other thing -- we can't actually tell the difference between
31 # the various SCM types based on URL alone. We have to try them 33 # the various SCM types based on URL alone. We have to try them
32 # (ideally in an order determined by a guess based on the URL) and 34 # (ideally in an order determined by a guess based on the URL) and
33 # see what happens. 35 # see what happens.
34 36
37 project_mirror="$mirrordir/$project"
38 mkdir -p "$project_mirror"
39 project_repo_mirror="$project_mirror/repo"
35 40
36 41 # Some test URLs:
37 42 #
43 # http://aimc.googlecode.com/svn/trunk/
44 # http://aimc.googlecode.com/svn/
45 # http://vagar.org/git/flam
46 # https://github.com/wslihgt/IMMF0salience.git
47 # http://hg.breakfastquay.com/dssi-vst/
48 # git://github.com/schacon/hg-git.git
49 # http://svn.drobilla.net/lad (externals!)
50
51 # If we are importing from another distributed system, then our aim is
52 # to create either a Hg repo or a git repo at $project_mirror, which
53 # we can then pull from directly to the Hg repo at $local_repo (using
54 # hg-git, in the case of a git repo).
55
56 # Importing from SVN, we should use hg convert directly to the target
57 # hg repo (or should we?) but keep a record of the last changeset ID
58 # we brought in, and test each time whether it matches the last
59 # changeset ID actually in the repo
60
61 success=""
62
63 if [ -d "$project_repo_mirror" ]; then
64
65 # Repo mirror exists: update it
66 echo "$$: Mirror for project $project exists at $project_repo_mirror, updating" 1>&2
67
68 if [ -d "$project_repo_mirror/.hg" ]; then
69 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" && success=true
70 elif [ -d "$project_repo_mirror/.git" ]; then
71 ( cd "$project_repo_mirror" && git fetch "$remote_repo" ) && success=true
72 else
73 echo "$$: ERROR: Repo mirror dir $project_repo_mirror exists but is not an Hg or git repo" 1>&2
74 fi
75
76 else
77
78 # Repo mirror does not exist yet
79 echo "$$: Mirror for project $project does not yet exist at $project_repo_mirror, trying to convert or clone" 1>&2
80
81 case "$remote_repo" in
82 *git*)
83 git clone "$remote_repo" "$project_repo_mirror" ||
84 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror"
85 ;;
86 *)
87 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" ||
88 git clone "$remote_repo" "$project_repo_mirror"
89 ;;
90 esac && success=true
91
92 fi
93
94 echo "Success=$success"
95
96 if [ -n "$success" ]; then
97 echo "$$: Update successful, pulling into local repo at $local_repo"
98 if [ -d "$project_repo_mirror/.git" ]; then
99 if [ ! -d "$local_repo" ]; then
100 hg init "$local_repo"
101 fi
102 ( cd "$local_repo" && hg --config extensions.hgext.git= pull "$project_repo_mirror" )
103 else
104 ( cd "$local_repo" && hg pull "$project_repo_mirror" )
105 fi
106 fi