/[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.33 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.33 2014/03/02 11:48: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
56# unavailable calls like 'git describe' will not reference prior tags. 67# unavailable calls like 'git describe' will not reference prior tags.
57# No purging of old references is done. This mode is intended mostly for 68# No purging of old references is done. This mode is intended mostly for
58# embedded systems with limited disk space. 69# embedded systems with limited disk space.
59: ${EGIT_CLONE_TYPE:=single} 70: ${EGIT_CLONE_TYPE:=single}
60 71
72# @ECLASS-VARIABLE: EGIT_MIN_CLONE_TYPE
73# @DESCRIPTION:
74# 'Minimum' clone type supported by the ebuild. Takes same values
75# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is,
76# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
77# EGIT_MIN_CLONE_TYPE instead.
78#
79# This variable is intended to be used by ebuilds only. Users are
80# supposed to set EGIT_CLONE_TYPE instead.
81#
82# A common case is to use 'single' whenever the build system requires
83# access to full branch history, or 'single+tags' when Google Code
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
86# fatal errors rather than 'non-pretty versions'.
87: ${EGIT_MIN_CLONE_TYPE:=shallow}
88
61# @ECLASS-VARIABLE: EGIT3_STORE_DIR 89# @ECLASS-VARIABLE: EGIT3_STORE_DIR
62# @DESCRIPTION: 90# @DESCRIPTION:
63# Storage directory for git sources. 91# Storage directory for git sources.
64# 92#
65# This is intended to be set by user in make.conf. Ebuilds must not set 93# This is intended to be set by user in make.conf. Ebuilds must not set
133_git-r3_env_setup() { 161_git-r3_env_setup() {
134 debug-print-function ${FUNCNAME} "$@" 162 debug-print-function ${FUNCNAME} "$@"
135 163
136 # check the clone type 164 # check the clone type
137 case "${EGIT_CLONE_TYPE}" in 165 case "${EGIT_CLONE_TYPE}" in
138 mirror|single|shallow) 166 mirror|single+tags|single|shallow)
139 ;; 167 ;;
140 *) 168 *)
141 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" 169 die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
170 esac
171 case "${EGIT_MIN_CLONE_TYPE}" in
172 shallow)
173 ;;
174 single)
175 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
176 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
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
184 fi
185 ;;
186 mirror)
187 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
188 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
189 EGIT_CLONE_TYPE=mirror
190 fi
191 ;;
192 *)
193 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
142 esac 194 esac
143 195
144 local esc_pn livevar 196 local esc_pn livevar
145 esc_pn=${PN//[-+]/_} 197 esc_pn=${PN//[-+]/_}
146 198
298 submodule."${subname}".path || die)" 350 submodule."${subname}".path || die)"
299 ) 351 )
300 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die) 352 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
301} 353}
302 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
303# @FUNCTION: _git-r3_is_local_repo 398# @FUNCTION: _git-r3_is_local_repo
304# @USAGE: <repo-uri> 399# @USAGE: <repo-uri>
305# @INTERNAL 400# @INTERNAL
306# @DESCRIPTION: 401# @DESCRIPTION:
307# Determine whether the given URI specifies a local (on-disk) 402# Determine whether the given URI specifies a local (on-disk)
414 local r success 509 local r success
415 for r in "${repos[@]}"; do 510 for r in "${repos[@]}"; do
416 einfo "Fetching ${r} ..." 511 einfo "Fetching ${r} ..."
417 512
418 local fetch_command=( git fetch "${r}" ) 513 local fetch_command=( git fetch "${r}" )
514 local clone_type=${EGIT_CLONE_TYPE}
419 515
420 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
421 fetch_command+=( 542 fetch_command+=(
422 --prune 543 --prune
423 # mirror the remote branches as local branches 544 # mirror the remote branches as local branches
424 "refs/heads/*:refs/heads/*" 545 "+refs/heads/*:refs/heads/*"
425 # pull tags explicitly in order to prune them properly 546 # pull tags explicitly in order to prune them properly
426 "refs/tags/*:refs/tags/*" 547 "+refs/tags/*:refs/tags/*"
427 # notes in case something needs them 548 # notes in case something needs them
428 "refs/notes/*:refs/notes/*" 549 "+refs/notes/*:refs/notes/*"
429 # and HEAD in case we need the default branch 550 # and HEAD in case we need the default branch
430 # (we keep it in refs/git-r3 since otherwise --prune interferes) 551 # (we keep it in refs/git-r3 since otherwise --prune interferes)
431 HEAD:refs/git-r3/HEAD 552 "+HEAD:refs/git-r3/HEAD"
432 ) 553 )
433 else # single or shallow 554 else # single or shallow
434 local fetch_l fetch_r 555 local fetch_l fetch_r
435 556
436 if [[ ${remote_ref} == HEAD ]]; then 557 if [[ ${remote_ref} == HEAD ]]; then
447 # if it was a tag, ls-remote obtained a hash 568 # if it was a tag, ls-remote obtained a hash
448 if [[ ${tagref} ]]; then 569 if [[ ${tagref} ]]; then
449 # tag 570 # tag
450 fetch_l=refs/tags/${remote_ref} 571 fetch_l=refs/tags/${remote_ref}
451 else 572 else
573 # commit
452 # commit, so we need to fetch the branch 574 # so we need to fetch the branch
453 # and guess where it takes us...
454 if [[ ${branch} ]]; then 575 if [[ ${branch} ]]; then
455 fetch_l=${branch} 576 fetch_l=${branch}
456 else 577 else
457 fetch_l=HEAD 578 fetch_l=HEAD
458 fi 579 fi
580
581 # fetching by commit in shallow mode? can't do.
582 if [[ ${clone_type} == shallow ]]; then
583 clone_type=single
584 fi
459 fi 585 fi
460 fi 586 fi
461 587
462 if [[ ${fetch_l} == HEAD ]]; then 588 if [[ ${fetch_l} == HEAD ]]; then
463 fetch_r=refs/git-r3/HEAD 589 fetch_r=refs/git-r3/HEAD
464 else 590 else
465 fetch_r=${fetch_l} 591 fetch_r=${fetch_l}
466 fi 592 fi
467 593
468 fetch_command+=( 594 fetch_command+=(
469 "${fetch_l}:${fetch_r}" 595 "+${fetch_l}:${fetch_r}"
470 ) 596 )
597
598 if [[ ${clone_type} == single+tags ]]; then
599 fetch_command+=(
600 # pull tags explicitly as requested
601 "+refs/tags/*:refs/tags/*"
602 )
471 fi 603 fi
604 fi
472 605
473 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 606 if [[ ${clone_type} == shallow ]]; then
474 # 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
475 if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] 611 elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
476 then 612 then
613 # use '--depth 1' when fetching a new branch
477 fetch_command+=( --depth 1 ) 614 fetch_command+=( --depth 1 )
478 fi 615 fi
479 else # non-shallow mode 616 else # non-shallow mode
480 if [[ -f ${GIT_DIR}/shallow ]]; then 617 if [[ -f ${GIT_DIR}/shallow ]]; then
481 fetch_command+=( --unshallow ) 618 fetch_command+=( --unshallow )
483 fi 620 fi
484 621
485 set -- "${fetch_command[@]}" 622 set -- "${fetch_command[@]}"
486 echo "${@}" >&2 623 echo "${@}" >&2
487 if "${@}"; then 624 if "${@}"; then
488 if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then 625 if [[ ${clone_type} == mirror ]]; then
489 # find remote HEAD and update our HEAD properly 626 # find remote HEAD and update our HEAD properly
490 git symbolic-ref HEAD \ 627 git symbolic-ref HEAD \
491 "$(_git-r3_find_head refs/git-r3/HEAD \ 628 "$(_git-r3_find_head refs/git-r3/HEAD \
492 < <(git show-ref --heads || die))" \ 629 < <(git show-ref --heads || die))" \
493 || die "Unable to update HEAD" 630 || die "Unable to update HEAD"
530 break 667 break
531 fi 668 fi
532 done 669 done
533 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 670 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
534 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
535 # recursively fetch submodules 676 # recursively fetch submodules
536 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then 677 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
537 local submodules 678 local submodules
538 _git-r3_set_submodules \ 679 _git-r3_set_submodules \
539 "$(git cat-file -p "${local_ref}":.gitmodules || die)" 680 "$(git cat-file -p "${local_ref}":.gitmodules || die)"
545 local commit=$(git rev-parse "${local_ref}:${path}") 686 local commit=$(git rev-parse "${local_ref}:${path}")
546 687
547 if [[ ! ${commit} ]]; then 688 if [[ ! ${commit} ]]; then
548 die "Unable to get commit id for submodule ${subname}" 689 die "Unable to get commit id for submodule ${subname}"
549 fi 690 fi
550 if [[ ${url} == ./* || ${url} == ../* ]]; then 691
551 local subrepos=( "${repos[@]/%//${url}}" ) 692 local subrepos
552 else 693 _git-r3_set_subrepos "${url}" "${repos[@]}"
553 local subrepos=( "${url}" )
554 fi
555 694
556 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" 695 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
557 696
558 submodules=( "${submodules[@]:3}" ) # shift 697 submodules=( "${submodules[@]:3}" ) # shift
559 done 698 done
681 820
682 while [[ ${submodules[@]} ]]; do 821 while [[ ${submodules[@]} ]]; do
683 local subname=${submodules[0]} 822 local subname=${submodules[0]}
684 local url=${submodules[1]} 823 local url=${submodules[1]}
685 local path=${submodules[2]} 824 local path=${submodules[2]}
825 local subrepos
826 _git-r3_set_subrepos "${url}" "${repos[@]}"
686 827
687 if [[ ${url} == ./* || ${url} == ../* ]]; then
688 url=${repos[0]%%/}/${url}
689 fi
690
691 git-r3_checkout "${url}" "${out_dir}/${path}" \ 828 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \
692 "${local_id}/${subname}" 829 "${local_id}/${subname}"
693 830
694 submodules=( "${submodules[@]:3}" ) # shift 831 submodules=( "${submodules[@]:3}" ) # shift
695 done 832 done
696 fi 833 fi

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

  ViewVC Help
Powered by ViewVC 1.1.20