/[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.32 Revision 1.35
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.32 2014/03/02 11:47:41 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.35 2014/03/02 11:49:05 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.
27EXPORT_FUNCTIONS src_unpack 27EXPORT_FUNCTIONS src_unpack
28 28
29if [[ ! ${_GIT_R3} ]]; then 29if [[ ! ${_GIT_R3} ]]; then
30 30
31if [[ ! ${_INHERITED_BY_GIT_2} ]]; then 31if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
32 DEPEND="dev-vcs/git" 32 DEPEND=">=dev-vcs/git-1.8.2.1"
33fi 33fi
34 34
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'. 38# This can be either of: 'mirror', 'single', 'shallow'.
39# 39#
40# The 'mirror' type clones all remote branches and tags with complete 40# The 'mirror' type clones all remote branches and tags with complete
41# history and all notes. EGIT_COMMIT can specify any commit hash. 41# history and all notes. EGIT_COMMIT can specify any commit hash.
42# Upstream-removed branches and tags are purged from the local clone 42# Upstream-removed branches and tags are purged from the local clone
43# while fetching. This mode is suitable for cloning the local copy 43# while fetching. This mode is suitable for cloning the local copy
48# referencing commits throughout the branch history are fetched as well, 48# referencing commits throughout the branch history are fetched as well,
49# and all notes. EGIT_COMMIT can safely specify only hashes 49# and all notes. EGIT_COMMIT can safely specify only hashes
50# in the current branch. No purging of old references is done (if you 50# in the current branch. No purging of old references is done (if you
51# often switch branches, you may need to remove stale branches 51# often switch branches, you may need to remove stale branches
52# yourself). This mode is suitable for general use. 52# yourself). This mode is suitable for general use.
53#
54# The 'shallow' type clones only the newest commit on requested branch
55# or tag. EGIT_COMMIT can only specify tags, and since the history is
56# unavailable calls like 'git describe' will not reference prior tags.
57# No purging of old references is done. This mode is intended mostly for
58# embedded systems with limited disk space.
53: ${EGIT_CLONE_TYPE:=single} 59: ${EGIT_CLONE_TYPE:=single}
60
61# @ECLASS-VARIABLE: EGIT_MIN_CLONE_TYPE
62# @DESCRIPTION:
63# '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,
65# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
66# EGIT_MIN_CLONE_TYPE instead.
67#
68# 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
70# support shallow clones. Please use sparingly, and to fix fatal errors
71# rather than 'non-pretty versions'.
72: ${EGIT_MIN_CLONE_TYPE:=shallow}
54 73
55# @ECLASS-VARIABLE: EGIT3_STORE_DIR 74# @ECLASS-VARIABLE: EGIT3_STORE_DIR
56# @DESCRIPTION: 75# @DESCRIPTION:
57# Storage directory for git sources. 76# Storage directory for git sources.
58# 77#
127_git-r3_env_setup() { 146_git-r3_env_setup() {
128 debug-print-function ${FUNCNAME} "$@" 147 debug-print-function ${FUNCNAME} "$@"
129 148
130 # check the clone type 149 # check the clone type
131 case "${EGIT_CLONE_TYPE}" in 150 case "${EGIT_CLONE_TYPE}" in
132 mirror|single) 151 mirror|single|shallow)
133 ;; 152 ;;
134 *) 153 *)
135 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 154 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
155 esac
156 case "${EGIT_MIN_CLONE_TYPE}" in
157 shallow)
158 ;;
159 single)
160 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
161 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
162 EGIT_CLONE_TYPE=single
163 fi
164 ;;
165 mirror)
166 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
167 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
168 EGIT_CLONE_TYPE=mirror
169 fi
170 ;;
171 *)
172 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
136 esac 173 esac
137 174
138 local esc_pn livevar 175 local esc_pn livevar
139 esc_pn=${PN//[-+]/_} 176 esc_pn=${PN//[-+]/_}
140 177
247 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die 284 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die
248 ) || die "Unable to create ${EGIT3_STORE_DIR}" 285 ) || die "Unable to create ${EGIT3_STORE_DIR}"
249 fi 286 fi
250 287
251 addwrite "${EGIT3_STORE_DIR}" 288 addwrite "${EGIT3_STORE_DIR}"
252 if [[ -e ${GIT_DIR}/shallow ]]; then
253 einfo "${GIT_DIR} was a shallow clone, recreating..."
254 rm -r "${GIT_DIR}" || die
255 fi
256 if [[ ! -d ${GIT_DIR} ]]; then 289 if [[ ! -d ${GIT_DIR} ]]; then
257 mkdir "${GIT_DIR}" || die 290 mkdir "${GIT_DIR}" || die
258 git init --bare || die 291 git init --bare || die
259 fi 292 fi
260} 293}
426 "refs/notes/*:refs/notes/*" 459 "refs/notes/*:refs/notes/*"
427 # and HEAD in case we need the default branch 460 # and HEAD in case we need the default branch
428 # (we keep it in refs/git-r3 since otherwise --prune interferes) 461 # (we keep it in refs/git-r3 since otherwise --prune interferes)
429 HEAD:refs/git-r3/HEAD 462 HEAD:refs/git-r3/HEAD
430 ) 463 )
431 else # single 464 else # single or shallow
432 local fetch_l fetch_r 465 local fetch_l fetch_r
433 466
434 if [[ ${remote_ref} == HEAD ]]; then 467 if [[ ${remote_ref} == HEAD ]]; then
435 # HEAD 468 # HEAD
436 fetch_l=HEAD 469 fetch_l=HEAD
445 # if it was a tag, ls-remote obtained a hash 478 # if it was a tag, ls-remote obtained a hash
446 if [[ ${tagref} ]]; then 479 if [[ ${tagref} ]]; then
447 # tag 480 # tag
448 fetch_l=refs/tags/${remote_ref} 481 fetch_l=refs/tags/${remote_ref}
449 else 482 else
483 # commit
450 # commit, so we need to fetch the branch 484 # so we need to fetch the branch
451 # and guess where it takes us...
452 if [[ ${branch} ]]; then 485 if [[ ${branch} ]]; then
453 fetch_l=${branch} 486 fetch_l=${branch}
454 else 487 else
455 fetch_l=HEAD 488 fetch_l=HEAD
456 fi 489 fi
490
491 # fetching by commit in shallow mode? can't do.
492 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
493 local EGIT_CLONE_TYPE=single
494 fi
457 fi 495 fi
458 fi 496 fi
459 497
460 if [[ ${fetch_l} == HEAD ]]; then 498 if [[ ${fetch_l} == HEAD ]]; then
461 fetch_r=refs/git-r3/HEAD 499 fetch_r=refs/git-r3/HEAD
464 fi 502 fi
465 503
466 fetch_command+=( 504 fetch_command+=(
467 "${fetch_l}:${fetch_r}" 505 "${fetch_l}:${fetch_r}"
468 ) 506 )
507 fi
508
509 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
510 # use '--depth 1' when fetching a new branch
511 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
512 then
513 fetch_command+=( --depth 1 )
514 fi
515 else # non-shallow mode
516 if [[ -f ${GIT_DIR}/shallow ]]; then
517 fetch_command+=( --unshallow )
518 fi
469 fi 519 fi
470 520
471 set -- "${fetch_command[@]}" 521 set -- "${fetch_command[@]}"
472 echo "${@}" >&2 522 echo "${@}" >&2
473 if "${@}"; then 523 if "${@}"; then
475 # find remote HEAD and update our HEAD properly 525 # find remote HEAD and update our HEAD properly
476 git symbolic-ref HEAD \ 526 git symbolic-ref HEAD \
477 "$(_git-r3_find_head refs/git-r3/HEAD \ 527 "$(_git-r3_find_head refs/git-r3/HEAD \
478 < <(git show-ref --heads || die))" \ 528 < <(git show-ref --heads || die))" \
479 || die "Unable to update HEAD" 529 || die "Unable to update HEAD"
480 else # single 530 else # single or shallow
481 if [[ ${fetch_l} == HEAD ]]; then 531 if [[ ${fetch_l} == HEAD ]]; then
482 # find out what branch we fetched as HEAD 532 # find out what branch we fetched as HEAD
483 local head_branch=$(_git-r3_find_head \ 533 local head_branch=$(_git-r3_find_head \
484 refs/git-r3/HEAD \ 534 refs/git-r3/HEAD \
485 < <(git ls-remote --heads "${r}" || die)) 535 < <(git ls-remote --heads "${r}" || die))
617 # [htn]* safely catches heads, tags, notes without complaining 667 # [htn]* safely catches heads, tags, notes without complaining
618 # on non-existing ones, and omits internal 'git-r3' ref 668 # on non-existing ones, and omits internal 'git-r3' ref
619 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die 669 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
620 670
621 # (no need to copy HEAD, we will set it via checkout) 671 # (no need to copy HEAD, we will set it via checkout)
672
673 if [[ -f ${orig_repo}/shallow ]]; then
674 cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die
675 fi
622 676
623 set -- git checkout --quiet 677 set -- git checkout --quiet
624 if [[ ${remote_ref} ]]; then 678 if [[ ${remote_ref} ]]; then
625 set -- "${@}" "${remote_ref#refs/heads/}" 679 set -- "${@}" "${remote_ref#refs/heads/}"
626 else 680 else

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

  ViewVC Help
Powered by ViewVC 1.1.20