/[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.10
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.10 2013/09/26 12:38:38 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 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
380 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
381 fi
382
368 local repos=( ${1:-${EGIT_REPO_URI}} ) 383 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
369 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 384 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
370 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 385 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
371 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 386 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
372 local local_ref=refs/heads/${local_id}/__main__ 387 local local_ref=refs/heads/${local_id}/__main__
373 388
374 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 389 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
375 390
376 local -x GIT_DIR 391 local -x GIT_DIR
377 _git-r3_set_gitdir ${repos[0]} 392 _git-r3_set_gitdir "${repos[0]}"
378 393
379 # try to fetch from the remote 394 # try to fetch from the remote
380 local r success 395 local r success
381 for r in ${repos[@]}; do 396 for r in "${repos[@]}"; do
382 einfo "Fetching ${remote_ref} from ${r} ..." 397 einfo "Fetching ${remote_ref} from ${r} ..."
383 398
384 local is_branch lookup_ref 399 local is_branch lookup_ref
385 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 400 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
386 then 401 then
396 # and not a commit id. if it succeeds, we can pass ${remote_ref} 411 # and not a commit id. if it succeeds, we can pass ${remote_ref}
397 # to 'fetch'. otherwise, we will just fetch everything 412 # to 'fetch'. otherwise, we will just fetch everything
398 413
399 # split on whitespace 414 # split on whitespace
400 local ref=( 415 local ref=(
401 $(git ls-remote "${r}" "${lookup_ref}") 416 $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
402 ) 417 )
418
419 # normally, ref[0] is a hash, so we can do magic strings here
420 [[ ${ref[0]} == __FAIL__ ]] && continue
403 421
404 local nonshallow=${EGIT_NONSHALLOW} 422 local nonshallow=${EGIT_NONSHALLOW}
405 local ref_param=() 423 local ref_param=()
406 if [[ ! ${ref[0]} ]]; then 424 if [[ ! ${ref[0]} ]]; then
407 nonshallow=1 425 nonshallow=1
509# the repository state into the environment. If the repository contains 527# the repository state into the environment. If the repository contains
510# submodules, they will be checked out recursively. 528# submodules, they will be checked out recursively.
511git-r3_checkout() { 529git-r3_checkout() {
512 debug-print-function ${FUNCNAME} "$@" 530 debug-print-function ${FUNCNAME} "$@"
513 531
532 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
533 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
534 fi
535
514 local repos=( ${1:-${EGIT_REPO_URI}} ) 536 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
515 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 537 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
516 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 538 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
517 539
518 local -x GIT_DIR GIT_WORK_TREE 540 local -x GIT_DIR GIT_WORK_TREE
519 _git-r3_set_gitdir ${repos[0]} 541 _git-r3_set_gitdir "${repos[0]}"
520 GIT_WORK_TREE=${out_dir} 542 GIT_WORK_TREE=${out_dir}
521 mkdir -p "${GIT_WORK_TREE}" 543 mkdir -p "${GIT_WORK_TREE}"
522 544
523 einfo "Checking out ${repos[0]} to ${out_dir} ..." 545 einfo "Checking out ${repos[0]} to ${out_dir} ..."
524 546
606# On success, the function returns 0 and writes hexadecimal commit SHA1 628# On success, the function returns 0 and writes hexadecimal commit SHA1
607# to stdout. On failure, the function returns 1. 629# to stdout. On failure, the function returns 1.
608git-r3_peek_remote_ref() { 630git-r3_peek_remote_ref() {
609 debug-print-function ${FUNCNAME} "$@" 631 debug-print-function ${FUNCNAME} "$@"
610 632
633 if [[ $(declare -p EGIT_REPO_URI) != "declare -a"* ]]; then
634 local EGIT_REPO_URI=( ${EGIT_REPO_URI} )
635 fi
636
611 local repos=( ${1:-${EGIT_REPO_URI}} ) 637 local repos=( "${1:-${EGIT_REPO_URI[@]}}" )
612 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 638 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
613 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 639 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
614 640
615 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 641 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
616 642
617 local r success 643 local r success
618 for r in ${repos[@]}; do 644 for r in "${repos[@]}"; do
619 einfo "Peeking ${remote_ref} on ${r} ..." >&2 645 einfo "Peeking ${remote_ref} on ${r} ..." >&2
620 646
621 local is_branch lookup_ref 647 local is_branch lookup_ref
622 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 648 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
623 then 649 then

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

  ViewVC Help
Powered by ViewVC 1.1.20