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 / update-external-repo.sh @ 1575:42618fc5ab46

History | View | Annotate | Download (4.75 KB)

1 241:7658d21a1493 chris
#!/bin/sh
2
3 242:bde4f47b6427 chris
mirrordir="/var/mirror"
4 1336:b61a51fb42b9 Chris
hg="/usr/bin/hg"
5 242:bde4f47b6427 chris
6 241:7658d21a1493 chris
project="$1"
7
local_repo="$2"
8
remote_repo="$3"
9
10
if [ -z "$project" ] || [ -z "$local_repo" ] || [ -z "$remote_repo" ]; then
11
    echo "Usage: $0 <project> <local-repo-path> <remote-repo-url>"
12
    exit 2
13
fi
14
15
  # We need to handle different source repository types separately.
16
  #
17
  # The convert extension cannot convert directly from a remote git
18
  # repo; we'd have to mirror to a local repo first.  Incremental
19
  # conversions do work though.  The hg-git plugin will convert
20
  # directly from remote repositories, but not via all schemes
21
  # (e.g. https is not currently supported).  It's probably easier to
22
  # use git itself to clone locally and then convert or hg-git from
23
  # there.
24
  #
25
  # We can of course convert directly from remote Subversion repos,
26
  # but we need to keep track of that -- you can ask to convert into a
27
  # repo that has already been used (for Mercurial) and it'll do so
28
  # happily; we don't want that.
29
  #
30
  # Converting from a remote Hg repo should be fine!
31
  #
32
  # One other thing -- we can't actually tell the difference between
33
  # the various SCM types based on URL alone.  We have to try them
34
  # (ideally in an order determined by a guess based on the URL) and
35
  # see what happens.
36
37 242:bde4f47b6427 chris
project_mirror="$mirrordir/$project"
38
mkdir -p "$project_mirror"
39
project_repo_mirror="$project_mirror/repo"
40 241:7658d21a1493 chris
41 242:bde4f47b6427 chris
  # Some test URLs:
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 436:4eb486dbf730 Chris
# If we have a record of the last successfully updated remote repo
64
# URL, check it against our current remote URL: if it has changed, we
65
# will need to start again with a new clone rather than pulling
66
# updates into the existing local mirror
67
68
successfile="$project_mirror/last_successful_url"
69
if [ -f "$successfile" ]; then
70
    last=$(cat "$successfile")
71 437:102056ec2de9 chris
    if [ x"$last" = x"$remote_repo" ]; then
72 436:4eb486dbf730 Chris
	echo "$$: Remote URL is unchanged from last successful update"
73
    else
74
	echo "$$: Remote URL has changed since last successful update:"
75
	echo "$$: Last URL was $last, current is $remote_repo"
76
	suffix="$$.$(date +%s)"
77
	echo "$$: Moving existing repos to $suffix suffix and starting afresh"
78
	mv "$project_repo_mirror" "$project_repo_mirror"."$suffix"
79
	mv "$local_repo" "$local_repo"."$suffix"
80
	mv "$successfile" "$successfile"."$suffix"
81 437:102056ec2de9 chris
	touch "$project_mirror/url_changed"
82 436:4eb486dbf730 Chris
    fi
83
fi
84
85 242:bde4f47b6427 chris
if [ -d "$project_repo_mirror" ]; then
86
87
    # Repo mirror exists: update it
88
    echo "$$: Mirror for project $project exists at $project_repo_mirror, updating" 1>&2
89
90
    if [ -d "$project_repo_mirror/.hg" ]; then
91 433:7fd72f22a42b Chris
	"$hg" --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" && success=true
92 439:d3faf348b287 chris
	if [ -z "$success" ]; then
93
	    ( cd "$project_repo_mirror" && "$hg" pull "$remote_repo" ) && success=true
94
	fi
95 242:bde4f47b6427 chris
    elif [ -d "$project_repo_mirror/.git" ]; then
96 431:d3af621ba9d4 Chris
	( cd "$project_repo_mirror" && git pull "$remote_repo" master ) && success=true
97 242:bde4f47b6427 chris
    else
98
	echo "$$: ERROR: Repo mirror dir $project_repo_mirror exists but is not an Hg or git repo" 1>&2
99
    fi
100
101
else
102
103
    # Repo mirror does not exist yet
104
    echo "$$: Mirror for project $project does not yet exist at $project_repo_mirror, trying to convert or clone" 1>&2
105
106
    case "$remote_repo" in
107
	*git*)
108
	    git clone "$remote_repo" "$project_repo_mirror" ||
109 433:7fd72f22a42b Chris
	    "$hg" --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror"
110 242:bde4f47b6427 chris
	    ;;
111
	*)
112 433:7fd72f22a42b Chris
	    "$hg" --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" ||
113 299:defe55be97b9 chris
	    git clone "$remote_repo" "$project_repo_mirror" ||
114 433:7fd72f22a42b Chris
	    "$hg" clone "$remote_repo" "$project_repo_mirror"
115 242:bde4f47b6427 chris
	    ;;
116
    esac && success=true
117
118
fi
119
120
echo "Success=$success"
121
122
if [ -n "$success" ]; then
123
    echo "$$: Update successful, pulling into local repo at $local_repo"
124 436:4eb486dbf730 Chris
    if [ ! -d "$local_repo" ]; then
125
	"$hg" init "$local_repo"
126
    fi
127 242:bde4f47b6427 chris
    if [ -d "$project_repo_mirror/.git" ]; then
128 436:4eb486dbf730 Chris
	( cd "$local_repo" && "$hg" --config extensions.hggit= pull "$project_repo_mirror" ) && echo "$remote_repo" > "$successfile"
129 242:bde4f47b6427 chris
    else
130 436:4eb486dbf730 Chris
	( cd "$local_repo" && "$hg" pull "$project_repo_mirror" ) && echo "$remote_repo" > "$successfile"
131 242:bde4f47b6427 chris
    fi
132
fi