/[gentoo-x86]/eclass/subversion.eclass
Gentoo

Diff of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.46 Revision 1.47
1# Copyright 1999-2008 Gentoo Foundation 1# Copyright 1999-2008 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.46 2008/02/20 17:11:34 zlin Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.47 2008/02/20 17:55:27 cardoe Exp $
4 4
5# @ECLASS: subversion.eclass 5# @ECLASS: subversion.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Akinori Hattori <hattya@gentoo.org> 7# Akinori Hattori <hattya@gentoo.org>
8# Bo ├śrsted Andresen <zlin@gentoo.org> 8# Bo ├śrsted Andresen <zlin@gentoo.org>
61# svn+ssh:// 61# svn+ssh://
62# 62#
63# to peg to a specific revision, append @REV to the repo's uri 63# to peg to a specific revision, append @REV to the repo's uri
64ESVN_REPO_URI="${ESVN_REPO_URI:-}" 64ESVN_REPO_URI="${ESVN_REPO_URI:-}"
65 65
66# @ECLASS-VARIABLE: ESVN_REVISION
67# @DESCRIPTION:
68# User configurable revision checkout or update to from the repository
69#
70# Useful for live svn or trunk svn ebuilds allowing the user to peg
71# to a specific revision
72#
73# Note: This should never be set in an ebuild!
74ESVN_REVISION="${ESVN_REVISION:-}"
75
66# @ECLASS-VARIABLE: ESVN_PROJECT 76# @ECLASS-VARIABLE: ESVN_PROJECT
67# @DESCRIPTION: 77# @DESCRIPTION:
68# project name of your ebuild (= name space) 78# project name of your ebuild (= name space)
69# 79#
70# subversion eclass will check out the subversion repository like: 80# subversion eclass will check out the subversion repository like:
117# 127#
118# Can take two optional parameters: 128# Can take two optional parameters:
119# repo_uri - a repository URI. default is ESVN_REPO_URI. 129# repo_uri - a repository URI. default is ESVN_REPO_URI.
120# destination - a check out path in S. 130# destination - a check out path in S.
121subversion_fetch() { 131subversion_fetch() {
122 local repo_uri="$(subversion__get_repository_uri "${1}")" 132 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
133 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
123 local S_dest="${2}" 134 local S_dest="${2}"
135
136 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
124 137
125 # check for the protocol 138 # check for the protocol
126 local protocol="${repo_uri%%:*}" 139 local protocol="${repo_uri%%:*}"
127 140
128 case "${protocol}" in 141 case "${protocol}" in
153 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}" 166 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
154 167
155 local wc_path="$(subversion__get_wc_path "${repo_uri}")" 168 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
156 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion" 169 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
157 170
171 [[ -n "${revision}" ]] && options="${options} -r ${revision}"
172
173 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
174 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
175 ewarn "see \${ESVN_REPO_URI}"
176 fi
177
158 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\"" 178 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
159 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\"" 179 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
160 debug-print "${FUNCNAME}: options = \"${options}\"" 180 debug-print "${FUNCNAME}: options = \"${options}\""
161 181
162 if [[ ! -d ${wc_path}/.svn ]]; then 182 if [[ ! -d ${wc_path}/.svn ]]; then
163 # first check out 183 # first check out
164 einfo "subversion check out start -->" 184 einfo "subversion check out start -->"
165 einfo " repository: ${repo_uri}" 185 einfo " repository: ${repo_uri}${revision:+@}${revision}"
166 186
167 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}" 187 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
168 188
169 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}." 189 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
170 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}" 190 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
171 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}." 191 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
172 192
173 else 193 else
174 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy." 194 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
175 195
176 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}" 1) ]]; then 196 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
177 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched." 197 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
178 fi 198 fi
179 199
180 # update working copy 200 # update working copy
181 einfo "subversion update start -->" 201 einfo "subversion update start -->"
182 einfo " repository: ${repo_uri}" 202 einfo " repository: ${repo_uri}${revision:+@}${revision}"
183 203
184 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}" 204 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
185 205
186 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}" 206 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
187 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}." 207 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
263 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap." 283 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
264} 284}
265 285
266# @FUNCTION: subversion_wc_info 286# @FUNCTION: subversion_wc_info
267# @USAGE: [repo_uri] 287# @USAGE: [repo_uri]
268# @RETURN: ESVN_WC_URL, ESVN_WC_REVISION and ESVN_WC_PATH 288# @RETURN: ESVN_WC_URL, ESVN_WC_ROOT, ESVN_WC_UUID, ESVN_WC_REVISION and ESVN_WC_PATH
269# @DESCRIPTION: 289# @DESCRIPTION:
270# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI. 290# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
271# 291#
272# The working copy information on the specified repository URI are set to 292# The working copy information on the specified repository URI are set to
273# ESVN_WC_* variables. 293# ESVN_WC_* variables.
280 300
281 if [[ ! -d ${wc_path} ]]; then 301 if [[ ! -d ${wc_path} ]]; then
282 return 1 302 return 1
283 fi 303 fi
284 304
285 local k 305 export ESVN_WC_URL="$(subversion__svn_info "${wc_path}" "URL")"
286 306 export ESVN_WC_ROOT="$(subversion__svn_info "${wc_path}" "Repository Root")"
287 for k in url revision; do 307 export ESVN_WC_UUID="$(subversion__svn_info "${wc_path}" "Repository UUID")"
288 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")" 308 export ESVN_WC_REVISION="$(subversion__svn_info "${wc_path}" "Revision")"
289 done
290
291 export ESVN_WC_PATH="${wc_path}" 309 export ESVN_WC_PATH="${wc_path}"
292} 310}
293 311
294## -- Private Functions 312## -- Private Functions
295 313
306} 324}
307 325
308## -- subversion__get_repository_uri() --------------------------------------- # 326## -- subversion__get_repository_uri() --------------------------------------- #
309# 327#
310# param $1 - a repository URI. 328# param $1 - a repository URI.
311# param $2 - a peg revision is deleted from a return value if this is
312# specified.
313subversion__get_repository_uri() { 329subversion__get_repository_uri() {
314 local repo_uri="${1:-${ESVN_REPO_URI}}" 330 local repo_uri="${1}"
315 local remove_peg_revision="${2}"
316 331
317 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 332 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
318 debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
319 333
320 if [[ -z ${repo_uri} ]]; then 334 if [[ -z ${repo_uri} ]]; then
321 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty." 335 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
322 fi 336 fi
323 337
324 # delete trailing slash 338 # delete trailing slash
325 if [[ -z ${repo_uri##*/} ]]; then 339 if [[ -z ${repo_uri##*/} ]]; then
326 repo_uri="${repo_uri%/}" 340 repo_uri="${repo_uri%/}"
327 fi 341 fi
328 342
329 if [[ -n ${remove_peg_revision} ]]; then
330 if subversion__has_peg_revision "${repo_uri}"; then
331 repo_uri="${repo_uri%@*}" 343 repo_uri="${repo_uri%@*}"
332
333 debug-print "${FUNCNAME}: repo_uri has a peg revision"
334 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
335 fi
336 fi
337 344
338 echo "${repo_uri}" 345 echo "${repo_uri}"
339} 346}
340 347
341## -- subversion__get_wc_path() ---------------------------------------------- # 348## -- subversion__get_wc_path() ---------------------------------------------- #
342# 349#
343# param $1 - a repository URI. 350# param $1 - a repository URI.
344subversion__get_wc_path() { 351subversion__get_wc_path() {
345 local repo_uri="$(subversion__get_repository_uri "${1}" 1)" 352 local repo_uri="$(subversion__get_repository_uri "${1}")"
346 353
347 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 354 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
348 355
349 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}" 356 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
350} 357}
351 358
352## -- subversion__has_peg_revision() ----------------------------------------- # 359## -- subversion__get_peg_revision() ----------------------------------------- #
353# 360#
354# param $1 - a repository URI. 361# param $1 - a repository URI.
355subversion__has_peg_revision() { 362subversion__get_peg_revision() {
356 local repo_uri="${1}" 363 local repo_uri="${1}"
357 364
358 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 365 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
359 366
360 # repo_uri has peg revision ? 367 # repo_uri has peg revision ?
361 if [[ ${repo_uri} != *@* ]]; then 368 if [[ ${repo_uri} != *@* ]]; then
362 debug-print "${FUNCNAME}: repo_uri does not have a peg revision." 369 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
363 return 1
364 fi 370 fi
365 371
366 local peg_rev="${repo_uri##*@}" 372 local peg_rev=
367 373 [[ ${repo_uri} = *@* ]] && peg_rev="${repo_uri##*@}"
368 case "$(subversion__to_upper_case "${peg_rev}")" in
369 [[:digit:]]*)
370 # NUMBER
371 ;;
372 HEAD|BASE|COMMITED|PREV)
373 ;;
374 {[^}]*})
375 # DATE
376 ;;
377 *)
378 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
379 return 1
380 ;;
381 esac
382 374
383 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}" 375 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
384 376
385 return 0 377 echo "${peg_rev}"
386} 378}
387
388## -- subversion__to_upper_case() ----------------------------------------- #
389#
390# param $@ - the strings to upper case.
391subversion__to_upper_case() {
392 echo "${@}" | tr "[:lower:]" "[:upper:]"
393}

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.20