/[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.35 Revision 1.47
1# Copyright 1999-2014 Gentoo Foundation 1# Copyright 1999-2014 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.35 2014/03/02 11:49:05 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.47 2014/07/28 14:13:50 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.
35# @ECLASS-VARIABLE: EGIT_CLONE_TYPE 35# @ECLASS-VARIABLE: EGIT_CLONE_TYPE
36# @DESCRIPTION: 36# @DESCRIPTION:
37# Type of clone that should be used against the remote repository. 37# Type of clone that should be used against the remote repository.
38# This can be either of: 'mirror', 'single', 'shallow'. 38# This can be either of: 'mirror', 'single', 'shallow'.
39# 39#
40# This is intended to be set by user in make.conf. Ebuilds are supposed
41# to set EGIT_MIN_CLONE_TYPE if necessary instead.
42#
40# The 'mirror' type clones all remote branches and tags with complete 43# The 'mirror' type clones all remote branches and tags with complete
41# history and all notes. EGIT_COMMIT can specify any commit hash. 44# history and all notes. EGIT_COMMIT can specify any commit hash.
42# Upstream-removed branches and tags are purged from the local clone 45# Upstream-removed branches and tags are purged from the local clone
43# while fetching. This mode is suitable for cloning the local copy 46# while fetching. This mode is suitable for cloning the local copy
44# for development or hosting a local git mirror. However, clones 47# for development or hosting a local git mirror. However, clones
45# of repositories with large diverged branches may quickly grow large. 48# of repositories with large diverged branches may quickly grow large.
46# 49#
50# The 'single+tags' type clones the requested branch and all tags
51# in the repository. All notes are fetched as well. EGIT_COMMIT
52# can safely specify hashes throughout the current branch and all tags.
53# No purging of old references is done (if you often switch branches,
54# you may need to remove stale branches yourself). This mode is intended
55# mostly for use with broken git servers such as Google Code that fail
56# to fetch tags along with the branch in 'single' mode.
57#
47# The 'single' type clones only the requested branch or tag. Tags 58# The 'single' type clones only the requested branch or tag. Tags
48# referencing commits throughout the branch history are fetched as well, 59# referencing commits throughout the branch history are fetched as well,
49# and all notes. EGIT_COMMIT can safely specify only hashes 60# and all notes. EGIT_COMMIT can safely specify only hashes
50# in the current branch. No purging of old references is done (if you 61# in the current branch. No purging of old references is done (if you
51# often switch branches, you may need to remove stale branches 62# often switch branches, you may need to remove stale branches
63# 'Minimum' clone type supported by the ebuild. Takes same values 74# 'Minimum' clone type supported by the ebuild. Takes same values
64# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is, 75# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is,
65# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses 76# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
66# EGIT_MIN_CLONE_TYPE instead. 77# EGIT_MIN_CLONE_TYPE instead.
67# 78#
79# This variable is intended to be used by ebuilds only. Users are
80# supposed to set EGIT_CLONE_TYPE instead.
81#
68# A common case is to use 'single' whenever the build system requires 82# A common case is to use 'single' whenever the build system requires
69# access to full branch history or the remote (Google Code) does not 83# access to full branch history, or 'single+tags' when Google Code
70# support shallow clones. Please use sparingly, and to fix fatal errors 84# or a similar remote is used that does not support shallow clones
85# and fetching tags along with commits. Please use sparingly, and to fix
71# rather than 'non-pretty versions'. 86# fatal errors rather than 'non-pretty versions'.
72: ${EGIT_MIN_CLONE_TYPE:=shallow} 87: ${EGIT_MIN_CLONE_TYPE:=shallow}
73 88
74# @ECLASS-VARIABLE: EGIT3_STORE_DIR 89# @ECLASS-VARIABLE: EGIT3_STORE_DIR
75# @DESCRIPTION: 90# @DESCRIPTION:
76# Storage directory for git sources. 91# Storage directory for git sources.
97# @ECLASS-VARIABLE: EGIT_REPO_URI 112# @ECLASS-VARIABLE: EGIT_REPO_URI
98# @REQUIRED 113# @REQUIRED
99# @DESCRIPTION: 114# @DESCRIPTION:
100# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs 115# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
101# are provided, the eclass will consider them as fallback URIs to try 116# are provided, the eclass will consider them as fallback URIs to try
102# if the first URI does not work. 117# if the first URI does not work. For supported URI syntaxes, read up
118# the manpage for git-clone(1).
103# 119#
104# It can be overriden via env using ${PN}_LIVE_REPO variable. 120# It can be overriden via env using ${PN}_LIVE_REPO variable.
105# 121#
106# Can be a whitespace-separated list or an array. 122# Can be a whitespace-separated list or an array.
107# 123#
146_git-r3_env_setup() { 162_git-r3_env_setup() {
147 debug-print-function ${FUNCNAME} "$@" 163 debug-print-function ${FUNCNAME} "$@"
148 164
149 # check the clone type 165 # check the clone type
150 case "${EGIT_CLONE_TYPE}" in 166 case "${EGIT_CLONE_TYPE}" in
151 mirror|single|shallow) 167 mirror|single+tags|single|shallow)
152 ;; 168 ;;
153 *) 169 *)
154 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 170 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
155 esac 171 esac
156 case "${EGIT_MIN_CLONE_TYPE}" in 172 case "${EGIT_MIN_CLONE_TYPE}" in
158 ;; 174 ;;
159 single) 175 single)
160 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 176 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
161 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting" 177 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
162 EGIT_CLONE_TYPE=single 178 EGIT_CLONE_TYPE=single
179 fi
180 ;;
181 single+tags)
182 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
183 einfo "git-r3: ebuild needs to be cloned in 'single+tags' mode, adjusting"
184 EGIT_CLONE_TYPE=single+tags
163 fi 185 fi
164 ;; 186 ;;
165 mirror) 187 mirror)
166 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then 188 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
167 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting" 189 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
279 GIT_DIR=${EGIT3_STORE_DIR}/${repo_name} 301 GIT_DIR=${EGIT3_STORE_DIR}/${repo_name}
280 302
281 if [[ ! -d ${EGIT3_STORE_DIR} ]]; then 303 if [[ ! -d ${EGIT3_STORE_DIR} ]]; then
282 ( 304 (
283 addwrite / 305 addwrite /
284 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die 306 mkdir -p "${EGIT3_STORE_DIR}" || die
285 ) || die "Unable to create ${EGIT3_STORE_DIR}" 307 ) || die "Unable to create ${EGIT3_STORE_DIR}"
286 fi 308 fi
287 309
288 addwrite "${EGIT3_STORE_DIR}" 310 addwrite "${EGIT3_STORE_DIR}"
289 if [[ ! -d ${GIT_DIR} ]]; then 311 if [[ ! -d ${GIT_DIR} ]]; then
329 submodule."${subname}".path || die)" 351 submodule."${subname}".path || die)"
330 ) 352 )
331 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die) 353 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
332} 354}
333 355
356# @FUNCTION: _git-r3_set_subrepos
357# @USAGE: <submodule-uri> <parent-repo-uri>...
358# @INTERNAL
359# @DESCRIPTION:
360# Create 'subrepos' array containing absolute (canonical) submodule URIs
361# for the given <submodule-uri>. If the URI is relative, URIs will be
362# constructed using all <parent-repo-uri>s. Otherwise, this single URI
363# will be placed in the array.
364_git-r3_set_subrepos() {
365 debug-print-function ${FUNCNAME} "$@"
366
367 local suburl=${1}
368 subrepos=( "${@:2}" )
369
370 if [[ ${suburl} == ./* || ${suburl} == ../* ]]; then
371 # drop all possible trailing slashes for consistency
372 subrepos=( "${subrepos[@]%%/}" )
373
374 while true; do
375 if [[ ${suburl} == ./* ]]; then
376 suburl=${suburl:2}
377 elif [[ ${suburl} == ../* ]]; then
378 suburl=${suburl:3}
379
380 # XXX: correctness checking
381
382 # drop the last path component
383 subrepos=( "${subrepos[@]%/*}" )
384 # and then the trailing slashes, again
385 subrepos=( "${subrepos[@]%%/}" )
386 else
387 break
388 fi
389 done
390
391 # append the preprocessed path to the preprocessed URIs
392 subrepos=( "${subrepos[@]/%//${suburl}}")
393 else
394 subrepos=( "${suburl}" )
395 fi
396}
397
398
334# @FUNCTION: _git-r3_is_local_repo 399# @FUNCTION: _git-r3_is_local_repo
335# @USAGE: <repo-uri> 400# @USAGE: <repo-uri>
336# @INTERNAL 401# @INTERNAL
337# @DESCRIPTION: 402# @DESCRIPTION:
338# Determine whether the given URI specifies a local (on-disk) 403# Determine whether the given URI specifies a local (on-disk)
445 local r success 510 local r success
446 for r in "${repos[@]}"; do 511 for r in "${repos[@]}"; do
447 einfo "Fetching ${r} ..." 512 einfo "Fetching ${r} ..."
448 513
449 local fetch_command=( git fetch "${r}" ) 514 local fetch_command=( git fetch "${r}" )
515 local clone_type=${EGIT_CLONE_TYPE}
450 516
451 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 517 if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then
518 eerror "git-r3: fetching from https:// requested. In order to support https,"
519 eerror "dev-vcs/git needs to be built with USE=curl. Example solution:"
520 eerror
521 eerror " echo dev-vcs/git curl >> /etc/portage/package.use"
522 eerror " emerge -1v dev-vcs/git"
523 die "dev-vcs/git built with USE=curl required."
524 fi
525
526 if [[ ${r} == https://code.google.com/* ]]; then
527 # Google Code has special magic on top of git that:
528 # 1) can't handle shallow clones at all,
529 # 2) fetches duplicately when tags are pulled in with branch
530 # so automatically switch to single+tags mode.
531 if [[ ${clone_type} == shallow ]]; then
532 einfo " Google Code does not support shallow clones"
533 einfo " using EGIT_CLONE_TYPE=single+tags"
534 clone_type=single+tags
535 elif [[ ${clone_type} == single ]]; then
536 einfo " git-r3: Google Code does not send tags properly in 'single' mode"
537 einfo " using EGIT_CLONE_TYPE=single+tags"
538 clone_type=single+tags
539 fi
540 fi
541
542 if [[ ${clone_type} == mirror ]]; then
452 fetch_command+=( 543 fetch_command+=(
453 --prune 544 --prune
454 # mirror the remote branches as local branches 545 # mirror the remote branches as local branches
455 "refs/heads/*:refs/heads/*" 546 "+refs/heads/*:refs/heads/*"
456 # pull tags explicitly in order to prune them properly 547 # pull tags explicitly in order to prune them properly
457 "refs/tags/*:refs/tags/*" 548 "+refs/tags/*:refs/tags/*"
458 # notes in case something needs them 549 # notes in case something needs them
459 "refs/notes/*:refs/notes/*" 550 "+refs/notes/*:refs/notes/*"
460 # and HEAD in case we need the default branch 551 # and HEAD in case we need the default branch
461 # (we keep it in refs/git-r3 since otherwise --prune interferes) 552 # (we keep it in refs/git-r3 since otherwise --prune interferes)
462 HEAD:refs/git-r3/HEAD 553 "+HEAD:refs/git-r3/HEAD"
463 ) 554 )
464 else # single or shallow 555 else # single or shallow
465 local fetch_l fetch_r 556 local fetch_l fetch_r
466 557
467 if [[ ${remote_ref} == HEAD ]]; then 558 if [[ ${remote_ref} == HEAD ]]; then
487 else 578 else
488 fetch_l=HEAD 579 fetch_l=HEAD
489 fi 580 fi
490 581
491 # fetching by commit in shallow mode? can't do. 582 # fetching by commit in shallow mode? can't do.
492 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 583 if [[ ${clone_type} == shallow ]]; then
493 local EGIT_CLONE_TYPE=single 584 clone_type=single
494 fi 585 fi
495 fi 586 fi
496 fi 587 fi
497 588
498 if [[ ${fetch_l} == HEAD ]]; then 589 if [[ ${fetch_l} == HEAD ]]; then
500 else 591 else
501 fetch_r=${fetch_l} 592 fetch_r=${fetch_l}
502 fi 593 fi
503 594
504 fetch_command+=( 595 fetch_command+=(
505 "${fetch_l}:${fetch_r}" 596 "+${fetch_l}:${fetch_r}"
506 ) 597 )
598
599 if [[ ${clone_type} == single+tags ]]; then
600 fetch_command+=(
601 # pull tags explicitly as requested
602 "+refs/tags/*:refs/tags/*"
603 )
507 fi 604 fi
605 fi
508 606
509 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 607 if [[ ${clone_type} == shallow ]]; then
510 # use '--depth 1' when fetching a new branch 608 if _git-r3_is_local_repo; then
609 # '--depth 1' causes sandbox violations with local repos
610 # bug #491260
611 clone_type=single
511 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] 612 elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
512 then 613 then
614 # use '--depth 1' when fetching a new branch
513 fetch_command+=( --depth 1 ) 615 fetch_command+=( --depth 1 )
514 fi 616 fi
515 else # non-shallow mode 617 else # non-shallow mode
516 if [[ -f ${GIT_DIR}/shallow ]]; then 618 if [[ -f ${GIT_DIR}/shallow ]]; then
517 fetch_command+=( --unshallow ) 619 fetch_command+=( --unshallow )
519 fi 621 fi
520 622
521 set -- "${fetch_command[@]}" 623 set -- "${fetch_command[@]}"
522 echo "${@}" >&2 624 echo "${@}" >&2
523 if "${@}"; then 625 if "${@}"; then
524 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 626 if [[ ${clone_type} == mirror ]]; then
525 # find remote HEAD and update our HEAD properly 627 # find remote HEAD and update our HEAD properly
526 git symbolic-ref HEAD \ 628 git symbolic-ref HEAD \
527 "$(_git-r3_find_head refs/git-r3/HEAD \ 629 "$(_git-r3_find_head refs/git-r3/HEAD \
528 < <(git show-ref --heads || die))" \ 630 < <(git show-ref --heads || die))" \
529 || die "Unable to update HEAD" 631 || die "Unable to update HEAD"
566 break 668 break
567 fi 669 fi
568 done 670 done
569 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 671 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
570 672
673 # submodules can reference commits in any branch
674 # always use the 'clone' mode to accomodate that, bug #503332
675 local EGIT_CLONE_TYPE=mirror
676
571 # recursively fetch submodules 677 # recursively fetch submodules
572 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then 678 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
573 local submodules 679 local submodules
574 _git-r3_set_submodules \ 680 _git-r3_set_submodules \
575 "$(git cat-file -p "${local_ref}":.gitmodules || die)" 681 "$(git cat-file -p "${local_ref}":.gitmodules || die)"
581 local commit=$(git rev-parse "${local_ref}:${path}") 687 local commit=$(git rev-parse "${local_ref}:${path}")
582 688
583 if [[ ! ${commit} ]]; then 689 if [[ ! ${commit} ]]; then
584 die "Unable to get commit id for submodule ${subname}" 690 die "Unable to get commit id for submodule ${subname}"
585 fi 691 fi
586 if [[ ${url} == ./* || ${url} == ../* ]]; then 692
587 local subrepos=( "${repos[@]/%//${url}}" ) 693 local subrepos
588 else 694 _git-r3_set_subrepos "${url}" "${repos[@]}"
589 local subrepos=( "${url}" )
590 fi
591 695
592 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" 696 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
593 697
594 submodules=( "${submodules[@]:3}" ) # shift 698 submodules=( "${submodules[@]:3}" ) # shift
595 done 699 done
717 821
718 while [[ ${submodules[@]} ]]; do 822 while [[ ${submodules[@]} ]]; do
719 local subname=${submodules[0]} 823 local subname=${submodules[0]}
720 local url=${submodules[1]} 824 local url=${submodules[1]}
721 local path=${submodules[2]} 825 local path=${submodules[2]}
826 local subrepos
827 _git-r3_set_subrepos "${url}" "${repos[@]}"
722 828
723 if [[ ${url} == ./* || ${url} == ../* ]]; then
724 url=${repos[0]%%/}/${url}
725 fi
726
727 git-r3_checkout "${url}" "${out_dir}/${path}" \ 829 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \
728 "${local_id}/${subname}" 830 "${local_id}/${subname}"
729 831
730 submodules=( "${submodules[@]:3}" ) # shift 832 submodules=( "${submodules[@]:3}" ) # shift
731 done 833 done
732 fi 834 fi

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.20