/[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.33
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.33 2014/03/02 11:48: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}
54 60
55# @ECLASS-VARIABLE: EGIT3_STORE_DIR 61# @ECLASS-VARIABLE: EGIT3_STORE_DIR
56# @DESCRIPTION: 62# @DESCRIPTION:
57# Storage directory for git sources. 63# Storage directory for git sources.
127_git-r3_env_setup() { 133_git-r3_env_setup() {
128 debug-print-function ${FUNCNAME} "$@" 134 debug-print-function ${FUNCNAME} "$@"
129 135
130 # check the clone type 136 # check the clone type
131 case "${EGIT_CLONE_TYPE}" in 137 case "${EGIT_CLONE_TYPE}" in
132 mirror|single) 138 mirror|single|shallow)
133 ;; 139 ;;
134 *) 140 *)
135 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 141 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
136 esac 142 esac
137 143
247 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die 253 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die
248 ) || die "Unable to create ${EGIT3_STORE_DIR}" 254 ) || die "Unable to create ${EGIT3_STORE_DIR}"
249 fi 255 fi
250 256
251 addwrite "${EGIT3_STORE_DIR}" 257 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 258 if [[ ! -d ${GIT_DIR} ]]; then
257 mkdir "${GIT_DIR}" || die 259 mkdir "${GIT_DIR}" || die
258 git init --bare || die 260 git init --bare || die
259 fi 261 fi
260} 262}
426 "refs/notes/*:refs/notes/*" 428 "refs/notes/*:refs/notes/*"
427 # and HEAD in case we need the default branch 429 # and HEAD in case we need the default branch
428 # (we keep it in refs/git-r3 since otherwise --prune interferes) 430 # (we keep it in refs/git-r3 since otherwise --prune interferes)
429 HEAD:refs/git-r3/HEAD 431 HEAD:refs/git-r3/HEAD
430 ) 432 )
431 else # single 433 else # single or shallow
432 local fetch_l fetch_r 434 local fetch_l fetch_r
433 435
434 if [[ ${remote_ref} == HEAD ]]; then 436 if [[ ${remote_ref} == HEAD ]]; then
435 # HEAD 437 # HEAD
436 fetch_l=HEAD 438 fetch_l=HEAD
466 fetch_command+=( 468 fetch_command+=(
467 "${fetch_l}:${fetch_r}" 469 "${fetch_l}:${fetch_r}"
468 ) 470 )
469 fi 471 fi
470 472
473 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
474 # use '--depth 1' when fetching a new branch
475 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
476 then
477 fetch_command+=( --depth 1 )
478 fi
479 else # non-shallow mode
480 if [[ -f ${GIT_DIR}/shallow ]]; then
481 fetch_command+=( --unshallow )
482 fi
483 fi
484
471 set -- "${fetch_command[@]}" 485 set -- "${fetch_command[@]}"
472 echo "${@}" >&2 486 echo "${@}" >&2
473 if "${@}"; then 487 if "${@}"; then
474 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 488 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then
475 # find remote HEAD and update our HEAD properly 489 # find remote HEAD and update our HEAD properly
476 git symbolic-ref HEAD \ 490 git symbolic-ref HEAD \
477 "$(_git-r3_find_head refs/git-r3/HEAD \ 491 "$(_git-r3_find_head refs/git-r3/HEAD \
478 < <(git show-ref --heads || die))" \ 492 < <(git show-ref --heads || die))" \
479 || die "Unable to update HEAD" 493 || die "Unable to update HEAD"
480 else # single 494 else # single or shallow
481 if [[ ${fetch_l} == HEAD ]]; then 495 if [[ ${fetch_l} == HEAD ]]; then
482 # find out what branch we fetched as HEAD 496 # find out what branch we fetched as HEAD
483 local head_branch=$(_git-r3_find_head \ 497 local head_branch=$(_git-r3_find_head \
484 refs/git-r3/HEAD \ 498 refs/git-r3/HEAD \
485 < <(git ls-remote --heads "${r}" || die)) 499 < <(git ls-remote --heads "${r}" || die))
617 # [htn]* safely catches heads, tags, notes without complaining 631 # [htn]* safely catches heads, tags, notes without complaining
618 # on non-existing ones, and omits internal 'git-r3' ref 632 # on non-existing ones, and omits internal 'git-r3' ref
619 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die 633 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
620 634
621 # (no need to copy HEAD, we will set it via checkout) 635 # (no need to copy HEAD, we will set it via checkout)
636
637 if [[ -f ${orig_repo}/shallow ]]; then
638 cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die
639 fi
622 640
623 set -- git checkout --quiet 641 set -- git checkout --quiet
624 if [[ ${remote_ref} ]]; then 642 if [[ ${remote_ref} ]]; then
625 set -- "${@}" "${remote_ref#refs/heads/}" 643 set -- "${@}" "${remote_ref#refs/heads/}"
626 else 644 else

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

  ViewVC Help
Powered by ViewVC 1.1.20