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 @ 383:47ae83ce8db8

History | View | Annotate | Download (3.71 KB)

1
#!/bin/sh
2

    
3
mirrordir="/var/mirror"
4
logfile="/var/www/test-cannam/log/update-external-repo.log"
5

    
6
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
project_mirror="$mirrordir/$project"
38
mkdir -p "$project_mirror"
39
project_repo_mirror="$project_mirror/repo"
40

    
41
  # 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
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
	    hg clone "$remote_repo" "$project_repo_mirror"
90
	    ;;
91
    esac && success=true
92

    
93
fi
94
	
95
echo "Success=$success"
96

    
97
if [ -n "$success" ]; then
98
    echo "$$: Update successful, pulling into local repo at $local_repo"
99
    if [ -d "$project_repo_mirror/.git" ]; then
100
	if [ ! -d "$local_repo" ]; then
101
	    hg init "$local_repo"
102
	fi
103
	( cd "$local_repo" && hg --config extensions.hgext.git= pull "$project_repo_mirror" )
104
    else 
105
	( cd "$local_repo" && hg pull "$project_repo_mirror" )
106
    fi
107
fi