/[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.7 Revision 1.15
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.7 2011/05/20 14:35:01 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.15 2011/09/23 13:55:47 mgorny Exp $
4 4
5# @ECLASS: git-2.eclass 5# @ECLASS: git-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Tomas Chvatal <scarabeus@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.
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Eclass for easing maitenance of live ebuilds using git as remote repository. 10# Eclass for easing maitenance of live ebuilds using git as remote repository.
11# Eclass support working with git submodules and branching. 11# Eclass support working with git submodules and branching.
12 12
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
120# all the variables before and after inherit. 126# all the variables before and after inherit.
121git-2_init_variables() { 127git-2_init_variables() {
122 debug-print-function ${FUNCNAME} "$@" 128 debug-print-function ${FUNCNAME} "$@"
123 129
124 local x 130 local esc_pn liverepo livebranch livecommit
131 esc_pn=${PN//[-+]/_}
125 132
126 : ${EGIT_SOURCEDIR="${S}"} 133 : ${EGIT_SOURCEDIR="${S}"}
127 134
128 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} 135 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"}
129 136
131 138
132 : ${EGIT_OPTIONS:=} 139 : ${EGIT_OPTIONS:=}
133 140
134 : ${EGIT_MASTER:=master} 141 : ${EGIT_MASTER:=master}
135 142
136 eval x="\$${PN//[-+]/_}_LIVE_REPO" 143 liverepo=${esc_pn}_LIVE_REPO
137 EGIT_REPO_URI=${x:-${EGIT_REPO_URI}} 144 EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}}
138 [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value" 145 [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value"
139 146
140 : ${EVCS_OFFLINE:=} 147 : ${EVCS_OFFLINE:=}
141 148
142 eval x="\$${PN//[-+]/_}_LIVE_BRANCH" 149 livebranch=${esc_pn}_LIVE_BRANCH
143 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_BRANCH\" variable, you won't get any support" 150 [[ -n ${!livebranch} ]] && ewarn "QA: using \"${esc_pn}_LIVE_BRANCH\" variable, you won't get any support"
144 EGIT_BRANCH=${x:-${EGIT_BRANCH:-${EGIT_MASTER}}} 151 EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}}
145 152
146 eval x="\$${PN//[-+]/_}_LIVE_COMMIT" 153 livecommit=${esc_pn}_LIVE_COMMIT
147 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_COMMIT\" variable, you won't get any support" 154 [[ -n ${!livecommit} ]] && ewarn "QA: using \"${esc_pn}_LIVE_COMMIT\" variable, you won't get any support"
148 EGIT_COMMIT=${x:-${EGIT_COMMIT:-${EGIT_BRANCH}}} 155 EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}}
149 156
150 : ${EGIT_REPACK:=} 157 : ${EGIT_REPACK:=}
151 158
152 : ${EGIT_PRUNE:=} 159 : ${EGIT_PRUNE:=}
153} 160}
183# Internal function that changes branch for the repo based on EGIT_COMMIT and 190# Internal function that changes branch for the repo based on EGIT_COMMIT and
184# EGIT_BRANCH variables. 191# EGIT_BRANCH variables.
185git-2_branch() { 192git-2_branch() {
186 debug-print-function ${FUNCNAME} "$@" 193 debug-print-function ${FUNCNAME} "$@"
187 194
195 local branchname src
196
188 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" 197 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\""
189 pushd "${EGIT_SOURCEDIR}" > /dev/null 198 pushd "${EGIT_SOURCEDIR}" > /dev/null
190 199
191 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} 200 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
192 if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then 201 if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then
196 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" 205 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}"
197 git checkout -b ${branchname} ${src} \ 206 git checkout -b ${branchname} ${src} \
198 || die "${FUNCNAME}: changing the branch failed" 207 || die "${FUNCNAME}: changing the branch failed"
199 208
200 popd > /dev/null 209 popd > /dev/null
201
202 unset branchname src
203} 210}
204 211
205# @FUNCTION: git-2_gc 212# @FUNCTION: git-2_gc
206# @DESCRIPTION: 213# @DESCRIPTION:
207# Internal function running garbage collector on checked out tree. 214# Internal function running garbage collector on checked out tree.
208git-2_gc() { 215git-2_gc() {
209 debug-print-function ${FUNCNAME} "$@" 216 debug-print-function ${FUNCNAME} "$@"
217
218 local args
210 219
211 pushd "${EGIT_DIR}" > /dev/null 220 pushd "${EGIT_DIR}" > /dev/null
212 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then 221 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then
213 ebegin "Garbage collecting the repository" 222 ebegin "Garbage collecting the repository"
214 local args
215 [[ -n ${EGIT_PRUNE} ]] && args='--prune' 223 [[ -n ${EGIT_PRUNE} ]] && args='--prune'
216 debug-print "${FUNCNAME}: git gc ${args}" 224 debug-print "${FUNCNAME}: git gc ${args}"
217 git gc ${args} 225 git gc ${args}
218 eend $? 226 eend $?
219 fi 227 fi
236 addwrite / 244 addwrite /
237 mkdir -p "${EGIT_STORE_DIR}" \ 245 mkdir -p "${EGIT_STORE_DIR}" \
238 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 246 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
239 fi 247 fi
240 248
241 cd -P "${EGIT_STORE_DIR}" \
242 || die "${FUNCNAME}: can't chdir to \"${EGIT_STORE_DIR}\""
243 # allow writing into EGIT_STORE_DIR 249 # allow writing into EGIT_STORE_DIR
244 addwrite "${EGIT_STORE_DIR}" 250 addwrite "${EGIT_STORE_DIR}"
245 # calculate the proper store dir for data 251 # calculate the proper store dir for data
246 # If user didn't specify the EGIT_DIR, we check if he did specify 252 # If user didn't specify the EGIT_DIR, we check if he did specify
247 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. 253 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
281 287
282 local repo_uri 288 local repo_uri
283 289
284 EGIT_REPO_URI_SELECTED="" 290 EGIT_REPO_URI_SELECTED=""
285 for repo_uri in ${EGIT_REPO_URI}; do 291 for repo_uri in ${EGIT_REPO_URI}; do
286 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 292 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
287 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 293 git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"
288 if [[ $? -eq 0 ]]; then 294 if [[ $? -eq 0 ]]; then
289 # global variable containing the repo_name we will be using 295 # global variable containing the repo_name we will be using
290 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 296 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
291 EGIT_REPO_URI_SELECTED="${repo_uri}" 297 EGIT_REPO_URI_SELECTED="${repo_uri}"
292 break 298 break
304git-2_update_repo() { 310git-2_update_repo() {
305 debug-print-function ${FUNCNAME} "$@" 311 debug-print-function ${FUNCNAME} "$@"
306 312
307 local repo_uri 313 local repo_uri
308 314
309 if [[ -n ${EGIT_NONBARE} ]]; then 315 if [[ -n ${EGIT_LOCAL_NONBARE} ]]; then
310 # checkout master branch and drop all other local branches 316 # checkout master branch and drop all other local branches
311 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}" 317 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
312 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do 318 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
313 debug-print "${FUNCNAME}: git branch -D ${x}" 319 debug-print "${FUNCNAME}: git branch -D ${x}"
314 git branch -D ${x} > /dev/null 320 git branch -D ${x} > /dev/null
342git-2_fetch() { 348git-2_fetch() {
343 debug-print-function ${FUNCNAME} "$@" 349 debug-print-function ${FUNCNAME} "$@"
344 350
345 local oldsha cursha repo_type 351 local oldsha cursha repo_type
346 352
347 [[ -n ${EGIT_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository" 353 [[ -n ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
348 354
349 if [[ ! -d ${EGIT_DIR} ]]; then 355 if [[ ! -d ${EGIT_DIR} ]]; then
350 git-2_initial_clone 356 git-2_initial_clone
351 pushd "${EGIT_DIR}" > /dev/null 357 pushd "${EGIT_DIR}" > /dev/null
352 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 358 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
397# @DESCRIPTION: 403# @DESCRIPTION:
398# Internal function that runs bootstrap command on unpacked source. 404# Internal function that runs bootstrap command on unpacked source.
399git-2_bootstrap() { 405git-2_bootstrap() {
400 debug-print-function ${FUNCNAME} "$@" 406 debug-print-function ${FUNCNAME} "$@"
401 407
402 # @ECLASS_VARIABLE: EGIT_BOOTSTRAP 408 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
403 # @DESCRIPTION: 409 # @DESCRIPTION:
404 # Command to be executed after checkout and clone of the specified 410 # Command to be executed after checkout and clone of the specified
405 # repository. 411 # repository.
406 # enviroment the package will fail if there is no update, thus in 412 # enviroment the package will fail if there is no update, thus in
407 # combination with --keep-going it would lead in not-updating 413 # combination with --keep-going it would lead in not-updating
438# @FUNCTION: git-2_migrate_repository 444# @FUNCTION: git-2_migrate_repository
439# @DESCRIPTION: 445# @DESCRIPTION:
440# Internal function migrating between bare and normal checkout repository. 446# Internal function migrating between bare and normal checkout repository.
441# This is based on usage of EGIT_SUBMODULES, at least until they 447# This is based on usage of EGIT_SUBMODULES, at least until they
442# start to work with bare checkouts sanely. 448# start to work with bare checkouts sanely.
449# This function also set some global variables that differ between
450# bare and non-bare checkout.
443git-2_migrate_repository() { 451git-2_migrate_repository() {
444 debug-print-function ${FUNCNAME} "$@" 452 debug-print-function ${FUNCNAME} "$@"
445 453
446 local target returnstate 454 local target returnstate
447 455
449 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 457 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then
450 target="bare" 458 target="bare"
451 else 459 else
452 target="full" 460 target="full"
453 fi 461 fi
454 [[ -n ${EGIT_NONBARE} ]] && target="full" 462 # check if user didn't specify that we want non-bare repo
463 if [[ -n ${EGIT_NONBARE} ]]; then
464 target="full"
465 EGIT_LOCAL_NONBARE="true"
466 fi
455 467
456 # test if we already have some repo and if so find out if we have 468 # test if we already have some repo and if so find out if we have
457 # to migrate the data 469 # to migrate the data
458 if [[ -d ${EGIT_DIR} ]]; then 470 if [[ -d ${EGIT_DIR} ]]; then
459 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 471 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then
489 fi 501 fi
490 502
491 # set various options to work with both targets 503 # set various options to work with both targets
492 if [[ ${target} == bare ]]; then 504 if [[ ${target} == bare ]]; then
493 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 505 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
494 EGIT_OPTIONS+=" --bare" 506 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
495 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 507 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
496 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}"
497 UPSTREAM_BRANCH="${EGIT_BRANCH}" 509 UPSTREAM_BRANCH="${EGIT_BRANCH}"
498 else 510 else
499 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 511 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
500 MOVE_COMMAND="cp -pPR ." 512 MOVE_COMMAND="cp -pPR ."
513 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
501 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 514 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
502 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 515 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
503 EGIT_NONBARE="true" 516 EGIT_LOCAL_NONBARE="true"
504 fi 517 fi
518}
519
520# @FUNCTION: git-2_cleanup
521# @DESCRIPTION:
522# Internal function cleaning up all the global variables
523# that are not required after the unpack has been done.
524git-2_cleanup() {
525 debug-print-function ${FUNCNAME} "$@"
526
527 # Here we can unset only variables that are GLOBAL
528 # defined by the eclass, BUT NOT subject to change
529 # by user (like EGIT_PROJECT).
530 # If ebuild writer polutes his environment it is
531 # his problem only.
532 unset EGIT_DIR
533 unset MOVE_COMMAND
534 unset EGIT_LOCAL_OPTIONS
535 unset EGIT_UPDATE_CMD
536 unset UPSTREAM_BRANCH
537 unset EGIT_LOCAL_NONBARE
505} 538}
506 539
507# @FUNCTION: git-2_src_unpack 540# @FUNCTION: git-2_src_unpack
508# @DESCRIPTION: 541# @DESCRIPTION:
509# Default git src_unpack function. 542# Default git src_unpack function.
517 git-2_gc 550 git-2_gc
518 git-2_submodules 551 git-2_submodules
519 git-2_move_source 552 git-2_move_source
520 git-2_branch 553 git-2_branch
521 git-2_bootstrap 554 git-2_bootstrap
555 git-2_cleanup
522 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 556 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
557
558 # Users can specify some SRC_URI and we should
559 # unpack the files too.
560 if [[ -z ${EGIT_NOUNPACK} ]]; then
561 if has ${EAPI:-0} 0 1; then
562 [[ -n ${A} ]] && unpack ${A}
563 else
564 default_src_unpack
565 fi
566 fi
523} 567}

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20