On Thu, Feb 12, 2009 at 05:30:58PM +0000, John Levon wrote: > Use the attached update-gate script
And here it is. regards john
#!/bin/bash # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # clone or update the xvm gate # set -e if echo $0 | grep ^/ 2>&1 > /dev/null ; then dir=$(dirname $0) else dir=$PWD/$(dirname $0) fi # copying a few functions directly from sunos.hg/inc/xvm.ksh - meaning this # script can be run standalone. # ------------------ start of content from xvm.ksh mq_gates="xen.hg virtinst.hg vbox.hg libvirt.hg" mq_repos="xen-patches.hg virtinst-patches.hg vbox-patches.hg libvirt-patches.hg" sfw_gates="urlgrabber.hg" hg_gates="vdisk.hg sunos.hg" cscope_gates="xen.hg libvirt.hg \ virtinst.hg urlgrabber.hg" all_gates="$mq_gates $sfw_gates $hg_gates" warn() { echo "$@" >&2 } # A simple function to compose a parent gate from a prefix and gate, # optionally replacing the patches component of the gate name if we're # going to opensolaris.org parentgate() { gate=$1 parent=$2 # remote gates if gate_is_remote $parent; then # When connecting to hg.opensolaris.org repositories, # the patch repositories can be found by taking parent # repository name, removing the the ".hg" portion and # appending "-patches.hg". Otherwise, they're found in # <parent>/.hg/patches if gate_is_patch $gate; then echo $(replace_opensolaris_patch $parent $gate) else echo ${parent}${gate} fi return 0 fi echo ${parent}${gate} } gate_is_patch() { gate=$1 if echo $gate | grep '.hg/patches$' 2>&1 > /dev/null; then return 0 else return 1 fi } gate_is_remote() { parent=$1 if echo $parent | grep "^ssh://" 2>&1 > /dev/null; then return 0 else return 1 fi } # checks if we're going to a repository which has a -patches component, # in which case we print a string pointing to the relocated patch gate # otherwise, print the standard MQ location for patches. replace_opensolaris_patch() { parent=$1 gate=$2 patch=$(echo $gate | sed -e 's#\.hg/\.hg/patches#-patches.hg#') if repo_exists ${parent}${patch} ; then echo ${parent}${patch} else echo ${parent}${gate} fi } repo_exists() { repo=$1 ret="" # this is a hack - ideally we'd just use "hg identify" here, but the # version of hg being used by xvm at the moment can't do that # with remote repos. mkdir -p /tmp/xvm-hg.$$ hg init /tmp/xvm-hg.$$ if hg -R /tmp/xvm-hg.$$ incoming -r 0 $repo > /dev/null 2>&1 ; then ret=0 else ret=1 fi rm -rf /tmp/xvm-hg.$$ return $ret } append_slash() { if echo $1 | grep '/$' 2>&1 > /dev/null; then echo $1 else echo $1/ fi } # This function performs some minor checks on the names of children/parents # passed to outgoing, update-gate, push-gate and webrev. fix_gate_name() { name=$1 # make sure the child & parent strings have '/' at the end of # them if they're directories. Needed because elsewhere we # compose gates using ${child}${gate} if echo $name | grep '+$' 2>&1 > /dev/null ; then warn "NOTE: Using $name as a gate prefix." if ! gate_is_remote $name ; then mkdir -p $(dirname $name) fi else if ! gate_is_remote $name ; then mkdir -p $name fi name=$(append_slash $name) fi echo $name } # ------------------ end of content from xvm.ksh usage() { echo "usage: update-gate [child] [parent]" >&2 exit 1 } [ "$1" = "-h" ] && usage [ "$1" = "-?" ] && usage find_parent() { # 1: a specified parent [ -z "$parent" ] || return 0 # 2: the default parent of the current hg root parent=`hg paths default 2>/dev/null | sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` [ -z "$parent" ] || return 0 [ -n "$XVM_WS" -a -d "${XVM_WS}sunos.hg/" ] || \ export XVM_WS=`echo $CODEMGR_WS | \ sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` if [ -d "${XVM_WS}" ] ; then export XVM_WS=${XVM_WS}/ fi # 3: the default parent of an hg tree [ -z "$XVM_WS" ] || { parent=`hg -R ${XVM_WS}sunos.hg/ paths default-push \ 2>/dev/null | sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` [ -z "$parent" ] || return 0 parent=`hg -R ${XVM_WS}sunos.hg paths default 2>/dev/null | sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` [ -z "$parent" ] || return 0 } # 4: the path holding this script parent=`dirname $0 | sed 's+sunos.hg/bin++'` [ -d "${parent}sunos.hg" ] && return 0 # 5: defaults parent="ssh://[email protected]/hg/xvm/xvm-unstable+" echo Pulling from default parent location $parent } find_child() { # 1: a specified child [ -z "$child" ] || return 0 [ -n "$XVM_WS" -a -d "${XVM_WS}sunos.hg/" ] || \ export XVM_WS=`echo $CODEMGR_WS | \ sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` # 2: the workspace root child=$XVM_WS [ -n "$child" ] && return 0 # 3: from the current hg root child=`hg root 2>/dev/null | sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` [ -z "$child" ] || return 0 # 4: via CODEMGR_WS [ -n "$XVM_WS" -a -d "${XVM_WS}sunos.hg/" ] || \ export XVM_WS=`echo $CODEMGR_WS | \ sed 's,[a-z]*\.hg,,;s,\.hg/patches,,'` # 5: a default child=./xvm-gate } child=$1 parent=$2 find_parent find_child child=$(fix_gate_name $child) parent=$(fix_gate_name $parent) echo "pulling from $parent to $child" if [ -d "${parent}sunos.hg" ]; then method=local else method=ssh fi export XVM_WS=$child for gate in $mq_gates; do pgate=$(parentgate $gate $parent) cgate=${child}${gate} if [ "$method" = "local" ]; then [ `hg -R $pgate qapplied | wc -l` -ne 0 ] && { echo "$pgate has applied patches: cannot pull" >&2 exit 1 } fi if [ -d $cgate ]; then [ `hg -R $cgate status -mard | wc -l` -eq 0 ] || { echo "Cannot update whilst local changes in $cgate" >&2 exit 1 } [ `hg -R $cgate qapplied | wc -l` -ne 0 ] && { hg -R $cgate qpop -a } fi done for gate in $all_gates; do if [ -d ${child}${gate} ]; then hg -R ${child}${gate} pull -uv ${parent}${gate} else hg clone ${parent}${gate} ${child}${gate} fi done for gate in $mq_gates; do cgate=${child}${gate}/.hg/patches patchgate="${gate}/.hg/patches" parentgate=`parentgate $patchgate $parent` if [ -d $cgate ]; then hg -R $cgate pull -uv $parentgate else hg clone $parentgate $cgate fi done
_______________________________________________ xen-discuss mailing list [email protected]
