| 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.17 2011/09/23 13:57:15 mgorny Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.21 2011/09/23 13:58:09 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. |
| … | |
… | |
| 215 | git-2_gc() { |
215 | git-2_gc() { |
| 216 | debug-print-function ${FUNCNAME} "$@" |
216 | debug-print-function ${FUNCNAME} "$@" |
| 217 | |
217 | |
| 218 | local args |
218 | local args |
| 219 | |
219 | |
| 220 | pushd "${EGIT_DIR}" > /dev/null |
|
|
| 221 | if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then |
220 | if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then |
|
|
221 | pushd "${EGIT_DIR}" > /dev/null |
| 222 | ebegin "Garbage collecting the repository" |
222 | ebegin "Garbage collecting the repository" |
| 223 | [[ ${EGIT_PRUNE} ]] && args='--prune' |
223 | [[ ${EGIT_PRUNE} ]] && args='--prune' |
| 224 | debug-print "${FUNCNAME}: git gc ${args}" |
224 | debug-print "${FUNCNAME}: git gc ${args}" |
| 225 | git gc ${args} |
225 | git gc ${args} |
| 226 | eend $? |
226 | eend $? |
| 227 | fi |
|
|
| 228 | popd > /dev/null |
227 | popd > /dev/null |
|
|
228 | fi |
| 229 | } |
229 | } |
| 230 | |
230 | |
| 231 | # @FUNCTION: git-2_prepare_storedir |
231 | # @FUNCTION: git-2_prepare_storedir |
| 232 | # @DESCRIPTION: |
232 | # @DESCRIPTION: |
| 233 | # Internal function preparing directory where we are going to store SCM |
233 | # Internal function preparing directory where we are going to store SCM |
| … | |
… | |
| 288 | local repo_uri |
288 | local repo_uri |
| 289 | |
289 | |
| 290 | EGIT_REPO_URI_SELECTED="" |
290 | EGIT_REPO_URI_SELECTED="" |
| 291 | for repo_uri in ${EGIT_REPO_URI}; do |
291 | for repo_uri in ${EGIT_REPO_URI}; do |
| 292 | debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" |
292 | debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" |
| 293 | git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}" |
293 | 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 |
294 | # global variable containing the repo_name we will be using |
| 296 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
295 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
| 297 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
296 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
| 298 | break |
297 | break |
| 299 | fi |
298 | fi |
| … | |
… | |
| 324 | for repo_uri in ${EGIT_REPO_URI}; do |
323 | for repo_uri in ${EGIT_REPO_URI}; do |
| 325 | # git urls might change, so reset it |
324 | # git urls might change, so reset it |
| 326 | git config remote.origin.url "${repo_uri}" |
325 | git config remote.origin.url "${repo_uri}" |
| 327 | |
326 | |
| 328 | debug-print "${EGIT_UPDATE_CMD}" |
327 | debug-print "${EGIT_UPDATE_CMD}" |
| 329 | ${EGIT_UPDATE_CMD} > /dev/null |
328 | if ${EGIT_UPDATE_CMD} > /dev/null; then |
| 330 | if [[ $? -eq 0 ]]; then |
|
|
| 331 | # global variable containing the repo_name we will be using |
329 | # global variable containing the repo_name we will be using |
| 332 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
330 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
| 333 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
331 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
| 334 | break |
332 | break |
| 335 | fi |
333 | fi |
| … | |
… | |
| 447 | # This function also set some global variables that differ between |
445 | # This function also set some global variables that differ between |
| 448 | # bare and non-bare checkout. |
446 | # bare and non-bare checkout. |
| 449 | git-2_migrate_repository() { |
447 | git-2_migrate_repository() { |
| 450 | debug-print-function ${FUNCNAME} "$@" |
448 | debug-print-function ${FUNCNAME} "$@" |
| 451 | |
449 | |
| 452 | local target returnstate |
450 | local bare returnstate |
| 453 | |
451 | |
| 454 | # first find out if we have submodules |
452 | # first find out if we have submodules |
|
|
453 | # or user explicitly wants us to use non-bare clones |
| 455 | if [[ ! ${EGIT_HAS_SUBMODULES} ]]; then |
454 | if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then |
| 456 | target="bare" |
455 | 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 |
456 | fi |
| 465 | |
457 | |
| 466 | # test if we already have some repo and if so find out if we have |
458 | # test if we already have some repo and if so find out if we have |
| 467 | # to migrate the data |
459 | # to migrate the data |
| 468 | if [[ -d ${EGIT_DIR} ]]; then |
460 | if [[ -d ${EGIT_DIR} ]]; then |
| 469 | if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then |
461 | if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then |
| 470 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" |
462 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" |
| 471 | |
463 | |
| 472 | ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" |
464 | ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" |
| 473 | mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" |
465 | mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" |
| 474 | export GIT_DIR="${EGIT_DIR}.bare" |
466 | export GIT_DIR="${EGIT_DIR}.bare" |
| … | |
… | |
| 476 | returnstate=$? |
468 | returnstate=$? |
| 477 | unset GIT_DIR |
469 | unset GIT_DIR |
| 478 | rm -rf "${EGIT_DIR}" |
470 | rm -rf "${EGIT_DIR}" |
| 479 | mv "${EGIT_DIR}.bare" "${EGIT_DIR}" |
471 | mv "${EGIT_DIR}.bare" "${EGIT_DIR}" |
| 480 | eend ${returnstate} |
472 | eend ${returnstate} |
| 481 | fi |
|
|
| 482 | if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then |
473 | elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then |
| 483 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" |
474 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" |
| 484 | |
475 | |
| 485 | ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" |
476 | ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" |
| 486 | git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null |
477 | git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null |
| 487 | returnstate=$? |
478 | returnstate=$? |
| … | |
… | |
| 497 | einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." |
488 | einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." |
| 498 | rm -rf "${EGIT_DIR}" |
489 | rm -rf "${EGIT_DIR}" |
| 499 | fi |
490 | fi |
| 500 | |
491 | |
| 501 | # set various options to work with both targets |
492 | # set various options to work with both targets |
| 502 | if [[ ${target} == bare ]]; then |
493 | if [[ ${bare} ]]; then |
| 503 | debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" |
494 | debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" |
| 504 | EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" |
495 | EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" |
| 505 | MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" |
496 | MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" |
| 506 | EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" |
497 | EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" |
| 507 | UPSTREAM_BRANCH="${EGIT_BRANCH}" |
498 | UPSTREAM_BRANCH="${EGIT_BRANCH}" |