/[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.21 Revision 1.29
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2012 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.21 2011/09/23 13:58:09 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.29 2012/04/03 10:32:09 pacho Exp $
4 4
5# @ECLASS: git-2.eclass 5# @ECLASS: git-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Michał Górny <mgorny@gentoo.org>
7# Donnie Berkholz <dberkholz@gentoo.org> 8# Donnie Berkholz <dberkholz@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 9# @BLURB: Eclass for fetching and unpacking git repositories.
9# @DESCRIPTION: 10# @DESCRIPTION:
10# Eclass for easing maitenance of live ebuilds using git as remote repository. 11# Eclass for easing maitenance of live ebuilds using git as remote repository.
11# Eclass support working with git submodules and branching. 12# Eclass support working with git submodules and branching.
118# @DESCRIPTION: 119# @DESCRIPTION:
119# If non-empty this variable bans unpacking of ${A} content into the srcdir. 120# If non-empty this variable bans unpacking of ${A} content into the srcdir.
120# Default behaviour is to unpack ${A} content. 121# Default behaviour is to unpack ${A} content.
121 122
122# @FUNCTION: git-2_init_variables 123# @FUNCTION: git-2_init_variables
124# @INTERNAL
123# @DESCRIPTION: 125# @DESCRIPTION:
124# Internal function initializing all git variables. 126# Internal function initializing all git variables.
125# We define it in function scope so user can define 127# We define it in function scope so user can define
126# all the variables before and after inherit. 128# all the variables before and after inherit.
127git-2_init_variables() { 129git-2_init_variables() {
158 160
159 : ${EGIT_PRUNE:=} 161 : ${EGIT_PRUNE:=}
160} 162}
161 163
162# @FUNCTION: git-2_submodules 164# @FUNCTION: git-2_submodules
165# @INTERNAL
163# @DESCRIPTION: 166# @DESCRIPTION:
164# Internal function wrapping the submodule initialisation and update. 167# Internal function wrapping the submodule initialisation and update.
165git-2_submodules() { 168git-2_submodules() {
166 debug-print-function ${FUNCNAME} "$@" 169 debug-print-function ${FUNCNAME} "$@"
167 if [[ ${EGIT_HAS_SUBMODULES} ]]; then 170 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
184 popd > /dev/null 187 popd > /dev/null
185 fi 188 fi
186} 189}
187 190
188# @FUNCTION: git-2_branch 191# @FUNCTION: git-2_branch
192# @INTERNAL
189# @DESCRIPTION: 193# @DESCRIPTION:
190# Internal function that changes branch for the repo based on EGIT_COMMIT and 194# Internal function that changes branch for the repo based on EGIT_COMMIT and
191# EGIT_BRANCH variables. 195# EGIT_BRANCH variables.
192git-2_branch() { 196git-2_branch() {
193 debug-print-function ${FUNCNAME} "$@" 197 debug-print-function ${FUNCNAME} "$@"
208 212
209 popd > /dev/null 213 popd > /dev/null
210} 214}
211 215
212# @FUNCTION: git-2_gc 216# @FUNCTION: git-2_gc
217# @INTERNAL
213# @DESCRIPTION: 218# @DESCRIPTION:
214# Internal function running garbage collector on checked out tree. 219# Internal function running garbage collector on checked out tree.
215git-2_gc() { 220git-2_gc() {
216 debug-print-function ${FUNCNAME} "$@" 221 debug-print-function ${FUNCNAME} "$@"
217 222
227 popd > /dev/null 232 popd > /dev/null
228 fi 233 fi
229} 234}
230 235
231# @FUNCTION: git-2_prepare_storedir 236# @FUNCTION: git-2_prepare_storedir
237# @INTERNAL
232# @DESCRIPTION: 238# @DESCRIPTION:
233# Internal function preparing directory where we are going to store SCM 239# Internal function preparing directory where we are going to store SCM
234# repository. 240# repository.
235git-2_prepare_storedir() { 241git-2_prepare_storedir() {
236 debug-print-function ${FUNCNAME} "$@" 242 debug-print-function ${FUNCNAME} "$@"
240 # initial clone, we have to create master git storage directory and play 246 # initial clone, we have to create master git storage directory and play
241 # nicely with sandbox 247 # nicely with sandbox
242 if [[ ! -d ${EGIT_STORE_DIR} ]]; then 248 if [[ ! -d ${EGIT_STORE_DIR} ]]; then
243 debug-print "${FUNCNAME}: Creating git main storage directory" 249 debug-print "${FUNCNAME}: Creating git main storage directory"
244 addwrite / 250 addwrite /
245 mkdir -p "${EGIT_STORE_DIR}" \ 251 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
246 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 252 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
247 fi 253 fi
248 254
249 # allow writing into EGIT_STORE_DIR 255 # allow writing into EGIT_STORE_DIR
250 addwrite "${EGIT_STORE_DIR}" 256 addwrite "${EGIT_STORE_DIR}"
257
258 # calculate git.eclass store dir for data
259 # We will try to clone the old repository,
260 # and we will remove it if we don't need it anymore.
261 EGIT_OLD_CLONE=
262 if [[ ${EGIT_STORE_DIR} == */egit-src ]]; then
263 local old_store_dir=${EGIT_STORE_DIR/%egit-src/git-src}
264 local old_location=${old_store_dir}/${EGIT_PROJECT:-${PN}}
265
266 if [[ -d ${old_location} ]]; then
267 EGIT_OLD_CLONE=${old_location}
268 # required to remove the old clone
269 addwrite "${old_store_dir}"
270 fi
271 fi
272
251 # calculate the proper store dir for data 273 # calculate the proper store dir for data
252 # If user didn't specify the EGIT_DIR, we check if he did specify 274 # If user didn't specify the EGIT_DIR, we check if he did specify
253 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. 275 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
254 EGIT_REPO_URI=${EGIT_REPO_URI%/} 276 EGIT_REPO_URI=${EGIT_REPO_URI%/}
255 if [[ ! ${EGIT_DIR} ]]; then 277 if [[ ! ${EGIT_DIR} ]]; then
256 if [[ ${EGIT_PROJECT} ]]; then 278 if [[ ${EGIT_PROJECT} ]]; then
257 clone_dir=${EGIT_PROJECT} 279 clone_dir=${EGIT_PROJECT}
258 else 280 else
259 clone_dir=${EGIT_REPO_URI##*/} 281 local strippeduri=${EGIT_REPO_URI%/.git}
282 clone_dir=${strippeduri##*/}
260 fi 283 fi
261 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 284 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
285
286 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
287 elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
288 elog "It will be necessary to rebuild the package to fetch updates."
289 EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
290 fi
262 fi 291 fi
263 export EGIT_DIR=${EGIT_DIR} 292 export EGIT_DIR=${EGIT_DIR}
264 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 293 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
265} 294}
266 295
267# @FUNCTION: git-2_move_source 296# @FUNCTION: git-2_move_source
297# @INTERNAL
268# @DESCRIPTION: 298# @DESCRIPTION:
269# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 299# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
270git-2_move_source() { 300git-2_move_source() {
271 debug-print-function ${FUNCNAME} "$@" 301 debug-print-function ${FUNCNAME} "$@"
272 302
278 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 308 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
279 popd > /dev/null 309 popd > /dev/null
280} 310}
281 311
282# @FUNCTION: git-2_initial_clone 312# @FUNCTION: git-2_initial_clone
313# @INTERNAL
283# @DESCRIPTION: 314# @DESCRIPTION:
284# Internal function running initial clone on specified repo_uri. 315# Internal function running initial clone on specified repo_uri.
285git-2_initial_clone() { 316git-2_initial_clone() {
286 debug-print-function ${FUNCNAME} "$@" 317 debug-print-function ${FUNCNAME} "$@"
287 318
301 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 332 [[ ${EGIT_REPO_URI_SELECTED} ]] \
302 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 333 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
303} 334}
304 335
305# @FUNCTION: git-2_update_repo 336# @FUNCTION: git-2_update_repo
337# @INTERNAL
306# @DESCRIPTION: 338# @DESCRIPTION:
307# Internal function running update command on specified repo_uri. 339# Internal function running update command on specified repo_uri.
308git-2_update_repo() { 340git-2_update_repo() {
309 debug-print-function ${FUNCNAME} "$@" 341 debug-print-function ${FUNCNAME} "$@"
310 342
336 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 368 [[ ${EGIT_REPO_URI_SELECTED} ]] \
337 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 369 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
338} 370}
339 371
340# @FUNCTION: git-2_fetch 372# @FUNCTION: git-2_fetch
373# @INTERNAL
341# @DESCRIPTION: 374# @DESCRIPTION:
342# Internal function fetching repository from EGIT_REPO_URI and storing it in 375# Internal function fetching repository from EGIT_REPO_URI and storing it in
343# specified EGIT_STORE_DIR. 376# specified EGIT_STORE_DIR.
344git-2_fetch() { 377git-2_fetch() {
345 debug-print-function ${FUNCNAME} "$@" 378 debug-print-function ${FUNCNAME} "$@"
391 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \ 424 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
392 && echo " commit: ${EGIT_COMMIT}" 425 && echo " commit: ${EGIT_COMMIT}"
393 echo " branch: ${EGIT_BRANCH}" 426 echo " branch: ${EGIT_BRANCH}"
394 echo " storage directory: \"${EGIT_DIR}\"" 427 echo " storage directory: \"${EGIT_DIR}\""
395 echo " checkout type: ${repo_type}" 428 echo " checkout type: ${repo_type}"
429
430 # Cleanup after git.eclass
431 if [[ ${EGIT_OLD_CLONE} ]]; then
432 einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
433 rm -rf "${EGIT_OLD_CLONE}"
434 fi
396} 435}
397 436
398# @FUNCTION: git_bootstrap 437# @FUNCTION: git_bootstrap
438# @INTERNAL
399# @DESCRIPTION: 439# @DESCRIPTION:
400# Internal function that runs bootstrap command on unpacked source. 440# Internal function that runs bootstrap command on unpacked source.
401git-2_bootstrap() { 441git-2_bootstrap() {
402 debug-print-function ${FUNCNAME} "$@" 442 debug-print-function ${FUNCNAME} "$@"
403 443
436 popd > /dev/null 476 popd > /dev/null
437 fi 477 fi
438} 478}
439 479
440# @FUNCTION: git-2_migrate_repository 480# @FUNCTION: git-2_migrate_repository
481# @INTERNAL
441# @DESCRIPTION: 482# @DESCRIPTION:
442# Internal function migrating between bare and normal checkout repository. 483# Internal function migrating between bare and normal checkout repository.
443# This is based on usage of EGIT_SUBMODULES, at least until they 484# This is based on usage of EGIT_SUBMODULES, at least until they
444# start to work with bare checkouts sanely. 485# start to work with bare checkouts sanely.
445# This function also set some global variables that differ between 486# This function also set some global variables that differ between
494 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 535 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
495 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" 536 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
496 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 537 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
497 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 538 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
498 UPSTREAM_BRANCH="${EGIT_BRANCH}" 539 UPSTREAM_BRANCH="${EGIT_BRANCH}"
540 EGIT_LOCAL_NONBARE=
499 else 541 else
500 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 542 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
501 MOVE_COMMAND="cp -pPR ." 543 MOVE_COMMAND="cp -pPR ."
502 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}" 544 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
503 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 545 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
505 EGIT_LOCAL_NONBARE="true" 547 EGIT_LOCAL_NONBARE="true"
506 fi 548 fi
507} 549}
508 550
509# @FUNCTION: git-2_cleanup 551# @FUNCTION: git-2_cleanup
552# @INTERNAL
510# @DESCRIPTION: 553# @DESCRIPTION:
511# Internal function cleaning up all the global variables 554# Internal function cleaning up all the global variables
512# that are not required after the unpack has been done. 555# that are not required after the unpack has been done.
513git-2_cleanup() { 556git-2_cleanup() {
514 debug-print-function ${FUNCNAME} "$@" 557 debug-print-function ${FUNCNAME} "$@"

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

  ViewVC Help
Powered by ViewVC 1.1.20