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

Diff of /eclass/subversion.eclass

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

Revision 1.35 Revision 1.41
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2007 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.35 2006/09/05 18:09:57 spb Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.41 2007/04/01 14:48:37 hattya Exp $
4 4
5## --------------------------------------------------------------------------- # 5## --------------------------------------------------------------------------- #
6# Author: Akinori Hattori <hattya@gentoo.org> 6# Author: Akinori Hattori <hattya@gentoo.org>
7# 7#
8# The subversion eclass is written to fetch the software sources from 8# The subversion eclass is written to fetch the software sources from
108: ESVN_PATCHES=${ESVN_PATCHES:=} 108: ESVN_PATCHES=${ESVN_PATCHES:=}
109 109
110 110
111## -- ESVN_RESTRICT: 111## -- ESVN_RESTRICT:
112# 112#
113# this should be a space delimited list of subversion eclass features to restrict. 113# this should be a space delimited list of subversion eclass features to
114# restrict.
114# export) 115# export)
115# don't export the working copy to S. 116# don't export the working copy to S.
116# 117#
117: ESVN_RESTRICT=${ESVN_RESTRICT:=} 118: ESVN_RESTRICT=${ESVN_RESTRICT:=}
118 119
119 120
120## -- subversion_fetch() ----------------------------------------------------- # 121## -- subversion_fetch() ----------------------------------------------------- #
121 122#
123# @param $1 - a repository URI. default is the ESVN_REPO_URI.
124# @param $2 - a check out path in S.
125#
122function subversion_fetch() { 126function subversion_fetch() {
123 127
124 local repo_uri=${1:-${ESVN_REPO_URI}} 128 local repo_uri="$(subversion__get_repository_uri "${1}")"
125 129 local S_dest="${2}"
126 if [[ -z "${repo_uri}" ]]; then
127 die "${ESVN}: ESVN_REPO_URI is empty."
128 fi
129
130 # delete trailing slash
131 if [[ -z "${repo_uri##*/}" ]]; then
132 repo_uri=${repo_uri%/}
133 fi
134 130
135 # check for the protocol 131 # check for the protocol
136 local protocol=${repo_uri%%:*} 132 local protocol="${repo_uri%%:*}"
137 133
138 case "${protocol}" in 134 case "${protocol}" in
139 http|https) 135 http|https)
140 if built_with_use dev-util/subversion nowebdav; then 136 if built_with_use dev-util/subversion nowebdav; then
141 echo 137 echo
150 *) 146 *)
151 die "${ESVN}: fetch from "${protocol}" is not yet implemented." 147 die "${ESVN}: fetch from "${protocol}" is not yet implemented."
152 ;; 148 ;;
153 esac 149 esac
154 150
151 # every time
152 addread "/etc/subversion"
153 addwrite "${ESVN_STORE_DIR}"
154
155 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then 155 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then
156 debug-print "${FUNCNAME}: initial checkout. creating subversion directory" 156 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
157
158 # Fix sandbox violations
159 addwrite ${ESVN_STORE_DIR%/*}
160
161 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}." 157 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
162 fi 158 fi
163 159
164 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}" 160 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
165 161
166 # every time 162 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
167 addread "/etc/subversion"
168
169 ESVN_OPTIONS="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion" 163 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
170 164
171 local wc_path=${ESVN_PROJECT}/${repo_uri##*/} 165 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
172
173 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\"" 166 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
167 debug-print "${FUNCNAME}: options = \"${options}\""
174 168
175 if [[ ! -d "${wc_path}/.svn" ]]; then 169 if [[ ! -d "${wc_path}/.svn" ]]; then
176 # first check out 170 # first check out
177 einfo "subversion check out start -->" 171 einfo "subversion check out start -->"
178 einfo " repository: ${repo_uri}" 172 einfo " repository: ${repo_uri}"
179 173
174 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
175
180 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}." 176 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
181 cd "${ESVN_PROJECT}" 177 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
182 ${ESVN_FETCH_CMD} ${ESVN_OPTIONS} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}." 178 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
183 179
184 else 180 else
185 subversion_wc_info || die "${ESVN}: unknown problem occurred while accessing working copy." 181 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
186 182
187 if [[ "${ESVN_WC_URL}" != "${ESVN_REPO_URI}" ]]; then 183 if [ "${ESVN_WC_URL}" != "$(subversion__get_repository_uri "${repo_uri}" 1)" ]; then
188 die "${ESVN}: ESVN_REPO_URI and working copy's URL are not matched." 184 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
189 fi 185 fi
190 186
191 # update working copy 187 # update working copy
192 einfo "subversion update start -->" 188 einfo "subversion update start -->"
193 einfo " repository: ${repo_uri}" 189 einfo " repository: ${repo_uri}"
194 190
195 # Fix sandbox violations 191 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
196 addwrite "${ESVN_STORE_DIR}"
197 192
198 cd "${wc_path}" 193 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
199 ${ESVN_UPDATE_CMD} ${ESVN_OPTIONS} || die "${ESVN}: can't update from ${repo_uri}." 194 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
200 195
201 fi 196 fi
202 197
203 einfo " working copy: ${ESVN_STORE_DIR}/${wc_path}" 198 einfo " working copy: ${wc_path}"
204 199
205 if ! has "export" ${ESVN_RESTRICT}; then 200 if ! has "export" ${ESVN_RESTRICT}; then
206 cd "${ESVN_STORE_DIR}/${wc_path}" 201 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
202
203 local S="${S}/${S_dest}"
207 204
208 # export to the ${WORKDIR} 205 # export to the ${WORKDIR}
209 #* "svn export" has a bug. see http://bugs.gentoo.org/119236 206 #* "svn export" has a bug. see http://bugs.gentoo.org/119236
210 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}." 207 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
211 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}." 208 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
215 212
216} 213}
217 214
218 215
219## -- subversion_bootstrap() ------------------------------------------------ # 216## -- subversion_bootstrap() ------------------------------------------------ #
220 217#
221function subversion_bootstrap() { 218function subversion_bootstrap() {
222 219
223 if has "export" ${ESVN_RESTRICT}; then 220 if has "export" ${ESVN_RESTRICT}; then
224 return 221 return
225 fi 222 fi
270 267
271} 268}
272 269
273 270
274## -- subversion_src_unpack() ------------------------------------------------ # 271## -- subversion_src_unpack() ------------------------------------------------ #
275 272#
276function subversion_src_unpack() { 273function subversion_src_unpack() {
277 274
278 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch." 275 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
279 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap." 276 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
280 277
281} 278}
282 279
283 280
284## -- subversion_wc_info() --------------------------------------------------- # 281## -- subversion_wc_info() --------------------------------------------------- #
285 282#
283# @param $1 - repository URI. default is ESVN_REPO_URI.
284#
286function subversion_wc_info() { 285function subversion_wc_info() {
287 286
287 local repo_uri="$(subversion__get_repository_uri "${1}")"
288 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
289
290 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
291 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
292
293 if [[ ! -e "${wc_path}" ]]; then
294 return 1
295 fi
296
297 local k
298
299 for k in url revision; do
300 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")"
301 done
302
303}
304
305
306## -- Private Functions
307
308
309## -- subversion__svn_info() ------------------------------------------------- #
310#
311# @param $1 - a target.
312# @param $2 - a key name.
313#
314function subversion__svn_info() {
315
316 local target="${1}"
317 local key="${2}"
318
319 env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
320
321}
322
323
324## -- subversion__get_repository_uri() --------------------------------------- #
325#
326# @param $1 - a repository URI.
327# @param $2 - a peg revision is deleted from a return value if this is
328# specified.
329#
330function subversion__get_repository_uri() {
331
288 local repo_uri=${ESVN_REPO_URI} 332 local repo_uri="${1:-${ESVN_REPO_URI}}"
333 local remove_peg_revision="${2}"
334
335 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
336 debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
337
338 if [[ -z "${repo_uri}" ]]; then
339 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
340 fi
289 341
290 # delete trailing slash 342 # delete trailing slash
291 if [[ -z "${repo_uri##*/}" ]]; then 343 if [[ -z "${repo_uri##*/}" ]]; then
292 repo_uri="${repo_uri%/}" 344 repo_uri="${repo_uri%/}"
293 fi 345 fi
294 346
347 if [[ -n "${remove_peg_revision}" ]]; then
348 if subversion__has_peg_revision "${repo_uri}"; then
349 repo_uri="${repo_uri%@*}"
350
351 debug-print "${FUNCNAME}: repo_uri has a peg revision"
352 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
353 fi
354 fi
355
356 echo "${repo_uri}"
357
358}
359
360
361## -- subversion__get_wc_path() ---------------------------------------------- #
362#
363# @param $1 - a repository URI.
364#
365function subversion__get_wc_path() {
366
367 local repo_uri="$(subversion__get_repository_uri "${1}" 1)"
368
369 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
370
295 local wc_path=${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/} 371 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
296 372
297 if [[ ! -e "${wc_path}" ]]; then 373}
374
375
376## -- subversion__has_peg_revision() ----------------------------------------- #
377#
378# @param $1 - a repository URI.
379#
380function subversion__has_peg_revision() {
381
382 local repo_uri="${1}"
383
384 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
385
386 # repo_uri has peg revision ?
387 if [[ "${repo_uri}" != *@* ]]; then
388 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
298 return 1 389 return 1
299 fi 390 fi
300 391
301 local k= 392 local peg_rev="${repo_uri##*@}"
302 393
303 for k in url revision; do 394 case "$(subversion__to_upper_case "${peg_rev}")" in
304 export ESVN_WC_$(echo "${k}" | tr [a-z] [A-Z])=$(env LANG=C svn info "${wc_path}" | grep -i "^${k}" | cut -d" " -f2) 395 [[:digit:]]*)
305 done 396 # NUMBER
397 ;;
398 HEAD|BASE|COMMITED|PREV)
399 ;;
400 {[^}]*})
401 # DATE
402 ;;
403 *)
404 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
405 return 1
406 ;;
407 esac
306 408
409 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
410
411 return 0
412
307} 413}
414
415
416## -- subversion__to_upper_case() ----------------------------------------- #
417#
418# @param $@ - the strings to upper case.
419#
420function subversion__to_upper_case() {
421 echo "${@}" | tr "[a-z]" "[A-Z]"
422}

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.20