#!/usr/bin/env bash # Copyright (c) 2005, Intel Corporation, James Ketrenos function die() { ret=$1 shift echo $@ >&2 exit $ret } function pull-delta-repo() { parent=$1 if echo "$parent" | egrep -q "#"; then branch=$(echo $parent | sed -ne "s,.*#\(.*\),\1,p") parent=$(echo $parent | sed -ne "s,\([^#]*\).*,\1,") else branch=master fi echo "$parent" | grep -q "/\$" || parent="$parent/" mkdir -p ${dst}{refs/{heads,branches},objects} echo "Grabbing repo:" echo -en "\tparent..." rsync ${RSYNC_FLAGS} -ap ${parent}refs/heads/${branch} \ ${2}refs/heads/parent || die 5 "Could not pull $parent $branch" echo "done." echo -en "\tancestors..." rsync ${RSYNC_FLAGS} -ap ${parent}refs/ancestors \ ${2}refs/ancestors || die 5 "Could not pull $parent $branch" echo "done." cat ${2}refs/ancestors | while read url sha; do echo $url | grep "^#.*" && continue url=$(echo $url | sed -e "s,\([^#]*\).*,\1,") echo $url | grep -q "/\$" || url="$url/" dir=$(echo $sha | sed -ne "s#^\(..\).*#\1#p") obj=$(echo $sha | sed -ne "s#^..\(.*\)#\1#p") echo -e "Checking for updates on:\n\t$url\nfor\n\t$sha..." if [ ! -e ${2}objects/$dir/$obj ]; then echo "Updating objects from $url..." rsync ${RSYNC_FLAGS} -avpr \ ${url}objects/ \ ${2}objects/ || die 6 "Could not pull objects from $url." echo "Updated." else echo "$url up to date." fi done || exit 1 url=$parent sha=$(cat ${2}/refs/heads/parent) dir=$(echo $sha | sed -ne "s#^\(..\).*#\1#p") obj=$(echo $sha | sed -ne "s#^..\(.*\)#\1#p") if [ ! -e ${2}objects/$dir/$obj ]; then echo "Updating objects from $url..." rsync ${RSYNC_FLAGS} -avpr \ ${url}objects/ \ ${2}objects/ || die 6 "Coult not pull objects from $url." else echo "$url up to date." fi echo -e "$parent\t$sha" >> ${2}refs/ancestors cp ${2}refs/heads/parent ${2}refs/heads/master ln -sf refs/heads/master ${2}HEAD # rsync ${RSYNC_FLAGS} -ap ${1}refs/branches ${2}refs/branches/ } ([ ! "$1" ] || [ ! "$2" ]) && echo \ "usage: git-grab-overlay src_delta_repo target_full_repo" && exit 1 src="${1}" echo ${src} | grep -q "/\$" || src="${src}/" echo ${src} | grep -q "\.git/\$" || src="${src}.git/" dst="${2}" echo ${dst} | grep -q "/\$" || dst="${dst}/" echo ${dst} | grep -q "\.git/\$" || dst="${dst}.git/" [ ! -d ${dst} ] && (mkdir -p ${dst} || die 5 "Error creating '${dst}'") dst=`readlink -f ${dst}`/ pull-delta-repo $src $dst || exit 1 echo "" echo "${2} now contains the full tree from ${1}." echo -e "\nTo sync the files to the cache state, run:" echo -e "\t% cd ${2}" echo -e "\t% git-read-tree -m HEAD && git-checkout-cache -q -f -u -a" while true; do read -p "Do you want to do this now? [Y/n] :" reply case $reply in "n") exit 0 ;; "Y"|"y"|"") dir=$PWD cd ${2} git-read-tree -m HEAD git-checkout-cache -q -f -u -a cd $PWD exit 0 esac done