/[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.17 Revision 1.34
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2014 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.17 2011/09/23 13:57:15 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.34 2014/11/20 15:25:52 mgorny 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.
66# @DEFAULT_UNSET 67# @DEFAULT_UNSET
67# @DESCRIPTION: 68# @DESCRIPTION:
68# URI for the repository 69# URI for the repository
69# e.g. http://foo, git://bar 70# e.g. http://foo, git://bar
70# 71#
72# It can be overriden via env using packagename_LIVE_REPO
73# variable.
74#
71# Support multiple values: 75# Support multiple values:
72# EGIT_REPO_URI="git://a/b.git http://c/d.git" 76# EGIT_REPO_URI="git://a/b.git http://c/d.git"
73 77
74# @ECLASS-VARIABLE: EVCS_OFFLINE 78# @ECLASS-VARIABLE: EVCS_OFFLINE
75# @DEFAULT_UNSET 79# @DEFAULT_UNSET
118# @DESCRIPTION: 122# @DESCRIPTION:
119# If non-empty this variable bans unpacking of ${A} content into the srcdir. 123# If non-empty this variable bans unpacking of ${A} content into the srcdir.
120# Default behaviour is to unpack ${A} content. 124# Default behaviour is to unpack ${A} content.
121 125
122# @FUNCTION: git-2_init_variables 126# @FUNCTION: git-2_init_variables
127# @INTERNAL
123# @DESCRIPTION: 128# @DESCRIPTION:
124# Internal function initializing all git variables. 129# Internal function initializing all git variables.
125# We define it in function scope so user can define 130# We define it in function scope so user can define
126# all the variables before and after inherit. 131# all the variables before and after inherit.
127git-2_init_variables() { 132git-2_init_variables() {
158 163
159 : ${EGIT_PRUNE:=} 164 : ${EGIT_PRUNE:=}
160} 165}
161 166
162# @FUNCTION: git-2_submodules 167# @FUNCTION: git-2_submodules
168# @INTERNAL
163# @DESCRIPTION: 169# @DESCRIPTION:
164# Internal function wrapping the submodule initialisation and update. 170# Internal function wrapping the submodule initialisation and update.
165git-2_submodules() { 171git-2_submodules() {
166 debug-print-function ${FUNCNAME} "$@" 172 debug-print-function ${FUNCNAME} "$@"
167 if [[ ${EGIT_HAS_SUBMODULES} ]]; then 173 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
184 popd > /dev/null 190 popd > /dev/null
185 fi 191 fi
186} 192}
187 193
188# @FUNCTION: git-2_branch 194# @FUNCTION: git-2_branch
195# @INTERNAL
189# @DESCRIPTION: 196# @DESCRIPTION:
190# Internal function that changes branch for the repo based on EGIT_COMMIT and 197# Internal function that changes branch for the repo based on EGIT_COMMIT and
191# EGIT_BRANCH variables. 198# EGIT_BRANCH variables.
192git-2_branch() { 199git-2_branch() {
193 debug-print-function ${FUNCNAME} "$@" 200 debug-print-function ${FUNCNAME} "$@"
208 215
209 popd > /dev/null 216 popd > /dev/null
210} 217}
211 218
212# @FUNCTION: git-2_gc 219# @FUNCTION: git-2_gc
220# @INTERNAL
213# @DESCRIPTION: 221# @DESCRIPTION:
214# Internal function running garbage collector on checked out tree. 222# Internal function running garbage collector on checked out tree.
215git-2_gc() { 223git-2_gc() {
216 debug-print-function ${FUNCNAME} "$@" 224 debug-print-function ${FUNCNAME} "$@"
217 225
218 local args 226 local args
219 227
220 pushd "${EGIT_DIR}" > /dev/null
221 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then 228 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
229 pushd "${EGIT_DIR}" > /dev/null
222 ebegin "Garbage collecting the repository" 230 ebegin "Garbage collecting the repository"
223 [[ ${EGIT_PRUNE} ]] && args='--prune' 231 [[ ${EGIT_PRUNE} ]] && args='--prune'
224 debug-print "${FUNCNAME}: git gc ${args}" 232 debug-print "${FUNCNAME}: git gc ${args}"
225 git gc ${args} 233 git gc ${args}
226 eend $? 234 eend $?
227 fi
228 popd > /dev/null 235 popd > /dev/null
236 fi
229} 237}
230 238
231# @FUNCTION: git-2_prepare_storedir 239# @FUNCTION: git-2_prepare_storedir
240# @INTERNAL
232# @DESCRIPTION: 241# @DESCRIPTION:
233# Internal function preparing directory where we are going to store SCM 242# Internal function preparing directory where we are going to store SCM
234# repository. 243# repository.
235git-2_prepare_storedir() { 244git-2_prepare_storedir() {
236 debug-print-function ${FUNCNAME} "$@" 245 debug-print-function ${FUNCNAME} "$@"
240 # initial clone, we have to create master git storage directory and play 249 # initial clone, we have to create master git storage directory and play
241 # nicely with sandbox 250 # nicely with sandbox
242 if [[ ! -d ${EGIT_STORE_DIR} ]]; then 251 if [[ ! -d ${EGIT_STORE_DIR} ]]; then
243 debug-print "${FUNCNAME}: Creating git main storage directory" 252 debug-print "${FUNCNAME}: Creating git main storage directory"
244 addwrite / 253 addwrite /
245 mkdir -p "${EGIT_STORE_DIR}" \ 254 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
246 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 255 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
247 fi 256 fi
248 257
249 # allow writing into EGIT_STORE_DIR 258 # allow writing into EGIT_STORE_DIR
250 addwrite "${EGIT_STORE_DIR}" 259 addwrite "${EGIT_STORE_DIR}"
260
261 # calculate git.eclass store dir for data
262 # We will try to clone the old repository,
263 # and we will remove it if we don't need it anymore.
264 EGIT_OLD_CLONE=
265 if [[ ${EGIT_STORE_DIR} == */egit-src ]]; then
266 local old_store_dir=${EGIT_STORE_DIR/%egit-src/git-src}
267 local old_location=${old_store_dir}/${EGIT_PROJECT:-${PN}}
268
269 if [[ -d ${old_location} ]]; then
270 EGIT_OLD_CLONE=${old_location}
271 # required to remove the old clone
272 addwrite "${old_store_dir}"
273 fi
274 fi
275
251 # calculate the proper store dir for data 276 # calculate the proper store dir for data
252 # If user didn't specify the EGIT_DIR, we check if he did specify 277 # 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. 278 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
254 EGIT_REPO_URI=${EGIT_REPO_URI%/} 279 EGIT_REPO_URI=${EGIT_REPO_URI%/}
255 if [[ ! ${EGIT_DIR} ]]; then 280 if [[ ! ${EGIT_DIR} ]]; then
256 if [[ ${EGIT_PROJECT} ]]; then 281 if [[ ${EGIT_PROJECT} ]]; then
257 clone_dir=${EGIT_PROJECT} 282 clone_dir=${EGIT_PROJECT}
258 else 283 else
259 clone_dir=${EGIT_REPO_URI##*/} 284 local strippeduri=${EGIT_REPO_URI%/.git}
285 clone_dir=${strippeduri##*/}
260 fi 286 fi
261 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 287 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
288
289 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
290 elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
291 elog "It will be necessary to rebuild the package to fetch updates."
292 EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
293 fi
262 fi 294 fi
263 export EGIT_DIR=${EGIT_DIR} 295 export EGIT_DIR=${EGIT_DIR}
264 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 296 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
265} 297}
266 298
267# @FUNCTION: git-2_move_source 299# @FUNCTION: git-2_move_source
300# @INTERNAL
268# @DESCRIPTION: 301# @DESCRIPTION:
269# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 302# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
270git-2_move_source() { 303git-2_move_source() {
271 debug-print-function ${FUNCNAME} "$@" 304 debug-print-function ${FUNCNAME} "$@"
272 305
278 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 311 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
279 popd > /dev/null 312 popd > /dev/null
280} 313}
281 314
282# @FUNCTION: git-2_initial_clone 315# @FUNCTION: git-2_initial_clone
316# @INTERNAL
283# @DESCRIPTION: 317# @DESCRIPTION:
284# Internal function running initial clone on specified repo_uri. 318# Internal function running initial clone on specified repo_uri.
285git-2_initial_clone() { 319git-2_initial_clone() {
286 debug-print-function ${FUNCNAME} "$@" 320 debug-print-function ${FUNCNAME} "$@"
287 321
288 local repo_uri 322 local repo_uri
289 323
290 EGIT_REPO_URI_SELECTED="" 324 EGIT_REPO_URI_SELECTED=""
291 for repo_uri in ${EGIT_REPO_URI}; do 325 for repo_uri in ${EGIT_REPO_URI}; do
292 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 326 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
293 git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 327 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
294 if [[ $? -eq 0 ]]; then
295 # global variable containing the repo_name we will be using 328 # global variable containing the repo_name we will be using
296 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 329 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
297 EGIT_REPO_URI_SELECTED="${repo_uri}" 330 EGIT_REPO_URI_SELECTED="${repo_uri}"
298 break 331 break
299 fi 332 fi
302 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 335 [[ ${EGIT_REPO_URI_SELECTED} ]] \
303 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 336 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
304} 337}
305 338
306# @FUNCTION: git-2_update_repo 339# @FUNCTION: git-2_update_repo
340# @INTERNAL
307# @DESCRIPTION: 341# @DESCRIPTION:
308# Internal function running update command on specified repo_uri. 342# Internal function running update command on specified repo_uri.
309git-2_update_repo() { 343git-2_update_repo() {
310 debug-print-function ${FUNCNAME} "$@" 344 debug-print-function ${FUNCNAME} "$@"
311 345
324 for repo_uri in ${EGIT_REPO_URI}; do 358 for repo_uri in ${EGIT_REPO_URI}; do
325 # git urls might change, so reset it 359 # git urls might change, so reset it
326 git config remote.origin.url "${repo_uri}" 360 git config remote.origin.url "${repo_uri}"
327 361
328 debug-print "${EGIT_UPDATE_CMD}" 362 debug-print "${EGIT_UPDATE_CMD}"
329 ${EGIT_UPDATE_CMD} > /dev/null 363 if ${EGIT_UPDATE_CMD} > /dev/null; then
330 if [[ $? -eq 0 ]]; then
331 # global variable containing the repo_name we will be using 364 # global variable containing the repo_name we will be using
332 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 365 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
333 EGIT_REPO_URI_SELECTED="${repo_uri}" 366 EGIT_REPO_URI_SELECTED="${repo_uri}"
334 break 367 break
335 fi 368 fi
338 [[ ${EGIT_REPO_URI_SELECTED} ]] \ 371 [[ ${EGIT_REPO_URI_SELECTED} ]] \
339 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 372 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
340} 373}
341 374
342# @FUNCTION: git-2_fetch 375# @FUNCTION: git-2_fetch
376# @INTERNAL
343# @DESCRIPTION: 377# @DESCRIPTION:
344# Internal function fetching repository from EGIT_REPO_URI and storing it in 378# Internal function fetching repository from EGIT_REPO_URI and storing it in
345# specified EGIT_STORE_DIR. 379# specified EGIT_STORE_DIR.
346git-2_fetch() { 380git-2_fetch() {
347 debug-print-function ${FUNCNAME} "$@" 381 debug-print-function ${FUNCNAME} "$@"
393 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \ 427 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
394 && echo " commit: ${EGIT_COMMIT}" 428 && echo " commit: ${EGIT_COMMIT}"
395 echo " branch: ${EGIT_BRANCH}" 429 echo " branch: ${EGIT_BRANCH}"
396 echo " storage directory: \"${EGIT_DIR}\"" 430 echo " storage directory: \"${EGIT_DIR}\""
397 echo " checkout type: ${repo_type}" 431 echo " checkout type: ${repo_type}"
432
433 # Cleanup after git.eclass
434 if [[ ${EGIT_OLD_CLONE} ]]; then
435 einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
436 rm -rf "${EGIT_OLD_CLONE}"
437 fi
398} 438}
399 439
400# @FUNCTION: git_bootstrap 440# @FUNCTION: git_bootstrap
441# @INTERNAL
401# @DESCRIPTION: 442# @DESCRIPTION:
402# Internal function that runs bootstrap command on unpacked source. 443# Internal function that runs bootstrap command on unpacked source.
403git-2_bootstrap() { 444git-2_bootstrap() {
404 debug-print-function ${FUNCNAME} "$@" 445 debug-print-function ${FUNCNAME} "$@"
405 446
438 popd > /dev/null 479 popd > /dev/null
439 fi 480 fi
440} 481}
441 482
442# @FUNCTION: git-2_migrate_repository 483# @FUNCTION: git-2_migrate_repository
484# @INTERNAL
443# @DESCRIPTION: 485# @DESCRIPTION:
444# Internal function migrating between bare and normal checkout repository. 486# Internal function migrating between bare and normal checkout repository.
445# This is based on usage of EGIT_SUBMODULES, at least until they 487# This is based on usage of EGIT_SUBMODULES, at least until they
446# start to work with bare checkouts sanely. 488# start to work with bare checkouts sanely.
447# This function also set some global variables that differ between 489# This function also set some global variables that differ between
448# bare and non-bare checkout. 490# bare and non-bare checkout.
449git-2_migrate_repository() { 491git-2_migrate_repository() {
450 debug-print-function ${FUNCNAME} "$@" 492 debug-print-function ${FUNCNAME} "$@"
451 493
452 local target returnstate 494 local bare returnstate
453 495
454 # first find out if we have submodules 496 # first find out if we have submodules
497 # or user explicitly wants us to use non-bare clones
455 if [[ ! ${EGIT_HAS_SUBMODULES} ]]; then 498 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
456 target="bare" 499 bare=1
457 else
458 target="full"
459 fi
460 # check if user didn't specify that we want non-bare repo
461 if [[ ${EGIT_NONBARE} ]]; then
462 target="full"
463 EGIT_LOCAL_NONBARE="true"
464 fi 500 fi
465 501
466 # test if we already have some repo and if so find out if we have 502 # test if we already have some repo and if so find out if we have
467 # to migrate the data 503 # to migrate the data
468 if [[ -d ${EGIT_DIR} ]]; then 504 if [[ -d ${EGIT_DIR} ]]; then
469 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 505 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
470 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 506 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
471 507
472 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 508 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
473 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 509 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
474 export GIT_DIR="${EGIT_DIR}.bare" 510 export GIT_DIR="${EGIT_DIR}.bare"
476 returnstate=$? 512 returnstate=$?
477 unset GIT_DIR 513 unset GIT_DIR
478 rm -rf "${EGIT_DIR}" 514 rm -rf "${EGIT_DIR}"
479 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 515 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
480 eend ${returnstate} 516 eend ${returnstate}
481 fi
482 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 517 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
483 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 518 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
484 519
485 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 520 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
486 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 521 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
487 returnstate=$? 522 returnstate=$?
497 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 532 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
498 rm -rf "${EGIT_DIR}" 533 rm -rf "${EGIT_DIR}"
499 fi 534 fi
500 535
501 # set various options to work with both targets 536 # set various options to work with both targets
502 if [[ ${target} == bare ]]; then 537 if [[ ${bare} ]]; then
503 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 538 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
504 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" 539 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
505 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 540 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
506 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 541 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
507 UPSTREAM_BRANCH="${EGIT_BRANCH}" 542 UPSTREAM_BRANCH="${EGIT_BRANCH}"
543 EGIT_LOCAL_NONBARE=
508 else 544 else
509 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 545 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
510 MOVE_COMMAND="cp -pPR ." 546 MOVE_COMMAND="cp -pPR ."
511 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}" 547 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
512 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 548 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
514 EGIT_LOCAL_NONBARE="true" 550 EGIT_LOCAL_NONBARE="true"
515 fi 551 fi
516} 552}
517 553
518# @FUNCTION: git-2_cleanup 554# @FUNCTION: git-2_cleanup
555# @INTERNAL
519# @DESCRIPTION: 556# @DESCRIPTION:
520# Internal function cleaning up all the global variables 557# Internal function cleaning up all the global variables
521# that are not required after the unpack has been done. 558# that are not required after the unpack has been done.
522git-2_cleanup() { 559git-2_cleanup() {
523 debug-print-function ${FUNCNAME} "$@" 560 debug-print-function ${FUNCNAME} "$@"

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.34

  ViewVC Help
Powered by ViewVC 1.1.20