/[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.27
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.21 2011/09/23 13:58:09 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.27 2011/12/14 23:40:18 vapier 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# Michał Górny <mgorny@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.
12 13
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
257 clone_dir=${EGIT_PROJECT} 279 clone_dir=${EGIT_PROJECT}
258 else 280 else
259 clone_dir=${EGIT_REPO_URI##*/} 281 clone_dir=${EGIT_REPO_URI##*/}
260 fi 282 fi
261 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 283 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
284
285 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
286 elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
287 elog "It will be necessary to rebuild the package to fetch updates."
288 EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
289 fi
262 fi 290 fi
263 export EGIT_DIR=${EGIT_DIR} 291 export EGIT_DIR=${EGIT_DIR}
264 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 292 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
265} 293}
266 294
267# @FUNCTION: git-2_move_source 295# @FUNCTION: git-2_move_source
296# @INTERNAL
268# @DESCRIPTION: 297# @DESCRIPTION:
269# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 298# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
270git-2_move_source() { 299git-2_move_source() {
271 debug-print-function ${FUNCNAME} "$@" 300 debug-print-function ${FUNCNAME} "$@"
272 301
278 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 307 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
279 popd > /dev/null 308 popd > /dev/null
280} 309}
281 310
282# @FUNCTION: git-2_initial_clone 311# @FUNCTION: git-2_initial_clone
312# @INTERNAL
283# @DESCRIPTION: 313# @DESCRIPTION:
284# Internal function running initial clone on specified repo_uri. 314# Internal function running initial clone on specified repo_uri.
285git-2_initial_clone() { 315git-2_initial_clone() {
286 debug-print-function ${FUNCNAME} "$@" 316 debug-print-function ${FUNCNAME} "$@"
287 317
301 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 331 [[ ${EGIT_REPO_URI_SELECTED} ]] \
302 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 332 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
303} 333}
304 334
305# @FUNCTION: git-2_update_repo 335# @FUNCTION: git-2_update_repo
336# @INTERNAL
306# @DESCRIPTION: 337# @DESCRIPTION:
307# Internal function running update command on specified repo_uri. 338# Internal function running update command on specified repo_uri.
308git-2_update_repo() { 339git-2_update_repo() {
309 debug-print-function ${FUNCNAME} "$@" 340 debug-print-function ${FUNCNAME} "$@"
310 341
336 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 367 [[ ${EGIT_REPO_URI_SELECTED} ]] \
337 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 368 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
338} 369}
339 370
340# @FUNCTION: git-2_fetch 371# @FUNCTION: git-2_fetch
372# @INTERNAL
341# @DESCRIPTION: 373# @DESCRIPTION:
342# Internal function fetching repository from EGIT_REPO_URI and storing it in 374# Internal function fetching repository from EGIT_REPO_URI and storing it in
343# specified EGIT_STORE_DIR. 375# specified EGIT_STORE_DIR.
344git-2_fetch() { 376git-2_fetch() {
345 debug-print-function ${FUNCNAME} "$@" 377 debug-print-function ${FUNCNAME} "$@"
391 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \ 423 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
392 && echo " commit: ${EGIT_COMMIT}" 424 && echo " commit: ${EGIT_COMMIT}"
393 echo " branch: ${EGIT_BRANCH}" 425 echo " branch: ${EGIT_BRANCH}"
394 echo " storage directory: \"${EGIT_DIR}\"" 426 echo " storage directory: \"${EGIT_DIR}\""
395 echo " checkout type: ${repo_type}" 427 echo " checkout type: ${repo_type}"
428
429 # Cleanup after git.eclass
430 if [[ ${EGIT_OLD_CLONE} ]]; then
431 einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
432 rm -rf "${EGIT_OLD_CLONE}"
433 fi
396} 434}
397 435
398# @FUNCTION: git_bootstrap 436# @FUNCTION: git_bootstrap
437# @INTERNAL
399# @DESCRIPTION: 438# @DESCRIPTION:
400# Internal function that runs bootstrap command on unpacked source. 439# Internal function that runs bootstrap command on unpacked source.
401git-2_bootstrap() { 440git-2_bootstrap() {
402 debug-print-function ${FUNCNAME} "$@" 441 debug-print-function ${FUNCNAME} "$@"
403 442
436 popd > /dev/null 475 popd > /dev/null
437 fi 476 fi
438} 477}
439 478
440# @FUNCTION: git-2_migrate_repository 479# @FUNCTION: git-2_migrate_repository
480# @INTERNAL
441# @DESCRIPTION: 481# @DESCRIPTION:
442# Internal function migrating between bare and normal checkout repository. 482# Internal function migrating between bare and normal checkout repository.
443# This is based on usage of EGIT_SUBMODULES, at least until they 483# This is based on usage of EGIT_SUBMODULES, at least until they
444# start to work with bare checkouts sanely. 484# start to work with bare checkouts sanely.
445# This function also set some global variables that differ between 485# This function also set some global variables that differ between
494 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 534 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
495 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" 535 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
496 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 536 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
497 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 537 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
498 UPSTREAM_BRANCH="${EGIT_BRANCH}" 538 UPSTREAM_BRANCH="${EGIT_BRANCH}"
539 EGIT_LOCAL_NONBARE=
499 else 540 else
500 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 541 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
501 MOVE_COMMAND="cp -pPR ." 542 MOVE_COMMAND="cp -pPR ."
502 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}" 543 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
503 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 544 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
505 EGIT_LOCAL_NONBARE="true" 546 EGIT_LOCAL_NONBARE="true"
506 fi 547 fi
507} 548}
508 549
509# @FUNCTION: git-2_cleanup 550# @FUNCTION: git-2_cleanup
551# @INTERNAL
510# @DESCRIPTION: 552# @DESCRIPTION:
511# Internal function cleaning up all the global variables 553# Internal function cleaning up all the global variables
512# that are not required after the unpack has been done. 554# that are not required after the unpack has been done.
513git-2_cleanup() { 555git-2_cleanup() {
514 debug-print-function ${FUNCNAME} "$@" 556 debug-print-function ${FUNCNAME} "$@"

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

  ViewVC Help
Powered by ViewVC 1.1.20