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

Diff of /eclass/subversion.eclass

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

Revision 1.38 Revision 1.39
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.38 2006/09/27 16:20:20 hattya Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.39 2007/01/19 10:39:51 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#
122function subversion_fetch() { 125function subversion_fetch() {
123 126
124 local repo_uri=${1:-${ESVN_REPO_URI}} 127 local repo_uri="$(subversion__get_repository_uri "${1}")"
125 128 local S_dest="${2}"
126 if [[ -z "${repo_uri}" ]]; then
127 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
128 fi
129
130 # delete trailing slash
131 if [[ -z "${repo_uri##*/}" ]]; then
132 repo_uri=${repo_uri%/}
133 fi
134 129
135 # check for the protocol 130 # check for the protocol
136 local protocol=${repo_uri%%:*} 131 local protocol="${repo_uri%%:*}"
137 132
138 case "${protocol}" in 133 case "${protocol}" in
139 http|https) 134 http|https)
140 if built_with_use dev-util/subversion nowebdav; then 135 if built_with_use dev-util/subversion nowebdav; then
141 echo 136 echo
156 addread "/etc/subversion" 151 addread "/etc/subversion"
157 addwrite "${ESVN_STORE_DIR}" 152 addwrite "${ESVN_STORE_DIR}"
158 153
159 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then 154 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then
160 debug-print "${FUNCNAME}: initial checkout. creating subversion directory" 155 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
161
162 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}." 156 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
163 fi 157 fi
164 158
165 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}" 159 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
166 160
167 161 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
168 local wc_path=${ESVN_PROJECT}/${repo_uri##*/}
169 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion" 162 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
170 163
164 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
171 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\"" 165 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
172 debug-print "${FUNCNAME}: options = \"${options}\"" 166 debug-print "${FUNCNAME}: options = \"${options}\""
173 167
174 if [[ ! -d "${wc_path}/.svn" ]]; then 168 if [[ ! -d "${wc_path}/.svn" ]]; then
175 # first check out 169 # first check out
176 einfo "subversion check out start -->" 170 einfo "subversion check out start -->"
177 einfo " repository: ${repo_uri}" 171 einfo " repository: ${repo_uri}"
178 172
173 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
174
179 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}." 175 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
180 cd "${ESVN_PROJECT}" 176 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
181 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}." 177 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
182 178
183 else 179 else
184 subversion_wc_info || die "${ESVN}: unknown problem occurred while accessing working copy." 180 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
185 181
186 if [[ "${ESVN_WC_URL}" != "${repo_uri}" ]]; then 182 if [ "${ESVN_WC_URL}" != "$(subversion__get_repository_uri "${repo_uri}" 1)" ]; then
187 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched." 183 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
188 fi 184 fi
189 185
190 # update working copy 186 # update working copy
191 einfo "subversion update start -->" 187 einfo "subversion update start -->"
192 einfo " repository: ${repo_uri}" 188 einfo " repository: ${repo_uri}"
193 189
194 cd "${wc_path}" 190 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
191
192 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
195 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}." 193 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
196 194
197 fi 195 fi
198 196
199 einfo " working copy: ${ESVN_STORE_DIR}/${wc_path}" 197 einfo " working copy: ${wc_path}"
200 198
201 if ! has "export" ${ESVN_RESTRICT}; then 199 if ! has "export" ${ESVN_RESTRICT}; then
202 cd "${ESVN_STORE_DIR}/${wc_path}" 200 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
201
202 local S="${S}/${S_dest}"
203 203
204 # export to the ${WORKDIR} 204 # export to the ${WORKDIR}
205 #* "svn export" has a bug. see http://bugs.gentoo.org/119236 205 #* "svn export" has a bug. see http://bugs.gentoo.org/119236
206 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}." 206 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
207 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}." 207 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
211 211
212} 212}
213 213
214 214
215## -- subversion_bootstrap() ------------------------------------------------ # 215## -- subversion_bootstrap() ------------------------------------------------ #
216 216#
217function subversion_bootstrap() { 217function subversion_bootstrap() {
218 218
219 if has "export" ${ESVN_RESTRICT}; then 219 if has "export" ${ESVN_RESTRICT}; then
220 return 220 return
221 fi 221 fi
266 266
267} 267}
268 268
269 269
270## -- subversion_src_unpack() ------------------------------------------------ # 270## -- subversion_src_unpack() ------------------------------------------------ #
271 271#
272function subversion_src_unpack() { 272function subversion_src_unpack() {
273 273
274 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch." 274 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
275 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap." 275 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
276 276
277} 277}
278 278
279 279
280## -- subversion_wc_info() --------------------------------------------------- # 280## -- subversion_wc_info() --------------------------------------------------- #
281 281#
282# @param $1 - repository URI. default is ESVN_REPO_URI.
283#
282function subversion_wc_info() { 284function subversion_wc_info() {
283 285
286 local repo_uri="$(subversion__get_repository_uri "${1}")"
287 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
288
289 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
290 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
291
292 if [[ ! -e "${wc_path}" ]]; then
293 return 1
294 fi
295
296 local k
297
298 for k in url revision; do
299 export ESVN_WC_$(echo "${k}" | tr "[a-z]" "[A-Z]")="$(subversion__svn_info "${wc_path}" "${k}")"
300 done
301
302}
303
304
305## -- Private Functions
306
307
308## -- subversion__svn_info() ------------------------------------------------- #
309#
310# @param $1 - a target.
311# @param $2 - a key name.
312#
313function subversion__svn_info() {
314
315 local target="${1}"
316 local key="${2}"
317
318 env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
319
320}
321
322
323## -- subversion__get_repository_uri() --------------------------------------- #
324#
325# @param $1 - a repository URI.
326# @param $2 - a peg revision is deleted from a return value if this is
327# specified.
328#
329function subversion__get_repository_uri() {
330
284 local repo_uri=${ESVN_REPO_URI} 331 local repo_uri="${1:-${ESVN_REPO_URI}}"
332 local remove_peg_revision="${2}"
333
334 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
335 debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
336
337 if [[ -z "${repo_uri}" ]]; then
338 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
339 fi
285 340
286 # delete trailing slash 341 # delete trailing slash
287 if [[ -z "${repo_uri##*/}" ]]; then 342 if [[ -z "${repo_uri##*/}" ]]; then
288 repo_uri="${repo_uri%/}" 343 repo_uri="${repo_uri%/}"
289 fi 344 fi
290 345
346 if [[ -n "${remove_peg_revision}" ]]; then
347 if subversion__has_peg_revision "${repo_uri}"; then
348 repo_uri="${repo_uri%@*}"
349
350 debug-print "${FUNCNAME}: repo_uri has a peg revision"
351 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
352 fi
353 fi
354
355 echo "${repo_uri}"
356
357}
358
359
360## -- subversion__get_wc_path() ---------------------------------------------- #
361#
362# @param $1 - a repository URI.
363#
364function subversion__get_wc_path() {
365
366 local repo_uri="$(subversion__get_repository_uri "${1}" 1)"
367
368 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
369
291 local wc_path=${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/} 370 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
292 371
293 if [[ ! -e "${wc_path}" ]]; then 372}
373
374
375## -- subversion__has_peg_revision() ----------------------------------------- #
376#
377# @param $1 - a repository URI.
378#
379function subversion__has_peg_revision() {
380
381 local repo_uri="${1}"
382
383 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
384
385 # repo_uri has peg revision ?
386 if [[ "${repo_uri}" != *@* ]]; then
387 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
294 return 1 388 return 1
295 fi 389 fi
296 390
297 local k= 391 local peg_rev="${repo_uri##*@}"
392 local rev=$(subversion__svn_info "${repo_uri}" "revision")
298 393
299 for k in url revision; do 394 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
300 export ESVN_WC_$(echo "${k}" | tr [a-z] [A-Z])=$(env LC_ALL=C svn info "${wc_path}" | grep -i "^${k}" | cut -d" " -f2) 395 debug-print "${FUNCNAME}: rev = ${rev} "
301 done
302 396
397 if [[ "${peg_rev}" -eq "${rev}" ]]; then
398 return 0
399 fi
400
401 return 1
402
303} 403}

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.20