/[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.6 Revision 1.16
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2013 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.6 2013/09/19 09:37:14 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.16 2013/10/13 07:14:58 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.
27 27
28EXPORT_FUNCTIONS src_unpack 28EXPORT_FUNCTIONS src_unpack
29 29
30if [[ ! ${_GIT_R3} ]]; then 30if [[ ! ${_GIT_R3} ]]; then
31 31
32if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
33 DEPEND=">=dev-vcs/git-1.8.2.1"
34fi
35
32# @ECLASS-VARIABLE: EGIT3_STORE_DIR 36# @ECLASS-VARIABLE: EGIT3_STORE_DIR
33# @DESCRIPTION: 37# @DESCRIPTION:
34# Storage directory for git sources. 38# Storage directory for git sources.
35# 39#
36# EGIT3_STORE_DIR=${DISTDIR}/git3-src 40# EGIT3_STORE_DIR=${DISTDIR}/git3-src
41# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs 45# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
42# are provided, the eclass will consider them as fallback URIs to try 46# are provided, the eclass will consider them as fallback URIs to try
43# if the first URI does not work. 47# if the first URI does not work.
44# 48#
45# It can be overriden via env using ${PN}_LIVE_REPO variable. 49# It can be overriden via env using ${PN}_LIVE_REPO variable.
50#
51# Can be a whitespace-separated list or an array.
46# 52#
47# Example: 53# Example:
48# @CODE 54# @CODE
49# EGIT_REPO_URI="git://a/b.git https://c/d.git" 55# EGIT_REPO_URI="git://a/b.git https://c/d.git"
50# @CODE 56# @CODE
82# @DESCRIPTION: 88# @DESCRIPTION:
83# Disable performing shallow fetches/clones. Shallow clones have 89# Disable performing shallow fetches/clones. Shallow clones have
84# a fair number of limitations. Therefore, if you'd like the eclass to 90# a fair number of limitations. Therefore, if you'd like the eclass to
85# perform complete clones instead, set this to a non-null value. 91# perform complete clones instead, set this to a non-null value.
86# 92#
87# This variable is to be set in make.conf. Ebuilds are not allowed 93# This variable can be set in make.conf and ebuilds. The make.conf
88# to set it. 94# value specifies user-specific default, while ebuilds may use it
95# to force deep clones when the server does not support shallow clones
96# (e.g. Google Code).
89 97
90# @FUNCTION: _git-r3_env_setup 98# @FUNCTION: _git-r3_env_setup
91# @INTERNAL 99# @INTERNAL
92# @DESCRIPTION: 100# @DESCRIPTION:
93# Set the eclass variables as necessary for operation. This can involve 101# Set the eclass variables as necessary for operation. This can involve
169_git-r3_set_gitdir() { 177_git-r3_set_gitdir() {
170 debug-print-function ${FUNCNAME} "$@" 178 debug-print-function ${FUNCNAME} "$@"
171 179
172 local repo_name=${1#*://*/} 180 local repo_name=${1#*://*/}
173 181
182 # strip the trailing slash
183 repo_name=${repo_name%/}
184
174 # strip common prefixes to make paths more likely to match 185 # strip common prefixes to make paths more likely to match
175 # e.g. git://X/Y.git vs https://X/git/Y.git 186 # e.g. git://X/Y.git vs https://X/git/Y.git
176 # (but just one of the prefixes) 187 # (but just one of the prefixes)
177 case "${repo_name}" in 188 case "${repo_name}" in
189 # gnome.org... who else?
190 browse/*) repo_name=${repo_name#browse/};;
178 # cgit can proxy requests to git 191 # cgit can proxy requests to git
179 cgit/*) repo_name=${repo_name#cgit/};; 192 cgit/*) repo_name=${repo_name#cgit/};;
180 # pretty common 193 # pretty common
181 git/*) repo_name=${repo_name#git/};; 194 git/*) repo_name=${repo_name#git/};;
182 # gentoo.org 195 # gentoo.org
237 [[ ${l} == submodule.*.url=* ]] || continue 250 [[ ${l} == submodule.*.url=* ]] || continue
238 251
239 l=${l#submodule.} 252 l=${l#submodule.}
240 local subname=${l%%.url=*} 253 local subname=${l%%.url=*}
241 254
255 # skip modules that have 'update = none', bug #487262.
256 local upd=$(echo "${data}" | git config -f /dev/fd/0 \
257 submodule."${subname}".update)
258 [[ ${upd} == none ]] && continue
259
242 submodules+=( 260 submodules+=(
243 "${subname}" 261 "${subname}"
244 "$(echo "${data}" | git config -f /dev/fd/0 \ 262 "$(echo "${data}" | git config -f /dev/fd/0 \
245 submodule."${subname}".url)" 263 submodule."${subname}".url)"
246 "$(echo "${data}" | git config -f /dev/fd/0 \ 264 "$(echo "${data}" | git config -f /dev/fd/0 \
365# If the repository contains submodules, they will be fetched 383# If the repository contains submodules, they will be fetched
366# recursively. 384# recursively.
367git-r3_fetch() { 385git-r3_fetch() {
368 debug-print-function ${FUNCNAME} "$@" 386 debug-print-function ${FUNCNAME} "$@"
369 387
388 [[ ${EVCS_OFFLINE} ]] && return
389
390 local repos
391 if [[ ${1} ]]; then
392 repos=( ${1} )
393 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
394 repos=( "${EGIT_REPO_URI[@]}" )
395 else
370 local repos=( ${1:-${EGIT_REPO_URI}} ) 396 repos=( ${EGIT_REPO_URI} )
397 fi
398
371 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 399 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
372 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 400 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
373 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 401 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
374 local local_ref=refs/heads/${local_id}/__main__ 402 local local_ref=refs/heads/${local_id}/__main__
375 403
376 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 404 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
377 405
378 local -x GIT_DIR 406 local -x GIT_DIR
379 _git-r3_set_gitdir ${repos[0]} 407 _git-r3_set_gitdir "${repos[0]}"
380 408
381 # try to fetch from the remote 409 # try to fetch from the remote
382 local r success 410 local r success
383 for r in ${repos[@]}; do 411 for r in "${repos[@]}"; do
384 einfo "Fetching ${remote_ref} from ${r} ..." 412 einfo "Fetching ${remote_ref} from ${r} ..."
385 413
386 local is_branch lookup_ref 414 local is_branch lookup_ref
387 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 415 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
388 then 416 then
426 local fetch_command=( git fetch ) 454 local fetch_command=( git fetch )
427 if [[ ${nonshallow} ]]; then 455 if [[ ${nonshallow} ]]; then
428 if [[ -f ${GIT_DIR}/shallow ]]; then 456 if [[ -f ${GIT_DIR}/shallow ]]; then
429 ref_param+=( --unshallow ) 457 ref_param+=( --unshallow )
430 fi 458 fi
459 # fetch all branches
460 ref_param+=( "refs/heads/*:refs/remotes/origin/*" )
431 else 461 else
432 # 'git show-ref --heads' returns 1 when there are no branches 462 # 'git show-ref --heads' returns 1 when there are no branches
433 if ! git show-ref --heads -q; then 463 if ! git show-ref --heads -q; then
434 ref_param+=( --depth 1 ) 464 ref_param+=( --depth 1 )
435 else 465 else
514# the repository state into the environment. If the repository contains 544# the repository state into the environment. If the repository contains
515# submodules, they will be checked out recursively. 545# submodules, they will be checked out recursively.
516git-r3_checkout() { 546git-r3_checkout() {
517 debug-print-function ${FUNCNAME} "$@" 547 debug-print-function ${FUNCNAME} "$@"
518 548
549 local repos
550 if [[ ${1} ]]; then
551 repos=( ${1} )
552 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
553 repos=( "${EGIT_REPO_URI[@]}" )
554 else
519 local repos=( ${1:-${EGIT_REPO_URI}} ) 555 repos=( ${EGIT_REPO_URI} )
556 fi
557
520 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 558 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
521 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 559 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
522 560
523 local -x GIT_DIR GIT_WORK_TREE 561 local -x GIT_DIR GIT_WORK_TREE
524 _git-r3_set_gitdir ${repos[0]} 562 _git-r3_set_gitdir "${repos[0]}"
525 GIT_WORK_TREE=${out_dir} 563 GIT_WORK_TREE=${out_dir}
526 mkdir -p "${GIT_WORK_TREE}" 564 mkdir -p "${GIT_WORK_TREE}"
527 565
528 einfo "Checking out ${repos[0]} to ${out_dir} ..." 566 einfo "Checking out ${repos[0]} to ${out_dir} ..."
529 567
611# On success, the function returns 0 and writes hexadecimal commit SHA1 649# On success, the function returns 0 and writes hexadecimal commit SHA1
612# to stdout. On failure, the function returns 1. 650# to stdout. On failure, the function returns 1.
613git-r3_peek_remote_ref() { 651git-r3_peek_remote_ref() {
614 debug-print-function ${FUNCNAME} "$@" 652 debug-print-function ${FUNCNAME} "$@"
615 653
654 local repos
655 if [[ ${1} ]]; then
656 repos=( ${1} )
657 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
658 repos=( "${EGIT_REPO_URI[@]}" )
659 else
616 local repos=( ${1:-${EGIT_REPO_URI}} ) 660 repos=( ${EGIT_REPO_URI} )
661 fi
662
617 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 663 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
618 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 664 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
619 665
620 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 666 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
621 667
622 local r success 668 local r success
623 for r in ${repos[@]}; do 669 for r in "${repos[@]}"; do
624 einfo "Peeking ${remote_ref} on ${r} ..." >&2 670 einfo "Peeking ${remote_ref} on ${r} ..." >&2
625 671
626 local is_branch lookup_ref 672 local is_branch lookup_ref
627 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 673 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
628 then 674 then
649} 695}
650 696
651git-r3_src_fetch() { 697git-r3_src_fetch() {
652 debug-print-function ${FUNCNAME} "$@" 698 debug-print-function ${FUNCNAME} "$@"
653 699
654 [[ ${EVCS_OFFLINE} ]] && return
655
656 if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then 700 if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then
657 ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider" 701 ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider"
658 ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use" 702 ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use"
659 ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones" 703 ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones"
660 ewarn "when git-2 eclass becomes deprecated." 704 ewarn "when git-2 eclass becomes deprecated."

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.20