/[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.44
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.44 2014/06/20 11:40: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.
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.
146_git-r3_env_setup() { 161_git-r3_env_setup() {
147 debug-print-function ${FUNCNAME} "$@" 162 debug-print-function ${FUNCNAME} "$@"
148 163
149 # check the clone type 164 # check the clone type
150 case "${EGIT_CLONE_TYPE}" in 165 case "${EGIT_CLONE_TYPE}" in
151 mirror|single|shallow) 166 mirror|single+tags|single|shallow)
152 ;; 167 ;;
153 *) 168 *)
154 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 169 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
155 esac 170 esac
156 case "${EGIT_MIN_CLONE_TYPE}" in 171 case "${EGIT_MIN_CLONE_TYPE}" in
158 ;; 173 ;;
159 single) 174 single)
160 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 175 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
161 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting" 176 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
162 EGIT_CLONE_TYPE=single 177 EGIT_CLONE_TYPE=single
178 fi
179 ;;
180 single+tags)
181 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
182 einfo "git-r3: ebuild needs to be cloned in 'single+tags' mode, adjusting"
183 EGIT_CLONE_TYPE=single+tags
163 fi 184 fi
164 ;; 185 ;;
165 mirror) 186 mirror)
166 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then 187 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
167 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting" 188 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
329 submodule."${subname}".path || die)" 350 submodule."${subname}".path || die)"
330 ) 351 )
331 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die) 352 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
332} 353}
333 354
355# @FUNCTION: _git-r3_set_subrepos
356# @USAGE: <submodule-uri> <parent-repo-uri>...
357# @INTERNAL
358# @DESCRIPTION:
359# Create 'subrepos' array containing absolute (canonical) submodule URIs
360# for the given <submodule-uri>. If the URI is relative, URIs will be
361# constructed using all <parent-repo-uri>s. Otherwise, this single URI
362# will be placed in the array.
363_git-r3_set_subrepos() {
364 debug-print-function ${FUNCNAME} "$@"
365
366 local suburl=${1}
367 subrepos=( "${@:2}" )
368
369 if [[ ${suburl} == ./* || ${suburl} == ../* ]]; then
370 # drop all possible trailing slashes for consistency
371 subrepos=( "${subrepos[@]%%/}" )
372
373 while true; do
374 if [[ ${suburl} == ./* ]]; then
375 suburl=${suburl:2}
376 elif [[ ${suburl} == ../* ]]; then
377 suburl=${suburl:3}
378
379 # XXX: correctness checking
380
381 # drop the last path component
382 subrepos=( "${subrepos[@]%/*}" )
383 # and then the trailing slashes, again
384 subrepos=( "${subrepos[@]%%/}" )
385 else
386 break
387 fi
388 done
389
390 # append the preprocessed path to the preprocessed URIs
391 subrepos=( "${subrepos[@]/%//${suburl}}")
392 else
393 subrepos=( "${suburl}" )
394 fi
395}
396
397
334# @FUNCTION: _git-r3_is_local_repo 398# @FUNCTION: _git-r3_is_local_repo
335# @USAGE: <repo-uri> 399# @USAGE: <repo-uri>
336# @INTERNAL 400# @INTERNAL
337# @DESCRIPTION: 401# @DESCRIPTION:
338# Determine whether the given URI specifies a local (on-disk) 402# Determine whether the given URI specifies a local (on-disk)
445 local r success 509 local r success
446 for r in "${repos[@]}"; do 510 for r in "${repos[@]}"; do
447 einfo "Fetching ${r} ..." 511 einfo "Fetching ${r} ..."
448 512
449 local fetch_command=( git fetch "${r}" ) 513 local fetch_command=( git fetch "${r}" )
514 local clone_type=${EGIT_CLONE_TYPE}
450 515
451 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 516 if [[ ${r} == https://* ]] && ! has_version 'dev-vcs/git[curl]'; then
517 eerror "git-r3: fetching from https:// requested. In order to support https,"
518 eerror "dev-vcs/git needs to be built with USE=curl. Example solution:"
519 eerror
520 eerror " echo dev-vcs/git curl >> /etc/portage/package.use"
521 eerror " emerge -1v dev-vcs/git"
522 die "dev-vcs/git built with USE=curl required."
523 fi
524
525 if [[ ${r} == https://code.google.com/* ]]; then
526 # Google Code has special magic on top of git that:
527 # 1) can't handle shallow clones at all,
528 # 2) fetches duplicately when tags are pulled in with branch
529 # so automatically switch to single+tags mode.
530 if [[ ${clone_type} == shallow ]]; then
531 einfo " Google Code does not support shallow clones"
532 einfo " using EGIT_CLONE_TYPE=single+tags"
533 clone_type=single+tags
534 elif [[ ${clone_type} == single ]]; then
535 einfo " git-r3: Google Code does not send tags properly in 'single' mode"
536 einfo " using EGIT_CLONE_TYPE=single+tags"
537 clone_type=single+tags
538 fi
539 fi
540
541 if [[ ${clone_type} == mirror ]]; then
452 fetch_command+=( 542 fetch_command+=(
453 --prune 543 --prune
454 # mirror the remote branches as local branches 544 # mirror the remote branches as local branches
455 "refs/heads/*:refs/heads/*" 545 "+refs/heads/*:refs/heads/*"
456 # pull tags explicitly in order to prune them properly 546 # pull tags explicitly in order to prune them properly
457 "refs/tags/*:refs/tags/*" 547 "+refs/tags/*:refs/tags/*"
458 # notes in case something needs them 548 # notes in case something needs them
459 "refs/notes/*:refs/notes/*" 549 "+refs/notes/*:refs/notes/*"
460 # and HEAD in case we need the default branch 550 # and HEAD in case we need the default branch
461 # (we keep it in refs/git-r3 since otherwise --prune interferes) 551 # (we keep it in refs/git-r3 since otherwise --prune interferes)
462 HEAD:refs/git-r3/HEAD 552 "+HEAD:refs/git-r3/HEAD"
463 ) 553 )
464 else # single or shallow 554 else # single or shallow
465 local fetch_l fetch_r 555 local fetch_l fetch_r
466 556
467 if [[ ${remote_ref} == HEAD ]]; then 557 if [[ ${remote_ref} == HEAD ]]; then
487 else 577 else
488 fetch_l=HEAD 578 fetch_l=HEAD
489 fi 579 fi
490 580
491 # fetching by commit in shallow mode? can't do. 581 # fetching by commit in shallow mode? can't do.
492 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 582 if [[ ${clone_type} == shallow ]]; then
493 local EGIT_CLONE_TYPE=single 583 clone_type=single
494 fi 584 fi
495 fi 585 fi
496 fi 586 fi
497 587
498 if [[ ${fetch_l} == HEAD ]]; then 588 if [[ ${fetch_l} == HEAD ]]; then
500 else 590 else
501 fetch_r=${fetch_l} 591 fetch_r=${fetch_l}
502 fi 592 fi
503 593
504 fetch_command+=( 594 fetch_command+=(
505 "${fetch_l}:${fetch_r}" 595 "+${fetch_l}:${fetch_r}"
506 ) 596 )
597
598 if [[ ${clone_type} == single+tags ]]; then
599 fetch_command+=(
600 # pull tags explicitly as requested
601 "+refs/tags/*:refs/tags/*"
602 )
507 fi 603 fi
604 fi
508 605
509 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 606 if [[ ${clone_type} == shallow ]]; then
510 # use '--depth 1' when fetching a new branch 607 if _git-r3_is_local_repo; then
608 # '--depth 1' causes sandbox violations with local repos
609 # bug #491260
610 clone_type=single
511 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] 611 elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
512 then 612 then
613 # use '--depth 1' when fetching a new branch
513 fetch_command+=( --depth 1 ) 614 fetch_command+=( --depth 1 )
514 fi 615 fi
515 else # non-shallow mode 616 else # non-shallow mode
516 if [[ -f ${GIT_DIR}/shallow ]]; then 617 if [[ -f ${GIT_DIR}/shallow ]]; then
517 fetch_command+=( --unshallow ) 618 fetch_command+=( --unshallow )
519 fi 620 fi
520 621
521 set -- "${fetch_command[@]}" 622 set -- "${fetch_command[@]}"
522 echo "${@}" >&2 623 echo "${@}" >&2
523 if "${@}"; then 624 if "${@}"; then
524 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 625 if [[ ${clone_type} == mirror ]]; then
525 # find remote HEAD and update our HEAD properly 626 # find remote HEAD and update our HEAD properly
526 git symbolic-ref HEAD \ 627 git symbolic-ref HEAD \
527 "$(_git-r3_find_head refs/git-r3/HEAD \ 628 "$(_git-r3_find_head refs/git-r3/HEAD \
528 < <(git show-ref --heads || die))" \ 629 < <(git show-ref --heads || die))" \
529 || die "Unable to update HEAD" 630 || die "Unable to update HEAD"
566 break 667 break
567 fi 668 fi
568 done 669 done
569 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 670 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
570 671
672 # submodules can reference commits in any branch
673 # always use the 'clone' mode to accomodate that, bug #503332
674 local EGIT_CLONE_TYPE=mirror
675
571 # recursively fetch submodules 676 # recursively fetch submodules
572 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then 677 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
573 local submodules 678 local submodules
574 _git-r3_set_submodules \ 679 _git-r3_set_submodules \
575 "$(git cat-file -p "${local_ref}":.gitmodules || die)" 680 "$(git cat-file -p "${local_ref}":.gitmodules || die)"
581 local commit=$(git rev-parse "${local_ref}:${path}") 686 local commit=$(git rev-parse "${local_ref}:${path}")
582 687
583 if [[ ! ${commit} ]]; then 688 if [[ ! ${commit} ]]; then
584 die "Unable to get commit id for submodule ${subname}" 689 die "Unable to get commit id for submodule ${subname}"
585 fi 690 fi
586 if [[ ${url} == ./* || ${url} == ../* ]]; then 691
587 local subrepos=( "${repos[@]/%//${url}}" ) 692 local subrepos
588 else 693 _git-r3_set_subrepos "${url}" "${repos[@]}"
589 local subrepos=( "${url}" )
590 fi
591 694
592 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" 695 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
593 696
594 submodules=( "${submodules[@]:3}" ) # shift 697 submodules=( "${submodules[@]:3}" ) # shift
595 done 698 done
717 820
718 while [[ ${submodules[@]} ]]; do 821 while [[ ${submodules[@]} ]]; do
719 local subname=${submodules[0]} 822 local subname=${submodules[0]}
720 local url=${submodules[1]} 823 local url=${submodules[1]}
721 local path=${submodules[2]} 824 local path=${submodules[2]}
825 local subrepos
826 _git-r3_set_subrepos "${url}" "${repos[@]}"
722 827
723 if [[ ${url} == ./* || ${url} == ../* ]]; then
724 url=${repos[0]%%/}/${url}
725 fi
726
727 git-r3_checkout "${url}" "${out_dir}/${path}" \ 828 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \
728 "${local_id}/${subname}" 829 "${local_id}/${subname}"
729 830
730 submodules=( "${submodules[@]:3}" ) # shift 831 submodules=( "${submodules[@]:3}" ) # shift
731 done 832 done
732 fi 833 fi

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

  ViewVC Help
Powered by ViewVC 1.1.20