/[gentoo-x86]/eclass/git-r3.eclass
Gentoo

Diff of /eclass/git-r3.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.35 Revision 1.42
1# Copyright 1999-2014 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-r3.eclass,v 1.35 2014/03/02 11:49:05 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.42 2014/05/23 07:09:07 mgorny Exp $
4 4
5# @ECLASS: git-r3.eclass 5# @ECLASS: git-r3.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Michał Górny <mgorny@gentoo.org> 7# Michał Górny <mgorny@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 8# @BLURB: Eclass for fetching and unpacking git repositories.
35# @ECLASS-VARIABLE: EGIT_CLONE_TYPE 35# @ECLASS-VARIABLE: EGIT_CLONE_TYPE
36# @DESCRIPTION: 36# @DESCRIPTION:
37# Type of clone that should be used against the remote repository. 37# Type of clone that should be used against the remote repository.
38# This can be either of: 'mirror', 'single', 'shallow'. 38# This can be either of: 'mirror', 'single', 'shallow'.
39# 39#
40# This is intended to be set by user in make.conf. Ebuilds are supposed
41# to set EGIT_MIN_CLONE_TYPE if necessary instead.
42#
40# The 'mirror' type clones all remote branches and tags with complete 43# The 'mirror' type clones all remote branches and tags with complete
41# history and all notes. EGIT_COMMIT can specify any commit hash. 44# history and all notes. EGIT_COMMIT can specify any commit hash.
42# Upstream-removed branches and tags are purged from the local clone 45# Upstream-removed branches and tags are purged from the local clone
43# while fetching. This mode is suitable for cloning the local copy 46# while fetching. This mode is suitable for cloning the local copy
44# for development or hosting a local git mirror. However, clones 47# for development or hosting a local git mirror. However, clones
45# of repositories with large diverged branches may quickly grow large. 48# of repositories with large diverged branches may quickly grow large.
46# 49#
50# The 'single+tags' type clones the requested branch and all tags
51# in the repository. All notes are fetched as well. EGIT_COMMIT
52# can safely specify hashes throughout the current branch and all tags.
53# No purging of old references is done (if you often switch branches,
54# you may need to remove stale branches yourself). This mode is intended
55# mostly for use with broken git servers such as Google Code that fail
56# to fetch tags along with the branch in 'single' mode.
57#
47# The 'single' type clones only the requested branch or tag. Tags 58# The 'single' type clones only the requested branch or tag. Tags
48# referencing commits throughout the branch history are fetched as well, 59# referencing commits throughout the branch history are fetched as well,
49# and all notes. EGIT_COMMIT can safely specify only hashes 60# and all notes. EGIT_COMMIT can safely specify only hashes
50# in the current branch. No purging of old references is done (if you 61# in the current branch. No purging of old references is done (if you
51# often switch branches, you may need to remove stale branches 62# often switch branches, you may need to remove stale branches
63# 'Minimum' clone type supported by the ebuild. Takes same values 74# 'Minimum' clone type supported by the ebuild. Takes same values
64# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is, 75# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is,
65# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses 76# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
66# EGIT_MIN_CLONE_TYPE instead. 77# EGIT_MIN_CLONE_TYPE instead.
67# 78#
79# This variable is intended to be used by ebuilds only. Users are
80# supposed to set EGIT_CLONE_TYPE instead.
81#
68# A common case is to use 'single' whenever the build system requires 82# A common case is to use 'single' whenever the build system requires
69# access to full branch history or the remote (Google Code) does not 83# access to full branch history, or 'single+tags' when Google Code
70# support shallow clones. Please use sparingly, and to fix fatal errors 84# or a similar remote is used that does not support shallow clones
85# and fetching tags along with commits. Please use sparingly, and to fix
71# rather than 'non-pretty versions'. 86# fatal errors rather than 'non-pretty versions'.
72: ${EGIT_MIN_CLONE_TYPE:=shallow} 87: ${EGIT_MIN_CLONE_TYPE:=shallow}
73 88
74# @ECLASS-VARIABLE: EGIT3_STORE_DIR 89# @ECLASS-VARIABLE: EGIT3_STORE_DIR
75# @DESCRIPTION: 90# @DESCRIPTION:
76# Storage directory for git sources. 91# Storage directory for git sources.
146_git-r3_env_setup() { 161_git-r3_env_setup() {
147 debug-print-function ${FUNCNAME} "$@" 162 debug-print-function ${FUNCNAME} "$@"
148 163
149 # check the clone type 164 # check the clone type
150 case "${EGIT_CLONE_TYPE}" in 165 case "${EGIT_CLONE_TYPE}" in
151 mirror|single|shallow) 166 mirror|single+tags|single|shallow)
152 ;; 167 ;;
153 *) 168 *)
154 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 169 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
155 esac 170 esac
156 case "${EGIT_MIN_CLONE_TYPE}" in 171 case "${EGIT_MIN_CLONE_TYPE}" in
158 ;; 173 ;;
159 single) 174 single)
160 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 175 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
161 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting" 176 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
162 EGIT_CLONE_TYPE=single 177 EGIT_CLONE_TYPE=single
178 fi
179 ;;
180 single+tags)
181 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
182 einfo "git-r3: ebuild needs to be cloned in 'single+tags' mode, adjusting"
183 EGIT_CLONE_TYPE=single+tags
163 fi 184 fi
164 ;; 185 ;;
165 mirror) 186 mirror)
166 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then 187 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
167 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting" 188 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
445 local r success 466 local r success
446 for r in "${repos[@]}"; do 467 for r in "${repos[@]}"; do
447 einfo "Fetching ${r} ..." 468 einfo "Fetching ${r} ..."
448 469
449 local fetch_command=( git fetch "${r}" ) 470 local fetch_command=( git fetch "${r}" )
471 local clone_type=${EGIT_CLONE_TYPE}
450 472
451 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 473 if [[ ${r} == https://* ]] && ! has_version 'dev-vcs/git[curl]'; then
474 eerror "git-r3: fetching from https:// requested. In order to support https,"
475 eerror "dev-vcs/git needs to be built with USE=curl. Example solution:"
476 eerror
477 eerror " echo dev-vcs/git curl >> /etc/portage/package.use"
478 eerror " emerge -1v dev-vcs/git"
479 die "dev-vcs/git built with USE=curl required."
480 fi
481
482 if [[ ${r} == https://code.google.com/* ]]; then
483 # Google Code has special magic on top of git that:
484 # 1) can't handle shallow clones at all,
485 # 2) fetches duplicately when tags are pulled in with branch
486 # so automatically switch to single+tags mode.
487 if [[ ${clone_type} == shallow ]]; then
488 einfo " Google Code does not support shallow clones"
489 einfo " using EGIT_CLONE_TYPE=single+tags"
490 clone_type=single+tags
491 elif [[ ${clone_type} == single ]]; then
492 einfo " git-r3: Google Code does not send tags properly in 'single' mode"
493 einfo " using EGIT_CLONE_TYPE=single+tags"
494 clone_type=single+tags
495 fi
496 fi
497
498 if [[ ${clone_type} == mirror ]]; then
452 fetch_command+=( 499 fetch_command+=(
453 --prune 500 --prune
454 # mirror the remote branches as local branches 501 # mirror the remote branches as local branches
455 "refs/heads/*:refs/heads/*" 502 "+refs/heads/*:refs/heads/*"
456 # pull tags explicitly in order to prune them properly 503 # pull tags explicitly in order to prune them properly
457 "refs/tags/*:refs/tags/*" 504 "+refs/tags/*:refs/tags/*"
458 # notes in case something needs them 505 # notes in case something needs them
459 "refs/notes/*:refs/notes/*" 506 "+refs/notes/*:refs/notes/*"
460 # and HEAD in case we need the default branch 507 # and HEAD in case we need the default branch
461 # (we keep it in refs/git-r3 since otherwise --prune interferes) 508 # (we keep it in refs/git-r3 since otherwise --prune interferes)
462 HEAD:refs/git-r3/HEAD 509 "+HEAD:refs/git-r3/HEAD"
463 ) 510 )
464 else # single or shallow 511 else # single or shallow
465 local fetch_l fetch_r 512 local fetch_l fetch_r
466 513
467 if [[ ${remote_ref} == HEAD ]]; then 514 if [[ ${remote_ref} == HEAD ]]; then
487 else 534 else
488 fetch_l=HEAD 535 fetch_l=HEAD
489 fi 536 fi
490 537
491 # fetching by commit in shallow mode? can't do. 538 # fetching by commit in shallow mode? can't do.
492 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 539 if [[ ${clone_type} == shallow ]]; then
493 local EGIT_CLONE_TYPE=single 540 clone_type=single
494 fi 541 fi
495 fi 542 fi
496 fi 543 fi
497 544
498 if [[ ${fetch_l} == HEAD ]]; then 545 if [[ ${fetch_l} == HEAD ]]; then
500 else 547 else
501 fetch_r=${fetch_l} 548 fetch_r=${fetch_l}
502 fi 549 fi
503 550
504 fetch_command+=( 551 fetch_command+=(
505 "${fetch_l}:${fetch_r}" 552 "+${fetch_l}:${fetch_r}"
506 ) 553 )
554
555 if [[ ${clone_type} == single+tags ]]; then
556 fetch_command+=(
557 # pull tags explicitly as requested
558 "+refs/tags/*:refs/tags/*"
559 )
507 fi 560 fi
561 fi
508 562
509 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 563 if [[ ${clone_type} == shallow ]]; then
510 # use '--depth 1' when fetching a new branch 564 if _git-r3_is_local_repo; then
565 # '--depth 1' causes sandbox violations with local repos
566 # bug #491260
567 clone_type=single
511 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] 568 elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
512 then 569 then
570 # use '--depth 1' when fetching a new branch
513 fetch_command+=( --depth 1 ) 571 fetch_command+=( --depth 1 )
514 fi 572 fi
515 else # non-shallow mode 573 else # non-shallow mode
516 if [[ -f ${GIT_DIR}/shallow ]]; then 574 if [[ -f ${GIT_DIR}/shallow ]]; then
517 fetch_command+=( --unshallow ) 575 fetch_command+=( --unshallow )
519 fi 577 fi
520 578
521 set -- "${fetch_command[@]}" 579 set -- "${fetch_command[@]}"
522 echo "${@}" >&2 580 echo "${@}" >&2
523 if "${@}"; then 581 if "${@}"; then
524 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 582 if [[ ${clone_type} == mirror ]]; then
525 # find remote HEAD and update our HEAD properly 583 # find remote HEAD and update our HEAD properly
526 git symbolic-ref HEAD \ 584 git symbolic-ref HEAD \
527 "$(_git-r3_find_head refs/git-r3/HEAD \ 585 "$(_git-r3_find_head refs/git-r3/HEAD \
528 < <(git show-ref --heads || die))" \ 586 < <(git show-ref --heads || die))" \
529 || die "Unable to update HEAD" 587 || die "Unable to update HEAD"
565 success=1 623 success=1
566 break 624 break
567 fi 625 fi
568 done 626 done
569 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 627 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
628
629 # submodules can reference commits in any branch
630 # always use the 'clone' mode to accomodate that, bug #503332
631 local EGIT_CLONE_TYPE=mirror
570 632
571 # recursively fetch submodules 633 # recursively fetch submodules
572 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then 634 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
573 local submodules 635 local submodules
574 _git-r3_set_submodules \ 636 _git-r3_set_submodules \

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.42

  ViewVC Help
Powered by ViewVC 1.1.20