/[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.4 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.4 2013/09/13 15:04:36 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
206 addwrite "${EGIT3_STORE_DIR}" 219 addwrite "${EGIT3_STORE_DIR}"
207 if [[ ! -d ${GIT_DIR} ]]; then 220 if [[ ! -d ${GIT_DIR} ]]; then
208 mkdir "${GIT_DIR}" || die 221 mkdir "${GIT_DIR}" || die
209 git init --bare || die 222 git init --bare || die
210 223
224 if [[ ! ${EGIT_NONSHALLOW} ]]; then
211 # avoid auto-unshallow :) 225 # avoid auto-unshallow :)
212 touch "${GIT_DIR}"/shallow || die 226 touch "${GIT_DIR}"/shallow || die
227 fi
213 fi 228 fi
214} 229}
215 230
216# @FUNCTION: _git-r3_set_submodules 231# @FUNCTION: _git-r3_set_submodules
217# @USAGE: <file-contents> 232# @USAGE: <file-contents>
234 # submodule.<path>.url=<url> 249 # submodule.<path>.url=<url>
235 [[ ${l} == submodule.*.url=* ]] || continue 250 [[ ${l} == submodule.*.url=* ]] || continue
236 251
237 l=${l#submodule.} 252 l=${l#submodule.}
238 local subname=${l%%.url=*} 253 local subname=${l%%.url=*}
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
239 259
240 submodules+=( 260 submodules+=(
241 "${subname}" 261 "${subname}"
242 "$(echo "${data}" | git config -f /dev/fd/0 \ 262 "$(echo "${data}" | git config -f /dev/fd/0 \
243 submodule."${subname}".url)" 263 submodule."${subname}".url)"
363# If the repository contains submodules, they will be fetched 383# If the repository contains submodules, they will be fetched
364# recursively. 384# recursively.
365git-r3_fetch() { 385git-r3_fetch() {
366 debug-print-function ${FUNCNAME} "$@" 386 debug-print-function ${FUNCNAME} "$@"
367 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
368 local repos=( ${1:-${EGIT_REPO_URI}} ) 396 repos=( ${EGIT_REPO_URI} )
397 fi
398
369 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 399 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
370 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 400 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
371 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 401 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
372 local local_ref=refs/heads/${local_id}/__main__ 402 local local_ref=refs/heads/${local_id}/__main__
373 403
374 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 404 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
375 405
376 local -x GIT_DIR 406 local -x GIT_DIR
377 _git-r3_set_gitdir ${repos[0]} 407 _git-r3_set_gitdir "${repos[0]}"
378 408
379 # try to fetch from the remote 409 # try to fetch from the remote
380 local r success 410 local r success
381 for r in ${repos[@]}; do 411 for r in "${repos[@]}"; do
382 einfo "Fetching ${remote_ref} from ${r} ..." 412 einfo "Fetching ${remote_ref} from ${r} ..."
383 413
384 local is_branch lookup_ref 414 local is_branch lookup_ref
385 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 415 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
386 then 416 then
396 # and not a commit id. if it succeeds, we can pass ${remote_ref} 426 # and not a commit id. if it succeeds, we can pass ${remote_ref}
397 # to 'fetch'. otherwise, we will just fetch everything 427 # to 'fetch'. otherwise, we will just fetch everything
398 428
399 # split on whitespace 429 # split on whitespace
400 local ref=( 430 local ref=(
401 $(git ls-remote "${r}" "${lookup_ref}") 431 $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
402 ) 432 )
433
434 # normally, ref[0] is a hash, so we can do magic strings here
435 [[ ${ref[0]} == __FAIL__ ]] && continue
403 436
404 local nonshallow=${EGIT_NONSHALLOW} 437 local nonshallow=${EGIT_NONSHALLOW}
405 local ref_param=() 438 local ref_param=()
406 if [[ ! ${ref[0]} ]]; then 439 if [[ ! ${ref[0]} ]]; then
407 nonshallow=1 440 nonshallow=1
421 local fetch_command=( git fetch ) 454 local fetch_command=( git fetch )
422 if [[ ${nonshallow} ]]; then 455 if [[ ${nonshallow} ]]; then
423 if [[ -f ${GIT_DIR}/shallow ]]; then 456 if [[ -f ${GIT_DIR}/shallow ]]; then
424 ref_param+=( --unshallow ) 457 ref_param+=( --unshallow )
425 fi 458 fi
459 # fetch all branches
460 ref_param+=( "refs/heads/*:refs/remotes/origin/*" )
426 else 461 else
427 # 'git show-ref --heads' returns 1 when there are no branches 462 # 'git show-ref --heads' returns 1 when there are no branches
428 if ! git show-ref --heads -q; then 463 if ! git show-ref --heads -q; then
429 ref_param+=( --depth 1 ) 464 ref_param+=( --depth 1 )
430 else 465 else
509# the repository state into the environment. If the repository contains 544# the repository state into the environment. If the repository contains
510# submodules, they will be checked out recursively. 545# submodules, they will be checked out recursively.
511git-r3_checkout() { 546git-r3_checkout() {
512 debug-print-function ${FUNCNAME} "$@" 547 debug-print-function ${FUNCNAME} "$@"
513 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
514 local repos=( ${1:-${EGIT_REPO_URI}} ) 555 repos=( ${EGIT_REPO_URI} )
556 fi
557
515 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 558 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
516 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 559 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
517 560
518 local -x GIT_DIR GIT_WORK_TREE 561 local -x GIT_DIR GIT_WORK_TREE
519 _git-r3_set_gitdir ${repos[0]} 562 _git-r3_set_gitdir "${repos[0]}"
520 GIT_WORK_TREE=${out_dir} 563 GIT_WORK_TREE=${out_dir}
521 mkdir -p "${GIT_WORK_TREE}" 564 mkdir -p "${GIT_WORK_TREE}"
522 565
523 einfo "Checking out ${repos[0]} to ${out_dir} ..." 566 einfo "Checking out ${repos[0]} to ${out_dir} ..."
524 567
606# On success, the function returns 0 and writes hexadecimal commit SHA1 649# On success, the function returns 0 and writes hexadecimal commit SHA1
607# to stdout. On failure, the function returns 1. 650# to stdout. On failure, the function returns 1.
608git-r3_peek_remote_ref() { 651git-r3_peek_remote_ref() {
609 debug-print-function ${FUNCNAME} "$@" 652 debug-print-function ${FUNCNAME} "$@"
610 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
611 local repos=( ${1:-${EGIT_REPO_URI}} ) 660 repos=( ${EGIT_REPO_URI} )
661 fi
662
612 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 663 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
613 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 664 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
614 665
615 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 666 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
616 667
617 local r success 668 local r success
618 for r in ${repos[@]}; do 669 for r in "${repos[@]}"; do
619 einfo "Peeking ${remote_ref} on ${r} ..." >&2 670 einfo "Peeking ${remote_ref} on ${r} ..." >&2
620 671
621 local is_branch lookup_ref 672 local is_branch lookup_ref
622 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 673 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
623 then 674 then
644} 695}
645 696
646git-r3_src_fetch() { 697git-r3_src_fetch() {
647 debug-print-function ${FUNCNAME} "$@" 698 debug-print-function ${FUNCNAME} "$@"
648 699
649 [[ ${EVCS_OFFLINE} ]] && return
650
651 if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then 700 if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then
652 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"
653 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"
654 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"
655 ewarn "when git-2 eclass becomes deprecated." 704 ewarn "when git-2 eclass becomes deprecated."

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

  ViewVC Help
Powered by ViewVC 1.1.20