/[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.13
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.13 2013/10/05 16:48:25 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
32DEPEND=">=dev-vcs/git-1.8.2.1"
33
32# @ECLASS-VARIABLE: EGIT3_STORE_DIR 34# @ECLASS-VARIABLE: EGIT3_STORE_DIR
33# @DESCRIPTION: 35# @DESCRIPTION:
34# Storage directory for git sources. 36# Storage directory for git sources.
35# 37#
36# EGIT3_STORE_DIR=${DISTDIR}/git3-src 38# EGIT3_STORE_DIR=${DISTDIR}/git3-src
41# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs 43# 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 44# are provided, the eclass will consider them as fallback URIs to try
43# if the first URI does not work. 45# if the first URI does not work.
44# 46#
45# It can be overriden via env using ${PN}_LIVE_REPO variable. 47# It can be overriden via env using ${PN}_LIVE_REPO variable.
48#
49# Can be a whitespace-separated list or an array.
46# 50#
47# Example: 51# Example:
48# @CODE 52# @CODE
49# EGIT_REPO_URI="git://a/b.git https://c/d.git" 53# EGIT_REPO_URI="git://a/b.git https://c/d.git"
50# @CODE 54# @CODE
82# @DESCRIPTION: 86# @DESCRIPTION:
83# Disable performing shallow fetches/clones. Shallow clones have 87# Disable performing shallow fetches/clones. Shallow clones have
84# a fair number of limitations. Therefore, if you'd like the eclass to 88# 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. 89# perform complete clones instead, set this to a non-null value.
86# 90#
87# This variable is to be set in make.conf. Ebuilds are not allowed 91# This variable can be set in make.conf and ebuilds. The make.conf
88# to set it. 92# value specifies user-specific default, while ebuilds may use it
93# to force deep clones when the server does not support shallow clones
94# (e.g. Google Code).
89 95
90# @FUNCTION: _git-r3_env_setup 96# @FUNCTION: _git-r3_env_setup
91# @INTERNAL 97# @INTERNAL
92# @DESCRIPTION: 98# @DESCRIPTION:
93# Set the eclass variables as necessary for operation. This can involve 99# Set the eclass variables as necessary for operation. This can involve
169_git-r3_set_gitdir() { 175_git-r3_set_gitdir() {
170 debug-print-function ${FUNCNAME} "$@" 176 debug-print-function ${FUNCNAME} "$@"
171 177
172 local repo_name=${1#*://*/} 178 local repo_name=${1#*://*/}
173 179
180 # strip the trailing slash
181 repo_name=${repo_name%/}
182
174 # strip common prefixes to make paths more likely to match 183 # strip common prefixes to make paths more likely to match
175 # e.g. git://X/Y.git vs https://X/git/Y.git 184 # e.g. git://X/Y.git vs https://X/git/Y.git
176 # (but just one of the prefixes) 185 # (but just one of the prefixes)
177 case "${repo_name}" in 186 case "${repo_name}" in
187 # gnome.org... who else?
188 browse/*) repo_name=${repo_name#browse/};;
178 # cgit can proxy requests to git 189 # cgit can proxy requests to git
179 cgit/*) repo_name=${repo_name#cgit/};; 190 cgit/*) repo_name=${repo_name#cgit/};;
180 # pretty common 191 # pretty common
181 git/*) repo_name=${repo_name#git/};; 192 git/*) repo_name=${repo_name#git/};;
182 # gentoo.org 193 # gentoo.org
206 addwrite "${EGIT3_STORE_DIR}" 217 addwrite "${EGIT3_STORE_DIR}"
207 if [[ ! -d ${GIT_DIR} ]]; then 218 if [[ ! -d ${GIT_DIR} ]]; then
208 mkdir "${GIT_DIR}" || die 219 mkdir "${GIT_DIR}" || die
209 git init --bare || die 220 git init --bare || die
210 221
222 if [[ ! ${EGIT_NONSHALLOW} ]]; then
211 # avoid auto-unshallow :) 223 # avoid auto-unshallow :)
212 touch "${GIT_DIR}"/shallow || die 224 touch "${GIT_DIR}"/shallow || die
225 fi
213 fi 226 fi
214} 227}
215 228
216# @FUNCTION: _git-r3_set_submodules 229# @FUNCTION: _git-r3_set_submodules
217# @USAGE: <file-contents> 230# @USAGE: <file-contents>
363# If the repository contains submodules, they will be fetched 376# If the repository contains submodules, they will be fetched
364# recursively. 377# recursively.
365git-r3_fetch() { 378git-r3_fetch() {
366 debug-print-function ${FUNCNAME} "$@" 379 debug-print-function ${FUNCNAME} "$@"
367 380
381 local repos
382 if [[ ${1} ]]; then
383 repos=( ${1} )
384 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
385 repos=( "${EGIT_REPO_URI[@]}" )
386 else
368 local repos=( ${1:-${EGIT_REPO_URI}} ) 387 repos=( ${EGIT_REPO_URI} )
388 fi
389
369 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 390 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
370 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 391 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
371 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 392 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
372 local local_ref=refs/heads/${local_id}/__main__ 393 local local_ref=refs/heads/${local_id}/__main__
373 394
374 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 395 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
375 396
376 local -x GIT_DIR 397 local -x GIT_DIR
377 _git-r3_set_gitdir ${repos[0]} 398 _git-r3_set_gitdir "${repos[0]}"
378 399
379 # try to fetch from the remote 400 # try to fetch from the remote
380 local r success 401 local r success
381 for r in ${repos[@]}; do 402 for r in "${repos[@]}"; do
382 einfo "Fetching ${remote_ref} from ${r} ..." 403 einfo "Fetching ${remote_ref} from ${r} ..."
383 404
384 local is_branch lookup_ref 405 local is_branch lookup_ref
385 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 406 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
386 then 407 then
396 # and not a commit id. if it succeeds, we can pass ${remote_ref} 417 # and not a commit id. if it succeeds, we can pass ${remote_ref}
397 # to 'fetch'. otherwise, we will just fetch everything 418 # to 'fetch'. otherwise, we will just fetch everything
398 419
399 # split on whitespace 420 # split on whitespace
400 local ref=( 421 local ref=(
401 $(git ls-remote "${r}" "${lookup_ref}") 422 $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
402 ) 423 )
424
425 # normally, ref[0] is a hash, so we can do magic strings here
426 [[ ${ref[0]} == __FAIL__ ]] && continue
403 427
404 local nonshallow=${EGIT_NONSHALLOW} 428 local nonshallow=${EGIT_NONSHALLOW}
405 local ref_param=() 429 local ref_param=()
406 if [[ ! ${ref[0]} ]]; then 430 if [[ ! ${ref[0]} ]]; then
407 nonshallow=1 431 nonshallow=1
421 local fetch_command=( git fetch ) 445 local fetch_command=( git fetch )
422 if [[ ${nonshallow} ]]; then 446 if [[ ${nonshallow} ]]; then
423 if [[ -f ${GIT_DIR}/shallow ]]; then 447 if [[ -f ${GIT_DIR}/shallow ]]; then
424 ref_param+=( --unshallow ) 448 ref_param+=( --unshallow )
425 fi 449 fi
450 # fetch all branches
451 ref_param+=( "refs/heads/*:refs/remotes/origin/*" )
426 else 452 else
427 # 'git show-ref --heads' returns 1 when there are no branches 453 # 'git show-ref --heads' returns 1 when there are no branches
428 if ! git show-ref --heads -q; then 454 if ! git show-ref --heads -q; then
429 ref_param+=( --depth 1 ) 455 ref_param+=( --depth 1 )
430 else 456 else
509# the repository state into the environment. If the repository contains 535# the repository state into the environment. If the repository contains
510# submodules, they will be checked out recursively. 536# submodules, they will be checked out recursively.
511git-r3_checkout() { 537git-r3_checkout() {
512 debug-print-function ${FUNCNAME} "$@" 538 debug-print-function ${FUNCNAME} "$@"
513 539
540 local repos
541 if [[ ${1} ]]; then
542 repos=( ${1} )
543 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
544 repos=( "${EGIT_REPO_URI[@]}" )
545 else
514 local repos=( ${1:-${EGIT_REPO_URI}} ) 546 repos=( ${EGIT_REPO_URI} )
547 fi
548
515 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 549 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
516 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 550 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
517 551
518 local -x GIT_DIR GIT_WORK_TREE 552 local -x GIT_DIR GIT_WORK_TREE
519 _git-r3_set_gitdir ${repos[0]} 553 _git-r3_set_gitdir "${repos[0]}"
520 GIT_WORK_TREE=${out_dir} 554 GIT_WORK_TREE=${out_dir}
521 mkdir -p "${GIT_WORK_TREE}" 555 mkdir -p "${GIT_WORK_TREE}"
522 556
523 einfo "Checking out ${repos[0]} to ${out_dir} ..." 557 einfo "Checking out ${repos[0]} to ${out_dir} ..."
524 558
606# On success, the function returns 0 and writes hexadecimal commit SHA1 640# On success, the function returns 0 and writes hexadecimal commit SHA1
607# to stdout. On failure, the function returns 1. 641# to stdout. On failure, the function returns 1.
608git-r3_peek_remote_ref() { 642git-r3_peek_remote_ref() {
609 debug-print-function ${FUNCNAME} "$@" 643 debug-print-function ${FUNCNAME} "$@"
610 644
645 local repos
646 if [[ ${1} ]]; then
647 repos=( ${1} )
648 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
649 repos=( "${EGIT_REPO_URI[@]}" )
650 else
611 local repos=( ${1:-${EGIT_REPO_URI}} ) 651 repos=( ${EGIT_REPO_URI} )
652 fi
653
612 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 654 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
613 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 655 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
614 656
615 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 657 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
616 658
617 local r success 659 local r success
618 for r in ${repos[@]}; do 660 for r in "${repos[@]}"; do
619 einfo "Peeking ${remote_ref} on ${r} ..." >&2 661 einfo "Peeking ${remote_ref} on ${r} ..." >&2
620 662
621 local is_branch lookup_ref 663 local is_branch lookup_ref
622 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 664 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
623 then 665 then

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

  ViewVC Help
Powered by ViewVC 1.1.20