annotate extra/soundsoftware/update-external-repo.sh @ 854:be557d78a11b bug_94

Close obsolete branch bug_94
author Chris Cannam
date Thu, 14 Jul 2011 12:45:24 +0100
parents defe55be97b9
children d3af621ba9d4
rev   line source
chris@241 1 #!/bin/sh
chris@241 2
chris@242 3 mirrordir="/var/mirror"
chris@242 4 logfile="/var/www/test-cannam/log/update-external-repo.log"
chris@242 5
chris@241 6 project="$1"
chris@241 7 local_repo="$2"
chris@241 8 remote_repo="$3"
chris@241 9
chris@241 10 if [ -z "$project" ] || [ -z "$local_repo" ] || [ -z "$remote_repo" ]; then
chris@241 11 echo "Usage: $0 <project> <local-repo-path> <remote-repo-url>"
chris@241 12 exit 2
chris@241 13 fi
chris@241 14
chris@241 15 # We need to handle different source repository types separately.
chris@241 16 #
chris@241 17 # The convert extension cannot convert directly from a remote git
chris@241 18 # repo; we'd have to mirror to a local repo first. Incremental
chris@241 19 # conversions do work though. The hg-git plugin will convert
chris@241 20 # directly from remote repositories, but not via all schemes
chris@241 21 # (e.g. https is not currently supported). It's probably easier to
chris@241 22 # use git itself to clone locally and then convert or hg-git from
chris@241 23 # there.
chris@241 24 #
chris@241 25 # We can of course convert directly from remote Subversion repos,
chris@241 26 # but we need to keep track of that -- you can ask to convert into a
chris@241 27 # repo that has already been used (for Mercurial) and it'll do so
chris@241 28 # happily; we don't want that.
chris@241 29 #
chris@241 30 # Converting from a remote Hg repo should be fine!
chris@241 31 #
chris@241 32 # One other thing -- we can't actually tell the difference between
chris@241 33 # the various SCM types based on URL alone. We have to try them
chris@241 34 # (ideally in an order determined by a guess based on the URL) and
chris@241 35 # see what happens.
chris@241 36
chris@242 37 project_mirror="$mirrordir/$project"
chris@242 38 mkdir -p "$project_mirror"
chris@242 39 project_repo_mirror="$project_mirror/repo"
chris@241 40
chris@242 41 # Some test URLs:
chris@242 42 #
chris@242 43 # http://aimc.googlecode.com/svn/trunk/
chris@242 44 # http://aimc.googlecode.com/svn/
chris@242 45 # http://vagar.org/git/flam
chris@242 46 # https://github.com/wslihgt/IMMF0salience.git
chris@242 47 # http://hg.breakfastquay.com/dssi-vst/
chris@242 48 # git://github.com/schacon/hg-git.git
chris@242 49 # http://svn.drobilla.net/lad (externals!)
chris@242 50
chris@242 51 # If we are importing from another distributed system, then our aim is
chris@242 52 # to create either a Hg repo or a git repo at $project_mirror, which
chris@242 53 # we can then pull from directly to the Hg repo at $local_repo (using
chris@242 54 # hg-git, in the case of a git repo).
chris@242 55
chris@242 56 # Importing from SVN, we should use hg convert directly to the target
chris@242 57 # hg repo (or should we?) but keep a record of the last changeset ID
chris@242 58 # we brought in, and test each time whether it matches the last
chris@242 59 # changeset ID actually in the repo
chris@242 60
chris@242 61 success=""
chris@242 62
chris@242 63 if [ -d "$project_repo_mirror" ]; then
chris@242 64
chris@242 65 # Repo mirror exists: update it
chris@242 66 echo "$$: Mirror for project $project exists at $project_repo_mirror, updating" 1>&2
chris@242 67
chris@242 68 if [ -d "$project_repo_mirror/.hg" ]; then
chris@242 69 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" && success=true
chris@242 70 elif [ -d "$project_repo_mirror/.git" ]; then
chris@242 71 ( cd "$project_repo_mirror" && git fetch "$remote_repo" ) && success=true
chris@242 72 else
chris@242 73 echo "$$: ERROR: Repo mirror dir $project_repo_mirror exists but is not an Hg or git repo" 1>&2
chris@242 74 fi
chris@242 75
chris@242 76 else
chris@242 77
chris@242 78 # Repo mirror does not exist yet
chris@242 79 echo "$$: Mirror for project $project does not yet exist at $project_repo_mirror, trying to convert or clone" 1>&2
chris@242 80
chris@242 81 case "$remote_repo" in
chris@242 82 *git*)
chris@242 83 git clone "$remote_repo" "$project_repo_mirror" ||
chris@242 84 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror"
chris@242 85 ;;
chris@242 86 *)
chris@242 87 hg --config extensions.convert= convert --datesort "$remote_repo" "$project_repo_mirror" ||
chris@299 88 git clone "$remote_repo" "$project_repo_mirror" ||
chris@299 89 hg clone "$remote_repo" "$project_repo_mirror"
chris@242 90 ;;
chris@242 91 esac && success=true
chris@242 92
chris@242 93 fi
chris@242 94
chris@242 95 echo "Success=$success"
chris@242 96
chris@242 97 if [ -n "$success" ]; then
chris@242 98 echo "$$: Update successful, pulling into local repo at $local_repo"
chris@242 99 if [ -d "$project_repo_mirror/.git" ]; then
chris@242 100 if [ ! -d "$local_repo" ]; then
chris@242 101 hg init "$local_repo"
chris@242 102 fi
chris@242 103 ( cd "$local_repo" && hg --config extensions.hgext.git= pull "$project_repo_mirror" )
chris@242 104 else
chris@242 105 ( cd "$local_repo" && hg pull "$project_repo_mirror" )
chris@242 106 fi
chris@242 107 fi