/[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.9
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.9 2013/09/25 11:19:09 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
169_git-r3_set_gitdir() { 171_git-r3_set_gitdir() {
170 debug-print-function ${FUNCNAME} "$@" 172 debug-print-function ${FUNCNAME} "$@"
171 173
172 local repo_name=${1#*://*/} 174 local repo_name=${1#*://*/}
173 175
176 # strip the trailing slash
177 repo_name=${repo_name%/}
178
174 # strip common prefixes to make paths more likely to match 179 # strip common prefixes to make paths more likely to match
175 # e.g. git://X/Y.git vs https://X/git/Y.git 180 # e.g. git://X/Y.git vs https://X/git/Y.git
176 # (but just one of the prefixes) 181 # (but just one of the prefixes)
177 case "${repo_name}" in 182 case "${repo_name}" in
183 # gnome.org... who else?
184 browse/*) repo_name=${repo_name#browse/};;
178 # cgit can proxy requests to git 185 # cgit can proxy requests to git
179 cgit/*) repo_name=${repo_name#cgit/};; 186 cgit/*) repo_name=${repo_name#cgit/};;
180 # pretty common 187 # pretty common
181 git/*) repo_name=${repo_name#git/};; 188 git/*) repo_name=${repo_name#git/};;
182 # gentoo.org 189 # gentoo.org
206 addwrite "${EGIT3_STORE_DIR}" 213 addwrite "${EGIT3_STORE_DIR}"
207 if [[ ! -d ${GIT_DIR} ]]; then 214 if [[ ! -d ${GIT_DIR} ]]; then
208 mkdir "${GIT_DIR}" || die 215 mkdir "${GIT_DIR}" || die
209 git init --bare || die 216 git init --bare || die
210 217
218 if [[ ! ${EGIT_NONSHALLOW} ]]; then
211 # avoid auto-unshallow :) 219 # avoid auto-unshallow :)
212 touch "${GIT_DIR}"/shallow || die 220 touch "${GIT_DIR}"/shallow || die
221 fi
213 fi 222 fi
214} 223}
215 224
216# @FUNCTION: _git-r3_set_submodules 225# @FUNCTION: _git-r3_set_submodules
217# @USAGE: <file-contents> 226# @USAGE: <file-contents>
363# If the repository contains submodules, they will be fetched 372# If the repository contains submodules, they will be fetched
364# recursively. 373# recursively.
365git-r3_fetch() { 374git-r3_fetch() {
366 debug-print-function ${FUNCNAME} "$@" 375 debug-print-function ${FUNCNAME} "$@"
367 376
377 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
378 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
379 fi
380
368 local repos=( ${1:-${EGIT_REPO_URI}} ) 381 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
369 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 382 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
370 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 383 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
371 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 384 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
372 local local_ref=refs/heads/${local_id}/__main__ 385 local local_ref=refs/heads/${local_id}/__main__
373 386
374 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 387 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
375 388
376 local -x GIT_DIR 389 local -x GIT_DIR
377 _git-r3_set_gitdir ${repos[0]} 390 _git-r3_set_gitdir "${repos[0]}"
378 391
379 # try to fetch from the remote 392 # try to fetch from the remote
380 local r success 393 local r success
381 for r in ${repos[@]}; do 394 for r in "${repos[@]}"; do
382 einfo "Fetching ${remote_ref} from ${r} ..." 395 einfo "Fetching ${remote_ref} from ${r} ..."
383 396
384 local is_branch lookup_ref 397 local is_branch lookup_ref
385 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 398 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
386 then 399 then
396 # and not a commit id. if it succeeds, we can pass ${remote_ref} 409 # and not a commit id. if it succeeds, we can pass ${remote_ref}
397 # to 'fetch'. otherwise, we will just fetch everything 410 # to 'fetch'. otherwise, we will just fetch everything
398 411
399 # split on whitespace 412 # split on whitespace
400 local ref=( 413 local ref=(
401 $(git ls-remote "${r}" "${lookup_ref}") 414 $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
402 ) 415 )
416
417 # normally, ref[0] is a hash, so we can do magic strings here
418 [[ ${ref[0]} == __FAIL__ ]] && continue
403 419
404 local nonshallow=${EGIT_NONSHALLOW} 420 local nonshallow=${EGIT_NONSHALLOW}
405 local ref_param=() 421 local ref_param=()
406 if [[ ! ${ref[0]} ]]; then 422 if [[ ! ${ref[0]} ]]; then
407 nonshallow=1 423 nonshallow=1
509# the repository state into the environment. If the repository contains 525# the repository state into the environment. If the repository contains
510# submodules, they will be checked out recursively. 526# submodules, they will be checked out recursively.
511git-r3_checkout() { 527git-r3_checkout() {
512 debug-print-function ${FUNCNAME} "$@" 528 debug-print-function ${FUNCNAME} "$@"
513 529
530 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
531 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
532 fi
533
514 local repos=( ${1:-${EGIT_REPO_URI}} ) 534 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
515 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 535 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
516 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 536 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
517 537
518 local -x GIT_DIR GIT_WORK_TREE 538 local -x GIT_DIR GIT_WORK_TREE
519 _git-r3_set_gitdir ${repos[0]} 539 _git-r3_set_gitdir "${repos[0]}"
520 GIT_WORK_TREE=${out_dir} 540 GIT_WORK_TREE=${out_dir}
521 mkdir -p "${GIT_WORK_TREE}" 541 mkdir -p "${GIT_WORK_TREE}"
522 542
523 einfo "Checking out ${repos[0]} to ${out_dir} ..." 543 einfo "Checking out ${repos[0]} to ${out_dir} ..."
524 544
606# On success, the function returns 0 and writes hexadecimal commit SHA1 626# On success, the function returns 0 and writes hexadecimal commit SHA1
607# to stdout. On failure, the function returns 1. 627# to stdout. On failure, the function returns 1.
608git-r3_peek_remote_ref() { 628git-r3_peek_remote_ref() {
609 debug-print-function ${FUNCNAME} "$@" 629 debug-print-function ${FUNCNAME} "$@"
610 630
631 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
632 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
633 fi
634
611 local repos=( ${1:-${EGIT_REPO_URI}} ) 635 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
612 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 636 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
613 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 637 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
614 638
615 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 639 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
616 640
617 local r success 641 local r success
618 for r in ${repos[@]}; do 642 for r in "${repos[@]}"; do
619 einfo "Peeking ${remote_ref} on ${r} ..." >&2 643 einfo "Peeking ${remote_ref} on ${r} ..." >&2
620 644
621 local is_branch lookup_ref 645 local is_branch lookup_ref
622 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 646 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
623 then 647 then

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

  ViewVC Help
Powered by ViewVC 1.1.20