/[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.12 Revision 1.13
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.12 2011/07/16 13:11:54 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.13 2011/07/30 15:10:34 scarabeus 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.
55# EGIT_PROJECT="${EGIT_REPO_URI##*/}" 55# EGIT_PROJECT="${EGIT_REPO_URI##*/}"
56 56
57# @ECLASS-VARIABLE: EGIT_DIR 57# @ECLASS-VARIABLE: EGIT_DIR
58# @DESCRIPTION: 58# @DESCRIPTION:
59# Directory where we want to store the git data. 59# Directory where we want to store the git data.
60# This should not be overriden unless really required. 60# This variable should not be overriden.
61# 61#
62# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}" 62# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
63 63
64# @ECLASS-VARIABLE: EGIT_REPO_URI 64# @ECLASS-VARIABLE: EGIT_REPO_URI
65# @REQUIRED 65# @REQUIRED
110# @DEFAULT_UNSET 110# @DEFAULT_UNSET
111# @DESCRIPTION: 111# @DESCRIPTION:
112# If non-empty this variable specifies that all checkouts will be done using 112# If non-empty this variable specifies that all checkouts will be done using
113# non bare repositories. This is useful if you can't operate with bare 113# non bare repositories. This is useful if you can't operate with bare
114# checkouts for some reason. 114# checkouts for some reason.
115
116# @ECLASS-VARIABLE: EGIT_NOUNPACK
117# @DEFAULT_UNSET
118# @DESCRIPTION:
119# If non-empty this variable bans unpacking of ${A} content into the srcdir.
120# Default behaviour is to unpack ${A} content.
115 121
116# @FUNCTION: git-2_init_variables 122# @FUNCTION: git-2_init_variables
117# @DESCRIPTION: 123# @DESCRIPTION:
118# Internal function initializing all git variables. 124# Internal function initializing all git variables.
119# We define it in function scope so user can define 125# We define it in function scope so user can define
183# Internal function that changes branch for the repo based on EGIT_COMMIT and 189# Internal function that changes branch for the repo based on EGIT_COMMIT and
184# EGIT_BRANCH variables. 190# EGIT_BRANCH variables.
185git-2_branch() { 191git-2_branch() {
186 debug-print-function ${FUNCNAME} "$@" 192 debug-print-function ${FUNCNAME} "$@"
187 193
194 local branchname src
195
188 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" 196 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\""
189 pushd "${EGIT_SOURCEDIR}" > /dev/null 197 pushd "${EGIT_SOURCEDIR}" > /dev/null
190 198
191 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} 199 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
192 if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then 200 if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then
196 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" 204 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}"
197 git checkout -b ${branchname} ${src} \ 205 git checkout -b ${branchname} ${src} \
198 || die "${FUNCNAME}: changing the branch failed" 206 || die "${FUNCNAME}: changing the branch failed"
199 207
200 popd > /dev/null 208 popd > /dev/null
201
202 unset branchname src
203} 209}
204 210
205# @FUNCTION: git-2_gc 211# @FUNCTION: git-2_gc
206# @DESCRIPTION: 212# @DESCRIPTION:
207# Internal function running garbage collector on checked out tree. 213# Internal function running garbage collector on checked out tree.
208git-2_gc() { 214git-2_gc() {
209 debug-print-function ${FUNCNAME} "$@" 215 debug-print-function ${FUNCNAME} "$@"
216
217 local args
210 218
211 pushd "${EGIT_DIR}" > /dev/null 219 pushd "${EGIT_DIR}" > /dev/null
212 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then 220 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then
213 ebegin "Garbage collecting the repository" 221 ebegin "Garbage collecting the repository"
214 local args
215 [[ -n ${EGIT_PRUNE} ]] && args='--prune' 222 [[ -n ${EGIT_PRUNE} ]] && args='--prune'
216 debug-print "${FUNCNAME}: git gc ${args}" 223 debug-print "${FUNCNAME}: git gc ${args}"
217 git gc ${args} 224 git gc ${args}
218 eend $? 225 eend $?
219 fi 226 fi
279 286
280 local repo_uri 287 local repo_uri
281 288
282 EGIT_REPO_URI_SELECTED="" 289 EGIT_REPO_URI_SELECTED=""
283 for repo_uri in ${EGIT_REPO_URI}; do 290 for repo_uri in ${EGIT_REPO_URI}; do
284 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 291 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
285 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 292 git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"
286 if [[ $? -eq 0 ]]; then 293 if [[ $? -eq 0 ]]; then
287 # global variable containing the repo_name we will be using 294 # global variable containing the repo_name we will be using
288 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 295 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
289 EGIT_REPO_URI_SELECTED="${repo_uri}" 296 EGIT_REPO_URI_SELECTED="${repo_uri}"
290 break 297 break
302git-2_update_repo() { 309git-2_update_repo() {
303 debug-print-function ${FUNCNAME} "$@" 310 debug-print-function ${FUNCNAME} "$@"
304 311
305 local repo_uri 312 local repo_uri
306 313
307 if [[ -n ${EGIT_NONBARE} ]]; then 314 if [[ -n ${EGIT_LOCAL_NONBARE} ]]; then
308 # checkout master branch and drop all other local branches 315 # checkout master branch and drop all other local branches
309 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}" 316 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
310 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do 317 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
311 debug-print "${FUNCNAME}: git branch -D ${x}" 318 debug-print "${FUNCNAME}: git branch -D ${x}"
312 git branch -D ${x} > /dev/null 319 git branch -D ${x} > /dev/null
340git-2_fetch() { 347git-2_fetch() {
341 debug-print-function ${FUNCNAME} "$@" 348 debug-print-function ${FUNCNAME} "$@"
342 349
343 local oldsha cursha repo_type 350 local oldsha cursha repo_type
344 351
345 [[ -n ${EGIT_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository" 352 [[ -n ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
346 353
347 if [[ ! -d ${EGIT_DIR} ]]; then 354 if [[ ! -d ${EGIT_DIR} ]]; then
348 git-2_initial_clone 355 git-2_initial_clone
349 pushd "${EGIT_DIR}" > /dev/null 356 pushd "${EGIT_DIR}" > /dev/null
350 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 357 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
436# @FUNCTION: git-2_migrate_repository 443# @FUNCTION: git-2_migrate_repository
437# @DESCRIPTION: 444# @DESCRIPTION:
438# Internal function migrating between bare and normal checkout repository. 445# Internal function migrating between bare and normal checkout repository.
439# This is based on usage of EGIT_SUBMODULES, at least until they 446# This is based on usage of EGIT_SUBMODULES, at least until they
440# start to work with bare checkouts sanely. 447# start to work with bare checkouts sanely.
448# This function also set some global variables that differ between
449# bare and non-bare checkout.
441git-2_migrate_repository() { 450git-2_migrate_repository() {
442 debug-print-function ${FUNCNAME} "$@" 451 debug-print-function ${FUNCNAME} "$@"
443 452
444 local target returnstate 453 local target returnstate
445 454
447 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 456 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then
448 target="bare" 457 target="bare"
449 else 458 else
450 target="full" 459 target="full"
451 fi 460 fi
452 [[ -n ${EGIT_NONBARE} ]] && target="full" 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
453 466
454 # test if we already have some repo and if so find out if we have 467 # test if we already have some repo and if so find out if we have
455 # to migrate the data 468 # to migrate the data
456 if [[ -d ${EGIT_DIR} ]]; then 469 if [[ -d ${EGIT_DIR} ]]; then
457 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 470 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then
487 fi 500 fi
488 501
489 # set various options to work with both targets 502 # set various options to work with both targets
490 if [[ ${target} == bare ]]; then 503 if [[ ${target} == bare ]]; then
491 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 504 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
492 EGIT_OPTIONS+=" --bare" 505 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
493 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 506 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
494 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 507 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
495 UPSTREAM_BRANCH="${EGIT_BRANCH}" 508 UPSTREAM_BRANCH="${EGIT_BRANCH}"
496 else 509 else
497 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 510 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
498 MOVE_COMMAND="cp -pPR ." 511 MOVE_COMMAND="cp -pPR ."
512 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
499 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 513 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
500 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 514 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
501 EGIT_NONBARE="true" 515 EGIT_LOCAL_NONBARE="true"
502 fi 516 fi
517}
518
519# @FUNCTION: git-2_cleanup
520# @DESCRIPTION:
521# Internal function cleaning up all the global variables
522# that are not required after the unpack has been done.
523git-2_cleanup() {
524 debug-print-function ${FUNCNAME} "$@"
525
526 # Here we can unset only variables that are GLOBAL
527 # defined by the eclass, BUT NOT subject to change
528 # by user (like EGIT_PROJECT).
529 # If ebuild writer polutes his environment it is
530 # his problem only.
531 unset EGIT_DIR
532 unset MOVE_COMMAND
533 unset EGIT_LOCAL_OPTIONS
534 unset EGIT_UPDATE_CMD
535 unset UPSTREAM_BRANCH
536 unset EGIT_LOCAL_NONBARE
503} 537}
504 538
505# @FUNCTION: git-2_src_unpack 539# @FUNCTION: git-2_src_unpack
506# @DESCRIPTION: 540# @DESCRIPTION:
507# Default git src_unpack function. 541# Default git src_unpack function.
515 git-2_gc 549 git-2_gc
516 git-2_submodules 550 git-2_submodules
517 git-2_move_source 551 git-2_move_source
518 git-2_branch 552 git-2_branch
519 git-2_bootstrap 553 git-2_bootstrap
554 git-2_cleanup
520 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 555 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
521 556
522 # Users can specify some SRC_URI and we should 557 # Users can specify some SRC_URI and we should
523 # unpack the files too. 558 # unpack the files too.
559 if [[ -z ${EGIT_NOUNPACK} ]]; then
524 if has ${EAPI:-0} 0 1; then 560 if has ${EAPI:-0} 0 1; then
525 [[ -n ${A} ]] && unpack ${A} 561 [[ -n ${A} ]] && unpack ${A}
526 else 562 else
527 default_src_unpack 563 default_src_unpack
528 fi 564 fi
565 fi
529} 566}

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.20