# Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/mercurial.eclass,v 1.3 2006/10/13 23:45:03 agriffis Exp $ # mercurial: Fetch sources from mercurial repositories, similar to cvs.eclass. # To use this from an ebuild, set EHG_REPO_URI in your ebuild. Then either # leave the default src_unpack or call mercurial_src_unpack. inherit eutils EXPORT_FUNCTIONS src_unpack DEPEND="dev-util/mercurial net-misc/rsync" EHG_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/hg-src" # This must be set by the ebuild : ${EHG_REPO_URI:=} # repository uri # These can be set by the ebuild but are usually fine as-is : ${EHG_PROJECT:=$PN} # dir under EHG_STORE_DIR : ${EHG_CLONE_CMD:=hg clone --pull} # clone cmd : ${EHG_PULL_CMD:=hg pull -u -C} # pull cmd; update and clean out local changes : ${EHG_CLONE_CMD_NOUPDATE:=hg clone --pull -U} # clone cmd; no working copy : ${EHG_PULL_CMD_NOUPDATE:=hg pull} # pull cmd; no updating # should be set but blank to prevent using $HOME/.hgrc export HGRCPATH= function mercurial_fetch { declare repo=${1:-$EHG_REPO_URI} repo=${repo%/} # remove trailing slash [[ -n $repo ]] || die "EHG_REPO_URI is empty" declare module=${2:-${repo##*/}} if [[ ! -d ${EHG_STORE_DIR} ]]; then ebegin "create ${EHG_STORE_DIR}" addwrite / && mkdir -p "${EHG_STORE_DIR}" && chmod -f g+rw "${EHG_STORE_DIR}" && export SANDBOX_WRITE="${SANDBOX_WRITE%:/}" eend $? || die fi pushd "${EHG_STORE_DIR}" >/dev/null \ || die "can't chdir to ${EHG_STORE_DIR}" addwrite "$(pwd -P)" if [[ ! -d ${EHG_PROJECT}/${module} ]]; then # first check out - if it fails, remove the dir again. ebegin "${EHG_CLONE_CMD_NOUPDATE} ${repo}" mkdir -p "${EHG_PROJECT}" && chmod -f g+rw "${EHG_PROJECT}" && cd "${EHG_PROJECT}" && ${EHG_CLONE_CMD_NOUPDATE} "${repo}" "${module}" && cd "${module}" || rm -r "${module}" eend $? || die else # update working copy ebegin "${EHG_PULL_CMD_NOUPDATE} ${repo}" cd "${EHG_PROJECT}/${module}" && ${EHG_PULL_CMD_NOUPDATE} case $? in # hg pull returns status 1 when there were no changes to pull 1) eend 0 ;; *) eend $? || die ;; esac fi # use Mercurial instead of cp or rsync, # as that saves space in distfiles and some setup.py scripts might depend on # being run in an hg repository (For example the one from Mercurial itself). if [[ ! -d ${WORKDIR}/${module} ]]; then # clone to workdir, remove the created dir if the clone fails. ebegin "${EHG_CLONE_CMD} ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} ${WORKDIR}/${module}" mkdir -p "${WORKDIR}" && ${EHG_CLONE_CMD} ${EHG_STORE_DIR}/${EHG_PROJECT}/${module} ${WORKDIR}/${module} || rm -r "${WORKDIR}/${module}" eend $? || die else # pull from workdir ebegin "${EHG_PULL_CMD} ${EHG_PROJECT}/${module}" cd "${WORKDIR}/${module}" && ${EHG_PULL_CMD} case $? in # hg pull returns status 1 when there were no changes to pull 1) eend 0 ;; *) eend $? || die ;; esac fi popd >/dev/null } function mercurial_src_unpack { mercurial_fetch }