/[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.9 Revision 1.16
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.9 2011/05/20 15:53:43 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.16 2011/09/23 13:56:29 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
241 # allow writing into EGIT_STORE_DIR 249 # allow writing into EGIT_STORE_DIR
242 addwrite "${EGIT_STORE_DIR}" 250 addwrite "${EGIT_STORE_DIR}"
243 # calculate the proper store dir for data 251 # calculate the proper store dir for data
244 # 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
245 # 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.
246 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" 254 EGIT_REPO_URI=${EGIT_REPO_URI%/}
247 if [[ -z ${EGIT_DIR} ]]; then 255 if [[ -z ${EGIT_DIR} ]]; then
248 if [[ -n ${EGIT_PROJECT} ]]; then 256 if [[ -n ${EGIT_PROJECT} ]]; then
249 clone_dir=${EGIT_PROJECT} 257 clone_dir=${EGIT_PROJECT}
250 else 258 else
251 clone_dir=${EGIT_REPO_URI##*/} 259 clone_dir=${EGIT_REPO_URI##*/}
279 287
280 local repo_uri 288 local repo_uri
281 289
282 EGIT_REPO_URI_SELECTED="" 290 EGIT_REPO_URI_SELECTED=""
283 for repo_uri in ${EGIT_REPO_URI}; do 291 for repo_uri in ${EGIT_REPO_URI}; do
284 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 292 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
285 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 293 git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"
286 if [[ $? -eq 0 ]]; then 294 if [[ $? -eq 0 ]]; then
287 # global variable containing the repo_name we will be using 295 # global variable containing the repo_name we will be using
288 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 296 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
289 EGIT_REPO_URI_SELECTED="${repo_uri}" 297 EGIT_REPO_URI_SELECTED="${repo_uri}"
290 break 298 break
302git-2_update_repo() { 310git-2_update_repo() {
303 debug-print-function ${FUNCNAME} "$@" 311 debug-print-function ${FUNCNAME} "$@"
304 312
305 local repo_uri 313 local repo_uri
306 314
307 if [[ -n ${EGIT_NONBARE} ]]; then 315 if [[ -n ${EGIT_LOCAL_NONBARE} ]]; then
308 # checkout master branch and drop all other local branches 316 # checkout master branch and drop all other local branches
309 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}"
310 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
311 debug-print "${FUNCNAME}: git branch -D ${x}" 319 debug-print "${FUNCNAME}: git branch -D ${x}"
312 git branch -D ${x} > /dev/null 320 git branch -D ${x} > /dev/null
340git-2_fetch() { 348git-2_fetch() {
341 debug-print-function ${FUNCNAME} "$@" 349 debug-print-function ${FUNCNAME} "$@"
342 350
343 local oldsha cursha repo_type 351 local oldsha cursha repo_type
344 352
345 [[ -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"
346 354
347 if [[ ! -d ${EGIT_DIR} ]]; then 355 if [[ ! -d ${EGIT_DIR} ]]; then
348 git-2_initial_clone 356 git-2_initial_clone
349 pushd "${EGIT_DIR}" > /dev/null 357 pushd "${EGIT_DIR}" > /dev/null
350 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 358 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
395# @DESCRIPTION: 403# @DESCRIPTION:
396# Internal function that runs bootstrap command on unpacked source. 404# Internal function that runs bootstrap command on unpacked source.
397git-2_bootstrap() { 405git-2_bootstrap() {
398 debug-print-function ${FUNCNAME} "$@" 406 debug-print-function ${FUNCNAME} "$@"
399 407
400 # @ECLASS_VARIABLE: EGIT_BOOTSTRAP 408 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
401 # @DESCRIPTION: 409 # @DESCRIPTION:
402 # Command to be executed after checkout and clone of the specified 410 # Command to be executed after checkout and clone of the specified
403 # repository. 411 # repository.
404 # 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
405 # combination with --keep-going it would lead in not-updating 413 # combination with --keep-going it would lead in not-updating
436# @FUNCTION: git-2_migrate_repository 444# @FUNCTION: git-2_migrate_repository
437# @DESCRIPTION: 445# @DESCRIPTION:
438# Internal function migrating between bare and normal checkout repository. 446# Internal function migrating between bare and normal checkout repository.
439# 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
440# 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.
441git-2_migrate_repository() { 451git-2_migrate_repository() {
442 debug-print-function ${FUNCNAME} "$@" 452 debug-print-function ${FUNCNAME} "$@"
443 453
444 local target returnstate 454 local target returnstate
445 455
447 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 457 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then
448 target="bare" 458 target="bare"
449 else 459 else
450 target="full" 460 target="full"
451 fi 461 fi
452 [[ -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
453 467
454 # 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
455 # to migrate the data 469 # to migrate the data
456 if [[ -d ${EGIT_DIR} ]]; then 470 if [[ -d ${EGIT_DIR} ]]; then
457 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 471 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then
487 fi 501 fi
488 502
489 # set various options to work with both targets 503 # set various options to work with both targets
490 if [[ ${target} == bare ]]; then 504 if [[ ${target} == bare ]]; then
491 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 505 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
492 EGIT_OPTIONS+=" --bare" 506 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
493 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 507 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
494 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}"
495 UPSTREAM_BRANCH="${EGIT_BRANCH}" 509 UPSTREAM_BRANCH="${EGIT_BRANCH}"
496 else 510 else
497 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}\""
498 MOVE_COMMAND="cp -pPR ." 512 MOVE_COMMAND="cp -pPR ."
513 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
499 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 514 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
500 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 515 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
501 EGIT_NONBARE="true" 516 EGIT_LOCAL_NONBARE="true"
502 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
503} 538}
504 539
505# @FUNCTION: git-2_src_unpack 540# @FUNCTION: git-2_src_unpack
506# @DESCRIPTION: 541# @DESCRIPTION:
507# Default git src_unpack function. 542# Default git src_unpack function.
515 git-2_gc 550 git-2_gc
516 git-2_submodules 551 git-2_submodules
517 git-2_move_source 552 git-2_move_source
518 git-2_branch 553 git-2_branch
519 git-2_bootstrap 554 git-2_bootstrap
555 git-2_cleanup
520 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 556 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
521 557
522 # Users can specify some SRC_URI and we should 558 # Users can specify some SRC_URI and we should
523 # unpack the files too. 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
524 default_src_unpack 564 default_src_unpack
565 fi
566 fi
525} 567}

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.20