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