/[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.14
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.14 2013/10/08 11:19:48 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>
363# If the repository contains submodules, they will be fetched 378# If the repository contains submodules, they will be fetched
364# recursively. 379# recursively.
365git-r3_fetch() { 380git-r3_fetch() {
366 debug-print-function ${FUNCNAME} "$@" 381 debug-print-function ${FUNCNAME} "$@"
367 382
383 local repos
384 if [[ ${1} ]]; then
385 repos=( ${1} )
386 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
387 repos=( "${EGIT_REPO_URI[@]}" )
388 else
368 local repos=( ${1:-${EGIT_REPO_URI}} ) 389 repos=( ${EGIT_REPO_URI} )
390 fi
391
369 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 392 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
370 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 393 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
371 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 394 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
372 local local_ref=refs/heads/${local_id}/__main__ 395 local local_ref=refs/heads/${local_id}/__main__
373 396
374 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 397 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
375 398
376 local -x GIT_DIR 399 local -x GIT_DIR
377 _git-r3_set_gitdir ${repos[0]} 400 _git-r3_set_gitdir "${repos[0]}"
378 401
379 # try to fetch from the remote 402 # try to fetch from the remote
380 local r success 403 local r success
381 for r in ${repos[@]}; do 404 for r in "${repos[@]}"; do
382 einfo "Fetching ${remote_ref} from ${r} ..." 405 einfo "Fetching ${remote_ref} from ${r} ..."
383 406
384 local is_branch lookup_ref 407 local is_branch lookup_ref
385 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 408 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
386 then 409 then
396 # and not a commit id. if it succeeds, we can pass ${remote_ref} 419 # and not a commit id. if it succeeds, we can pass ${remote_ref}
397 # to 'fetch'. otherwise, we will just fetch everything 420 # to 'fetch'. otherwise, we will just fetch everything
398 421
399 # split on whitespace 422 # split on whitespace
400 local ref=( 423 local ref=(
401 $(git ls-remote "${r}" "${lookup_ref}") 424 $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
402 ) 425 )
426
427 # normally, ref[0] is a hash, so we can do magic strings here
428 [[ ${ref[0]} == __FAIL__ ]] && continue
403 429
404 local nonshallow=${EGIT_NONSHALLOW} 430 local nonshallow=${EGIT_NONSHALLOW}
405 local ref_param=() 431 local ref_param=()
406 if [[ ! ${ref[0]} ]]; then 432 if [[ ! ${ref[0]} ]]; then
407 nonshallow=1 433 nonshallow=1
421 local fetch_command=( git fetch ) 447 local fetch_command=( git fetch )
422 if [[ ${nonshallow} ]]; then 448 if [[ ${nonshallow} ]]; then
423 if [[ -f ${GIT_DIR}/shallow ]]; then 449 if [[ -f ${GIT_DIR}/shallow ]]; then
424 ref_param+=( --unshallow ) 450 ref_param+=( --unshallow )
425 fi 451 fi
452 # fetch all branches
453 ref_param+=( "refs/heads/*:refs/remotes/origin/*" )
426 else 454 else
427 # 'git show-ref --heads' returns 1 when there are no branches 455 # 'git show-ref --heads' returns 1 when there are no branches
428 if ! git show-ref --heads -q; then 456 if ! git show-ref --heads -q; then
429 ref_param+=( --depth 1 ) 457 ref_param+=( --depth 1 )
430 else 458 else
509# the repository state into the environment. If the repository contains 537# the repository state into the environment. If the repository contains
510# submodules, they will be checked out recursively. 538# submodules, they will be checked out recursively.
511git-r3_checkout() { 539git-r3_checkout() {
512 debug-print-function ${FUNCNAME} "$@" 540 debug-print-function ${FUNCNAME} "$@"
513 541
542 local repos
543 if [[ ${1} ]]; then
544 repos=( ${1} )
545 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
546 repos=( "${EGIT_REPO_URI[@]}" )
547 else
514 local repos=( ${1:-${EGIT_REPO_URI}} ) 548 repos=( ${EGIT_REPO_URI} )
549 fi
550
515 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 551 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
516 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 552 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
517 553
518 local -x GIT_DIR GIT_WORK_TREE 554 local -x GIT_DIR GIT_WORK_TREE
519 _git-r3_set_gitdir ${repos[0]} 555 _git-r3_set_gitdir "${repos[0]}"
520 GIT_WORK_TREE=${out_dir} 556 GIT_WORK_TREE=${out_dir}
521 mkdir -p "${GIT_WORK_TREE}" 557 mkdir -p "${GIT_WORK_TREE}"
522 558
523 einfo "Checking out ${repos[0]} to ${out_dir} ..." 559 einfo "Checking out ${repos[0]} to ${out_dir} ..."
524 560
606# On success, the function returns 0 and writes hexadecimal commit SHA1 642# On success, the function returns 0 and writes hexadecimal commit SHA1
607# to stdout. On failure, the function returns 1. 643# to stdout. On failure, the function returns 1.
608git-r3_peek_remote_ref() { 644git-r3_peek_remote_ref() {
609 debug-print-function ${FUNCNAME} "$@" 645 debug-print-function ${FUNCNAME} "$@"
610 646
647 local repos
648 if [[ ${1} ]]; then
649 repos=( ${1} )
650 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
651 repos=( "${EGIT_REPO_URI[@]}" )
652 else
611 local repos=( ${1:-${EGIT_REPO_URI}} ) 653 repos=( ${EGIT_REPO_URI} )
654 fi
655
612 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 656 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
613 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 657 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
614 658
615 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 659 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
616 660
617 local r success 661 local r success
618 for r in ${repos[@]}; do 662 for r in "${repos[@]}"; do
619 einfo "Peeking ${remote_ref} on ${r} ..." >&2 663 einfo "Peeking ${remote_ref} on ${r} ..." >&2
620 664
621 local is_branch lookup_ref 665 local is_branch lookup_ref
622 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 666 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
623 then 667 then

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

  ViewVC Help
Powered by ViewVC 1.1.20