/[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.6 Revision 1.11
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.6 2013/09/19 09:37:14 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.11 2013/09/26 21:04:42 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
365# If the repository contains submodules, they will be fetched 374# If the repository contains submodules, they will be fetched
366# recursively. 375# recursively.
367git-r3_fetch() { 376git-r3_fetch() {
368 debug-print-function ${FUNCNAME} "$@" 377 debug-print-function ${FUNCNAME} "$@"
369 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
370 local repos=( ${1:-${EGIT_REPO_URI}} ) 385 repos=( ${EGIT_REPO_URI} )
386 fi
387
371 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 388 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
372 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 389 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
373 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 390 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
374 local local_ref=refs/heads/${local_id}/__main__ 391 local local_ref=refs/heads/${local_id}/__main__
375 392
376 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 393 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
377 394
378 local -x GIT_DIR 395 local -x GIT_DIR
379 _git-r3_set_gitdir ${repos[0]} 396 _git-r3_set_gitdir "${repos[0]}"
380 397
381 # try to fetch from the remote 398 # try to fetch from the remote
382 local r success 399 local r success
383 for r in ${repos[@]}; do 400 for r in "${repos[@]}"; do
384 einfo "Fetching ${remote_ref} from ${r} ..." 401 einfo "Fetching ${remote_ref} from ${r} ..."
385 402
386 local is_branch lookup_ref 403 local is_branch lookup_ref
387 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 404 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
388 then 405 then
514# the repository state into the environment. If the repository contains 531# the repository state into the environment. If the repository contains
515# submodules, they will be checked out recursively. 532# submodules, they will be checked out recursively.
516git-r3_checkout() { 533git-r3_checkout() {
517 debug-print-function ${FUNCNAME} "$@" 534 debug-print-function ${FUNCNAME} "$@"
518 535
536 local repos
537 if [[ ${1} ]]; then
538 repos=( ${1} )
539 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
540 repos=( "${EGIT_REPO_URI[@]}" )
541 else
519 local repos=( ${1:-${EGIT_REPO_URI}} ) 542 repos=( ${EGIT_REPO_URI} )
543 fi
544
520 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} 545 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
521 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}} 546 local local_id=${3:-${CATEGORY}/${PN}/${SLOT}}
522 547
523 local -x GIT_DIR GIT_WORK_TREE 548 local -x GIT_DIR GIT_WORK_TREE
524 _git-r3_set_gitdir ${repos[0]} 549 _git-r3_set_gitdir "${repos[0]}"
525 GIT_WORK_TREE=${out_dir} 550 GIT_WORK_TREE=${out_dir}
526 mkdir -p "${GIT_WORK_TREE}" 551 mkdir -p "${GIT_WORK_TREE}"
527 552
528 einfo "Checking out ${repos[0]} to ${out_dir} ..." 553 einfo "Checking out ${repos[0]} to ${out_dir} ..."
529 554
611# On success, the function returns 0 and writes hexadecimal commit SHA1 636# On success, the function returns 0 and writes hexadecimal commit SHA1
612# to stdout. On failure, the function returns 1. 637# to stdout. On failure, the function returns 1.
613git-r3_peek_remote_ref() { 638git-r3_peek_remote_ref() {
614 debug-print-function ${FUNCNAME} "$@" 639 debug-print-function ${FUNCNAME} "$@"
615 640
641 local repos
642 if [[ ${1} ]]; then
643 repos=( ${1} )
644 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
645 repos=( "${EGIT_REPO_URI[@]}" )
646 else
616 local repos=( ${1:-${EGIT_REPO_URI}} ) 647 repos=( ${EGIT_REPO_URI} )
648 fi
649
617 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} 650 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
618 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} 651 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
619 652
620 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 653 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
621 654
622 local r success 655 local r success
623 for r in ${repos[@]}; do 656 for r in "${repos[@]}"; do
624 einfo "Peeking ${remote_ref} on ${r} ..." >&2 657 einfo "Peeking ${remote_ref} on ${r} ..." >&2
625 658
626 local is_branch lookup_ref 659 local is_branch lookup_ref
627 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 660 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
628 then 661 then

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.20