Mercurial > hg > soundsoftware-site
changeset 1543:05d639e5d59b feature_1136
First cut of a git export script
author | Chris Cannam |
---|---|
date | Tue, 12 Jan 2016 15:15:02 +0000 |
parents | 60acfbd8f6d6 |
children | f81fcbde7eaf |
files | extra/soundsoftware/create-repo-authormaps.rb extra/soundsoftware/export-git.sh |
diffstat | 2 files changed, 91 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/soundsoftware/create-repo-authormaps.rb Tue Jun 02 12:25:31 2015 +0100 +++ b/extra/soundsoftware/create-repo-authormaps.rb Tue Jan 12 15:15:02 2016 +0000 @@ -18,7 +18,7 @@ # This script does that, if given the two directory names as arguments # to the -s and -o options. In the above example: # -# script/rails runner create-repo-authormaps.rb -s /var/hg -o /var/repo-export/authormap +# ./script/rails runner -e production extra/soundsoftware/create-repo-authormaps.rb -s /var/hg -o /var/repo-export/authormap # # Note that this script will overwrite any existing authormap # files. (That's why the output files are given an authormap_ prefix, @@ -28,9 +28,9 @@ require 'getoptlong' opts = GetoptLong.new( - ['--scm-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], - ['--out-dir', '-o', GetoptLong::REQUIRED_ARGUMENT], - ['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT] + ['--scm-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--out-dir', '-o', GetoptLong::REQUIRED_ARGUMENT], + ['--environment', '-e', GetoptLong::OPTIONAL_ARGUMENT] ) $repos_base = ''
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/soundsoftware/export-git.sh Tue Jan 12 15:15:02 2016 +0000 @@ -0,0 +1,87 @@ +#!/bin/bash + +set -e + +progdir=$(dirname $0) +case "$progdir" in + /*) ;; + *) progdir="$(pwd)/$progdir" ;; +esac + +rails_scriptdir="$progdir/../../script" +rails="$rails_scriptdir/rails" + +if [ ! -x "$rails" ]; then + echo "Expected to find rails executable at $rails" + exit 2 +fi + +fastexport="$progdir/../fast-export/hg-fast-export.sh" +if [ ! -x "$fastexport" ]; then + echo "Expected to find hg-fast-export.sh executable at $fastexport" + exit 2 +fi + +hgdir="$1" +gitdir="$2" + +if [ -z "$hgdir" ] || [ -z "$gitdir" ]; then + echo "Usage: $0 <hgdir> <gitdir>" + echo "where hgdir is the directory containing project Mercurial repositories," + echo "and gitdir is the directory in which output git repositories are" + echo "to be created or updated" + exit 2 +fi + +if [ ! -d "$hgdir" ]; then + echo "Mercurial repository directory $hgdir not found" + exit 1 +fi + +if [ ! -d "$gitdir" ]; then + echo "Target git repository dir $gitdir not found (please create at least the empty directory)" + exit 1 +fi + +set -u + +authordir="$gitdir/AUTHORMAPS" + +mkdir -p "$authordir" + +"$rails" runner -e production "$progdir/create-repo-authormaps.rb" \ + -s "$hgdir" -o "$authordir" + +for hgrepo in "$hgdir"/*; do + + if [ ! -d "$hgrepo/.hg" ]; then + echo "Directory $hgrepo does not appear to be a Mercurial repo, skipping" + continue + fi + + reponame=$(basename "$hgrepo") + authormap="$authordir/authormap_$reponame" + gitrepo="$gitdir/$reponame" + + if [ ! -f "$authormap" ]; then + echo "Authormap file $authormap not found for repo $hgrepo, skipping: the create-repo-authormaps script already run by this script should have created an authormap file (even if empty) for every repo with a corresponding project" + continue + fi + + if [ ! -d "$gitrepo" ]; then + git init "$gitrepo" + fi + + echo "About to run fast export..." + + ( + cd "$gitrepo" + "$fastexport" -r "$hgrepo" -A "$authormap" + ) + + echo "Fast export done" + +done + +echo "All done" +