/[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.18 Revision 1.23
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.18 2011/09/23 13:57:28 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.23 2011/09/23 13:58:35 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.
118# @DESCRIPTION: 118# @DESCRIPTION:
119# If non-empty this variable bans unpacking of ${A} content into the srcdir. 119# If non-empty this variable bans unpacking of ${A} content into the srcdir.
120# Default behaviour is to unpack ${A} content. 120# Default behaviour is to unpack ${A} content.
121 121
122# @FUNCTION: git-2_init_variables 122# @FUNCTION: git-2_init_variables
123# @INTERNAL
123# @DESCRIPTION: 124# @DESCRIPTION:
124# Internal function initializing all git variables. 125# Internal function initializing all git variables.
125# We define it in function scope so user can define 126# We define it in function scope so user can define
126# all the variables before and after inherit. 127# all the variables before and after inherit.
127git-2_init_variables() { 128git-2_init_variables() {
158 159
159 : ${EGIT_PRUNE:=} 160 : ${EGIT_PRUNE:=}
160} 161}
161 162
162# @FUNCTION: git-2_submodules 163# @FUNCTION: git-2_submodules
164# @INTERNAL
163# @DESCRIPTION: 165# @DESCRIPTION:
164# Internal function wrapping the submodule initialisation and update. 166# Internal function wrapping the submodule initialisation and update.
165git-2_submodules() { 167git-2_submodules() {
166 debug-print-function ${FUNCNAME} "$@" 168 debug-print-function ${FUNCNAME} "$@"
167 if [[ ${EGIT_HAS_SUBMODULES} ]]; then 169 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
184 popd > /dev/null 186 popd > /dev/null
185 fi 187 fi
186} 188}
187 189
188# @FUNCTION: git-2_branch 190# @FUNCTION: git-2_branch
191# @INTERNAL
189# @DESCRIPTION: 192# @DESCRIPTION:
190# Internal function that changes branch for the repo based on EGIT_COMMIT and 193# Internal function that changes branch for the repo based on EGIT_COMMIT and
191# EGIT_BRANCH variables. 194# EGIT_BRANCH variables.
192git-2_branch() { 195git-2_branch() {
193 debug-print-function ${FUNCNAME} "$@" 196 debug-print-function ${FUNCNAME} "$@"
208 211
209 popd > /dev/null 212 popd > /dev/null
210} 213}
211 214
212# @FUNCTION: git-2_gc 215# @FUNCTION: git-2_gc
216# @INTERNAL
213# @DESCRIPTION: 217# @DESCRIPTION:
214# Internal function running garbage collector on checked out tree. 218# Internal function running garbage collector on checked out tree.
215git-2_gc() { 219git-2_gc() {
216 debug-print-function ${FUNCNAME} "$@" 220 debug-print-function ${FUNCNAME} "$@"
217 221
218 local args 222 local args
219 223
220 pushd "${EGIT_DIR}" > /dev/null
221 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then 224 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
225 pushd "${EGIT_DIR}" > /dev/null
222 ebegin "Garbage collecting the repository" 226 ebegin "Garbage collecting the repository"
223 [[ ${EGIT_PRUNE} ]] && args='--prune' 227 [[ ${EGIT_PRUNE} ]] && args='--prune'
224 debug-print "${FUNCNAME}: git gc ${args}" 228 debug-print "${FUNCNAME}: git gc ${args}"
225 git gc ${args} 229 git gc ${args}
226 eend $? 230 eend $?
227 fi
228 popd > /dev/null 231 popd > /dev/null
232 fi
229} 233}
230 234
231# @FUNCTION: git-2_prepare_storedir 235# @FUNCTION: git-2_prepare_storedir
236# @INTERNAL
232# @DESCRIPTION: 237# @DESCRIPTION:
233# Internal function preparing directory where we are going to store SCM 238# Internal function preparing directory where we are going to store SCM
234# repository. 239# repository.
235git-2_prepare_storedir() { 240git-2_prepare_storedir() {
236 debug-print-function ${FUNCNAME} "$@" 241 debug-print-function ${FUNCNAME} "$@"
263 export EGIT_DIR=${EGIT_DIR} 268 export EGIT_DIR=${EGIT_DIR}
264 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 269 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
265} 270}
266 271
267# @FUNCTION: git-2_move_source 272# @FUNCTION: git-2_move_source
273# @INTERNAL
268# @DESCRIPTION: 274# @DESCRIPTION:
269# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 275# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
270git-2_move_source() { 276git-2_move_source() {
271 debug-print-function ${FUNCNAME} "$@" 277 debug-print-function ${FUNCNAME} "$@"
272 278
278 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 284 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
279 popd > /dev/null 285 popd > /dev/null
280} 286}
281 287
282# @FUNCTION: git-2_initial_clone 288# @FUNCTION: git-2_initial_clone
289# @INTERNAL
283# @DESCRIPTION: 290# @DESCRIPTION:
284# Internal function running initial clone on specified repo_uri. 291# Internal function running initial clone on specified repo_uri.
285git-2_initial_clone() { 292git-2_initial_clone() {
286 debug-print-function ${FUNCNAME} "$@" 293 debug-print-function ${FUNCNAME} "$@"
287 294
301 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 308 [[ ${EGIT_REPO_URI_SELECTED} ]] \
302 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 309 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
303} 310}
304 311
305# @FUNCTION: git-2_update_repo 312# @FUNCTION: git-2_update_repo
313# @INTERNAL
306# @DESCRIPTION: 314# @DESCRIPTION:
307# Internal function running update command on specified repo_uri. 315# Internal function running update command on specified repo_uri.
308git-2_update_repo() { 316git-2_update_repo() {
309 debug-print-function ${FUNCNAME} "$@" 317 debug-print-function ${FUNCNAME} "$@"
310 318
336 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 344 [[ ${EGIT_REPO_URI_SELECTED} ]] \
337 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 345 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
338} 346}
339 347
340# @FUNCTION: git-2_fetch 348# @FUNCTION: git-2_fetch
349# @INTERNAL
341# @DESCRIPTION: 350# @DESCRIPTION:
342# Internal function fetching repository from EGIT_REPO_URI and storing it in 351# Internal function fetching repository from EGIT_REPO_URI and storing it in
343# specified EGIT_STORE_DIR. 352# specified EGIT_STORE_DIR.
344git-2_fetch() { 353git-2_fetch() {
345 debug-print-function ${FUNCNAME} "$@" 354 debug-print-function ${FUNCNAME} "$@"
394 echo " storage directory: \"${EGIT_DIR}\"" 403 echo " storage directory: \"${EGIT_DIR}\""
395 echo " checkout type: ${repo_type}" 404 echo " checkout type: ${repo_type}"
396} 405}
397 406
398# @FUNCTION: git_bootstrap 407# @FUNCTION: git_bootstrap
408# @INTERNAL
399# @DESCRIPTION: 409# @DESCRIPTION:
400# Internal function that runs bootstrap command on unpacked source. 410# Internal function that runs bootstrap command on unpacked source.
401git-2_bootstrap() { 411git-2_bootstrap() {
402 debug-print-function ${FUNCNAME} "$@" 412 debug-print-function ${FUNCNAME} "$@"
403 413
436 popd > /dev/null 446 popd > /dev/null
437 fi 447 fi
438} 448}
439 449
440# @FUNCTION: git-2_migrate_repository 450# @FUNCTION: git-2_migrate_repository
451# @INTERNAL
441# @DESCRIPTION: 452# @DESCRIPTION:
442# Internal function migrating between bare and normal checkout repository. 453# Internal function migrating between bare and normal checkout repository.
443# This is based on usage of EGIT_SUBMODULES, at least until they 454# This is based on usage of EGIT_SUBMODULES, at least until they
444# start to work with bare checkouts sanely. 455# start to work with bare checkouts sanely.
445# This function also set some global variables that differ between 456# This function also set some global variables that differ between
446# bare and non-bare checkout. 457# bare and non-bare checkout.
447git-2_migrate_repository() { 458git-2_migrate_repository() {
448 debug-print-function ${FUNCNAME} "$@" 459 debug-print-function ${FUNCNAME} "$@"
449 460
450 local target returnstate 461 local bare returnstate
451 462
452 # first find out if we have submodules 463 # first find out if we have submodules
464 # or user explicitly wants us to use non-bare clones
453 if [[ ! ${EGIT_HAS_SUBMODULES} ]]; then 465 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
454 target="bare" 466 bare=1
455 else
456 target="full"
457 fi
458 # check if user didn't specify that we want non-bare repo
459 if [[ ${EGIT_NONBARE} ]]; then
460 target="full"
461 EGIT_LOCAL_NONBARE="true"
462 fi 467 fi
463 468
464 # test if we already have some repo and if so find out if we have 469 # test if we already have some repo and if so find out if we have
465 # to migrate the data 470 # to migrate the data
466 if [[ -d ${EGIT_DIR} ]]; then 471 if [[ -d ${EGIT_DIR} ]]; then
467 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 472 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
468 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 473 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
469 474
470 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 475 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
471 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 476 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
472 export GIT_DIR="${EGIT_DIR}.bare" 477 export GIT_DIR="${EGIT_DIR}.bare"
474 returnstate=$? 479 returnstate=$?
475 unset GIT_DIR 480 unset GIT_DIR
476 rm -rf "${EGIT_DIR}" 481 rm -rf "${EGIT_DIR}"
477 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 482 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
478 eend ${returnstate} 483 eend ${returnstate}
479 fi
480 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 484 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
481 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 485 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
482 486
483 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 487 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
484 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 488 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
485 returnstate=$? 489 returnstate=$?
495 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 499 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
496 rm -rf "${EGIT_DIR}" 500 rm -rf "${EGIT_DIR}"
497 fi 501 fi
498 502
499 # set various options to work with both targets 503 # set various options to work with both targets
500 if [[ ${target} == bare ]]; then 504 if [[ ${bare} ]]; then
501 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 505 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
502 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" 506 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
503 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 507 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
504 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 508 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
505 UPSTREAM_BRANCH="${EGIT_BRANCH}" 509 UPSTREAM_BRANCH="${EGIT_BRANCH}"
510 EGIT_LOCAL_NONBARE=
506 else 511 else
507 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 512 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
508 MOVE_COMMAND="cp -pPR ." 513 MOVE_COMMAND="cp -pPR ."
509 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}" 514 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
510 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 515 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
512 EGIT_LOCAL_NONBARE="true" 517 EGIT_LOCAL_NONBARE="true"
513 fi 518 fi
514} 519}
515 520
516# @FUNCTION: git-2_cleanup 521# @FUNCTION: git-2_cleanup
522# @INTERNAL
517# @DESCRIPTION: 523# @DESCRIPTION:
518# Internal function cleaning up all the global variables 524# Internal function cleaning up all the global variables
519# that are not required after the unpack has been done. 525# that are not required after the unpack has been done.
520git-2_cleanup() { 526git-2_cleanup() {
521 debug-print-function ${FUNCNAME} "$@" 527 debug-print-function ${FUNCNAME} "$@"

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.20