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

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

  ViewVC Help
Powered by ViewVC 1.1.20