/[gentoo-x86]/eclass/git-2.eclass
Gentoo

Diff of /eclass/git-2.eclass

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

Revision 1.14 Revision 1.21
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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/git-2.eclass,v 1.14 2011/08/22 04:46:31 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.21 2011/09/23 13:58:09 mgorny Exp $
4 4
5# @ECLASS: git-2.eclass 5# @ECLASS: git-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Donnie Berkholz <dberkholz@gentoo.org> 7# Donnie Berkholz <dberkholz@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 8# @BLURB: Eclass for fetching and unpacking git repositories.
125# We define it in function scope so user can define 125# We define it in function scope so user can define
126# all the variables before and after inherit. 126# all the variables before and after inherit.
127git-2_init_variables() { 127git-2_init_variables() {
128 debug-print-function ${FUNCNAME} "$@" 128 debug-print-function ${FUNCNAME} "$@"
129 129
130 local x 130 local esc_pn liverepo livebranch livecommit
131 esc_pn=${PN//[-+]/_}
131 132
132 : ${EGIT_SOURCEDIR="${S}"} 133 : ${EGIT_SOURCEDIR="${S}"}
133 134
134 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} 135 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"}
135 136
137 138
138 : ${EGIT_OPTIONS:=} 139 : ${EGIT_OPTIONS:=}
139 140
140 : ${EGIT_MASTER:=master} 141 : ${EGIT_MASTER:=master}
141 142
142 eval x="\$${PN//[-+]/_}_LIVE_REPO" 143 liverepo=${esc_pn}_LIVE_REPO
143 EGIT_REPO_URI=${x:-${EGIT_REPO_URI}} 144 EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}}
144 [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value" 145 [[ ${EGIT_REPO_URI} ]] || die "EGIT_REPO_URI must have some value"
145 146
146 : ${EVCS_OFFLINE:=} 147 : ${EVCS_OFFLINE:=}
147 148
148 eval x="\$${PN//[-+]/_}_LIVE_BRANCH" 149 livebranch=${esc_pn}_LIVE_BRANCH
149 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_BRANCH\" variable, you won't get any support" 150 [[ ${!livebranch} ]] && ewarn "QA: using \"${esc_pn}_LIVE_BRANCH\" variable, you won't get any support"
150 EGIT_BRANCH=${x:-${EGIT_BRANCH:-${EGIT_MASTER}}} 151 EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}}
151 152
152 eval x="\$${PN//[-+]/_}_LIVE_COMMIT" 153 livecommit=${esc_pn}_LIVE_COMMIT
153 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_COMMIT\" variable, you won't get any support" 154 [[ ${!livecommit} ]] && ewarn "QA: using \"${esc_pn}_LIVE_COMMIT\" variable, you won't get any support"
154 EGIT_COMMIT=${x:-${EGIT_COMMIT:-${EGIT_BRANCH}}} 155 EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}}
155 156
156 : ${EGIT_REPACK:=} 157 : ${EGIT_REPACK:=}
157 158
158 : ${EGIT_PRUNE:=} 159 : ${EGIT_PRUNE:=}
159} 160}
161# @FUNCTION: git-2_submodules 162# @FUNCTION: git-2_submodules
162# @DESCRIPTION: 163# @DESCRIPTION:
163# Internal function wrapping the submodule initialisation and update. 164# Internal function wrapping the submodule initialisation and update.
164git-2_submodules() { 165git-2_submodules() {
165 debug-print-function ${FUNCNAME} "$@" 166 debug-print-function ${FUNCNAME} "$@"
166 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then 167 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
167 if [[ -n ${EVCS_OFFLINE} ]]; then 168 if [[ ${EVCS_OFFLINE} ]]; then
168 # for submodules operations we need to be online 169 # for submodules operations we need to be online
169 debug-print "${FUNCNAME}: not updating submodules in offline mode" 170 debug-print "${FUNCNAME}: not updating submodules in offline mode"
170 return 1 171 return 1
171 fi 172 fi
172 173
214git-2_gc() { 215git-2_gc() {
215 debug-print-function ${FUNCNAME} "$@" 216 debug-print-function ${FUNCNAME} "$@"
216 217
217 local args 218 local args
218 219
220 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
219 pushd "${EGIT_DIR}" > /dev/null 221 pushd "${EGIT_DIR}" > /dev/null
220 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then
221 ebegin "Garbage collecting the repository" 222 ebegin "Garbage collecting the repository"
222 [[ -n ${EGIT_PRUNE} ]] && args='--prune' 223 [[ ${EGIT_PRUNE} ]] && args='--prune'
223 debug-print "${FUNCNAME}: git gc ${args}" 224 debug-print "${FUNCNAME}: git gc ${args}"
224 git gc ${args} 225 git gc ${args}
225 eend $? 226 eend $?
226 fi
227 popd > /dev/null 227 popd > /dev/null
228 fi
228} 229}
229 230
230# @FUNCTION: git-2_prepare_storedir 231# @FUNCTION: git-2_prepare_storedir
231# @DESCRIPTION: 232# @DESCRIPTION:
232# Internal function preparing directory where we are going to store SCM 233# Internal function preparing directory where we are going to store SCM
248 # allow writing into EGIT_STORE_DIR 249 # allow writing into EGIT_STORE_DIR
249 addwrite "${EGIT_STORE_DIR}" 250 addwrite "${EGIT_STORE_DIR}"
250 # calculate the proper store dir for data 251 # calculate the proper store dir for data
251 # If user didn't specify the EGIT_DIR, we check if he did specify 252 # If user didn't specify the EGIT_DIR, we check if he did specify
252 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. 253 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
253 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" 254 EGIT_REPO_URI=${EGIT_REPO_URI%/}
254 if [[ -z ${EGIT_DIR} ]]; then 255 if [[ ! ${EGIT_DIR} ]]; then
255 if [[ -n ${EGIT_PROJECT} ]]; then 256 if [[ ${EGIT_PROJECT} ]]; then
256 clone_dir=${EGIT_PROJECT} 257 clone_dir=${EGIT_PROJECT}
257 else 258 else
258 clone_dir=${EGIT_REPO_URI##*/} 259 clone_dir=${EGIT_REPO_URI##*/}
259 fi 260 fi
260 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 261 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
287 local repo_uri 288 local repo_uri
288 289
289 EGIT_REPO_URI_SELECTED="" 290 EGIT_REPO_URI_SELECTED=""
290 for repo_uri in ${EGIT_REPO_URI}; do 291 for repo_uri in ${EGIT_REPO_URI}; do
291 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 292 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
292 git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 293 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
293 if [[ $? -eq 0 ]]; then
294 # global variable containing the repo_name we will be using 294 # global variable containing the repo_name we will be using
295 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 295 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
296 EGIT_REPO_URI_SELECTED="${repo_uri}" 296 EGIT_REPO_URI_SELECTED="${repo_uri}"
297 break 297 break
298 fi 298 fi
299 done 299 done
300 300
301 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 301 [[ ${EGIT_REPO_URI_SELECTED} ]] \
302 die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 302 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
303 fi
304} 303}
305 304
306# @FUNCTION: git-2_update_repo 305# @FUNCTION: git-2_update_repo
307# @DESCRIPTION: 306# @DESCRIPTION:
308# Internal function running update command on specified repo_uri. 307# Internal function running update command on specified repo_uri.
309git-2_update_repo() { 308git-2_update_repo() {
310 debug-print-function ${FUNCNAME} "$@" 309 debug-print-function ${FUNCNAME} "$@"
311 310
312 local repo_uri 311 local repo_uri
313 312
314 if [[ -n ${EGIT_LOCAL_NONBARE} ]]; then 313 if [[ ${EGIT_LOCAL_NONBARE} ]]; then
315 # checkout master branch and drop all other local branches 314 # checkout master branch and drop all other local branches
316 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}" 315 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
317 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do 316 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
318 debug-print "${FUNCNAME}: git branch -D ${x}" 317 debug-print "${FUNCNAME}: git branch -D ${x}"
319 git branch -D ${x} > /dev/null 318 git branch -D ${x} > /dev/null
324 for repo_uri in ${EGIT_REPO_URI}; do 323 for repo_uri in ${EGIT_REPO_URI}; do
325 # git urls might change, so reset it 324 # git urls might change, so reset it
326 git config remote.origin.url "${repo_uri}" 325 git config remote.origin.url "${repo_uri}"
327 326
328 debug-print "${EGIT_UPDATE_CMD}" 327 debug-print "${EGIT_UPDATE_CMD}"
329 ${EGIT_UPDATE_CMD} > /dev/null 328 if ${EGIT_UPDATE_CMD} > /dev/null; then
330 if [[ $? -eq 0 ]]; then
331 # global variable containing the repo_name we will be using 329 # global variable containing the repo_name we will be using
332 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 330 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
333 EGIT_REPO_URI_SELECTED="${repo_uri}" 331 EGIT_REPO_URI_SELECTED="${repo_uri}"
334 break 332 break
335 fi 333 fi
336 done 334 done
337 335
338 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 336 [[ ${EGIT_REPO_URI_SELECTED} ]] \
339 die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 337 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
340 fi
341} 338}
342 339
343# @FUNCTION: git-2_fetch 340# @FUNCTION: git-2_fetch
344# @DESCRIPTION: 341# @DESCRIPTION:
345# Internal function fetching repository from EGIT_REPO_URI and storing it in 342# Internal function fetching repository from EGIT_REPO_URI and storing it in
347git-2_fetch() { 344git-2_fetch() {
348 debug-print-function ${FUNCNAME} "$@" 345 debug-print-function ${FUNCNAME} "$@"
349 346
350 local oldsha cursha repo_type 347 local oldsha cursha repo_type
351 348
352 [[ -n ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository" 349 [[ ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
353 350
354 if [[ ! -d ${EGIT_DIR} ]]; then 351 if [[ ! -d ${EGIT_DIR} ]]; then
355 git-2_initial_clone 352 git-2_initial_clone
356 pushd "${EGIT_DIR}" > /dev/null 353 pushd "${EGIT_DIR}" > /dev/null
357 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 354 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
358 echo "GIT NEW clone -->" 355 echo "GIT NEW clone -->"
359 echo " repository: ${EGIT_REPO_URI_SELECTED}" 356 echo " repository: ${EGIT_REPO_URI_SELECTED}"
360 echo " at the commit: ${cursha}" 357 echo " at the commit: ${cursha}"
361 358
362 popd > /dev/null 359 popd > /dev/null
363 elif [[ -n ${EVCS_OFFLINE} ]]; then 360 elif [[ ${EVCS_OFFLINE} ]]; then
364 pushd "${EGIT_DIR}" > /dev/null 361 pushd "${EGIT_DIR}" > /dev/null
365 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 362 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
366 echo "GIT offline update -->" 363 echo "GIT offline update -->"
367 echo " repository: $(git config remote.origin.url)" 364 echo " repository: $(git config remote.origin.url)"
368 echo " at the commit: ${cursha}" 365 echo " at the commit: ${cursha}"
409 # Command to be executed after checkout and clone of the specified 406 # Command to be executed after checkout and clone of the specified
410 # repository. 407 # repository.
411 # enviroment the package will fail if there is no update, thus in 408 # enviroment the package will fail if there is no update, thus in
412 # combination with --keep-going it would lead in not-updating 409 # combination with --keep-going it would lead in not-updating
413 # pakcages that are up-to-date. 410 # pakcages that are up-to-date.
414 if [[ -n ${EGIT_BOOTSTRAP} ]]; then 411 if [[ ${EGIT_BOOTSTRAP} ]]; then
415 pushd "${EGIT_SOURCEDIR}" > /dev/null 412 pushd "${EGIT_SOURCEDIR}" > /dev/null
416 einfo "Starting bootstrap" 413 einfo "Starting bootstrap"
417 414
418 if [[ -f ${EGIT_BOOTSTRAP} ]]; then 415 if [[ -f ${EGIT_BOOTSTRAP} ]]; then
419 # we have file in the repo which we should execute 416 # we have file in the repo which we should execute
448# This function also set some global variables that differ between 445# This function also set some global variables that differ between
449# bare and non-bare checkout. 446# bare and non-bare checkout.
450git-2_migrate_repository() { 447git-2_migrate_repository() {
451 debug-print-function ${FUNCNAME} "$@" 448 debug-print-function ${FUNCNAME} "$@"
452 449
453 local target returnstate 450 local bare returnstate
454 451
455 # first find out if we have submodules 452 # first find out if we have submodules
453 # or user explicitly wants us to use non-bare clones
456 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 454 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
457 target="bare" 455 bare=1
458 else
459 target="full"
460 fi
461 # check if user didn't specify that we want non-bare repo
462 if [[ -n ${EGIT_NONBARE} ]]; then
463 target="full"
464 EGIT_LOCAL_NONBARE="true"
465 fi 456 fi
466 457
467 # test if we already have some repo and if so find out if we have 458 # test if we already have some repo and if so find out if we have
468 # to migrate the data 459 # to migrate the data
469 if [[ -d ${EGIT_DIR} ]]; then 460 if [[ -d ${EGIT_DIR} ]]; then
470 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 461 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
471 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 462 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
472 463
473 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 464 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
474 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 465 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
475 export GIT_DIR="${EGIT_DIR}.bare" 466 export GIT_DIR="${EGIT_DIR}.bare"
477 returnstate=$? 468 returnstate=$?
478 unset GIT_DIR 469 unset GIT_DIR
479 rm -rf "${EGIT_DIR}" 470 rm -rf "${EGIT_DIR}"
480 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 471 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
481 eend ${returnstate} 472 eend ${returnstate}
482 fi
483 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 473 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
484 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 474 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
485 475
486 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 476 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
487 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 477 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
488 returnstate=$? 478 returnstate=$?
498 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 488 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
499 rm -rf "${EGIT_DIR}" 489 rm -rf "${EGIT_DIR}"
500 fi 490 fi
501 491
502 # set various options to work with both targets 492 # set various options to work with both targets
503 if [[ ${target} == bare ]]; then 493 if [[ ${bare} ]]; then
504 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 494 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
505 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" 495 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
506 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 496 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
507 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 497 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
508 UPSTREAM_BRANCH="${EGIT_BRANCH}" 498 UPSTREAM_BRANCH="${EGIT_BRANCH}"
554 git-2_cleanup 544 git-2_cleanup
555 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 545 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
556 546
557 # Users can specify some SRC_URI and we should 547 # Users can specify some SRC_URI and we should
558 # unpack the files too. 548 # unpack the files too.
559 if [[ -z ${EGIT_NOUNPACK} ]]; then 549 if [[ ! ${EGIT_NOUNPACK} ]]; then
560 if has ${EAPI:-0} 0 1; then 550 if has ${EAPI:-0} 0 1; then
561 [[ -n ${A} ]] && unpack ${A} 551 [[ ${A} ]] && unpack ${A}
562 else 552 else
563 default_src_unpack 553 default_src_unpack
564 fi 554 fi
565 fi 555 fi
566} 556}

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.20