/[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.47 Revision 1.51
1# Copyright 1999-2014 Gentoo Foundation 1# Copyright 1999-2015 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.47 2014/07/28 14:13:50 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.51 2015/08/08 09:32: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.
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Third generation eclass for easing maitenance of live ebuilds using 10# Third generation eclass for easing maintenance of live ebuilds using
11# git as remote repository. 11# git as remote repository.
12 12
13case "${EAPI:-0}" in 13case "${EAPI:-0}" in
14 0|1|2|3|4|5) 14 0|1|2|3|4|5)
15 ;; 15 ;;
128 128
129# @ECLASS-VARIABLE: EVCS_OFFLINE 129# @ECLASS-VARIABLE: EVCS_OFFLINE
130# @DEFAULT_UNSET 130# @DEFAULT_UNSET
131# @DESCRIPTION: 131# @DESCRIPTION:
132# If non-empty, this variable prevents any online operations. 132# If non-empty, this variable prevents any online operations.
133
134# @ECLASS-VARIABLE: EVCS_UMASK
135# @DEFAULT_UNSET
136# @DESCRIPTION:
137# Set this variable to a custom umask. This is intended to be set by
138# users. By setting this to something like 002, it can make life easier
139# for people who do development as non-root (but are in the portage
140# group), and then switch over to building with FEATURES=userpriv.
141# Or vice-versa. Shouldn't be a security issue here as anyone who has
142# portage group write access already can screw the system over in more
143# creative ways.
133 144
134# @ECLASS-VARIABLE: EGIT_BRANCH 145# @ECLASS-VARIABLE: EGIT_BRANCH
135# @DEFAULT_UNSET 146# @DEFAULT_UNSET
136# @DESCRIPTION: 147# @DESCRIPTION:
137# The branch name to check out. If unset, the upstream default (HEAD) 148# The branch name to check out. If unset, the upstream default (HEAD)
172 case "${EGIT_MIN_CLONE_TYPE}" in 183 case "${EGIT_MIN_CLONE_TYPE}" in
173 shallow) 184 shallow)
174 ;; 185 ;;
175 single) 186 single)
176 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 187 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
177 einfo "git-r3: ebuild needs to be cloned in 'single' mode, adjusting" 188 einfo "git-r3: ebuild needs to be cloned in '\e[1msingle\e[22m' mode, adjusting"
178 EGIT_CLONE_TYPE=single 189 EGIT_CLONE_TYPE=single
179 fi 190 fi
180 ;; 191 ;;
181 single+tags) 192 single+tags)
182 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then 193 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
183 einfo "git-r3: ebuild needs to be cloned in 'single+tags' mode, adjusting" 194 einfo "git-r3: ebuild needs to be cloned in '\e[1msingle+tags\e[22m' mode, adjusting"
184 EGIT_CLONE_TYPE=single+tags 195 EGIT_CLONE_TYPE=single+tags
185 fi 196 fi
186 ;; 197 ;;
187 mirror) 198 mirror)
188 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then 199 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
189 einfo "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting" 200 einfo "git-r3: ebuild needs to be cloned in '\e[1mmirror\e[22m' mode, adjusting"
190 EGIT_CLONE_TYPE=mirror 201 EGIT_CLONE_TYPE=mirror
191 fi 202 fi
192 ;; 203 ;;
193 *) 204 *)
194 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}" 205 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
307 ) || die "Unable to create ${EGIT3_STORE_DIR}" 318 ) || die "Unable to create ${EGIT3_STORE_DIR}"
308 fi 319 fi
309 320
310 addwrite "${EGIT3_STORE_DIR}" 321 addwrite "${EGIT3_STORE_DIR}"
311 if [[ ! -d ${GIT_DIR} ]]; then 322 if [[ ! -d ${GIT_DIR} ]]; then
323 local saved_umask
324 if [[ ${EVCS_UMASK} ]]; then
325 saved_umask=$(umask)
326 umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}"
327 fi
312 mkdir "${GIT_DIR}" || die 328 mkdir "${GIT_DIR}" || die
313 git init --bare || die 329 git init --bare || die
330 if [[ ${saved_umask} ]]; then
331 umask "${saved_umask}" || die
332 fi
314 fi 333 fi
315} 334}
316 335
317# @FUNCTION: _git-r3_set_submodules 336# @FUNCTION: _git-r3_set_submodules
318# @USAGE: <file-contents> 337# @USAGE: <file-contents>
505 "${repos[@]}" 524 "${repos[@]}"
506 ) 525 )
507 fi 526 fi
508 527
509 # try to fetch from the remote 528 # try to fetch from the remote
510 local r success 529 local r success saved_umask
530 if [[ ${EVCS_UMASK} ]]; then
531 saved_umask=$(umask)
532 umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}"
533 fi
511 for r in "${repos[@]}"; do 534 for r in "${repos[@]}"; do
512 einfo "Fetching ${r} ..." 535 einfo "Fetching \e[1m${r}\e[22m ..."
513 536
514 local fetch_command=( git fetch "${r}" ) 537 local fetch_command=( git fetch "${r}" )
515 local clone_type=${EGIT_CLONE_TYPE} 538 local clone_type=${EGIT_CLONE_TYPE}
516 539
517 if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then 540 if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then
528 # 1) can't handle shallow clones at all, 551 # 1) can't handle shallow clones at all,
529 # 2) fetches duplicately when tags are pulled in with branch 552 # 2) fetches duplicately when tags are pulled in with branch
530 # so automatically switch to single+tags mode. 553 # so automatically switch to single+tags mode.
531 if [[ ${clone_type} == shallow ]]; then 554 if [[ ${clone_type} == shallow ]]; then
532 einfo " Google Code does not support shallow clones" 555 einfo " Google Code does not support shallow clones"
533 einfo " using EGIT_CLONE_TYPE=single+tags" 556 einfo " using \e[1mEGIT_CLONE_TYPE=single+tags\e[22m"
534 clone_type=single+tags 557 clone_type=single+tags
535 elif [[ ${clone_type} == single ]]; then 558 elif [[ ${clone_type} == single ]]; then
536 einfo " git-r3: Google Code does not send tags properly in 'single' mode" 559 einfo " git-r3: Google Code does not send tags properly in 'single' mode"
537 einfo " using EGIT_CLONE_TYPE=single+tags" 560 einfo " using \e[1mEGIT_CLONE_TYPE=single+tags\e[22m"
538 clone_type=single+tags 561 clone_type=single+tags
539 fi 562 fi
540 fi 563 fi
541 564
542 if [[ ${clone_type} == mirror ]]; then 565 if [[ ${clone_type} == mirror ]]; then
666 689
667 success=1 690 success=1
668 break 691 break
669 fi 692 fi
670 done 693 done
694 if [[ ${saved_umask} ]]; then
695 umask "${saved_umask}" || die
696 fi
671 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 697 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
672 698
673 # submodules can reference commits in any branch 699 # submodules can reference commits in any branch
674 # always use the 'clone' mode to accomodate that, bug #503332 700 # always use the 'clone' mode to accomodate that, bug #503332
675 local EGIT_CLONE_TYPE=mirror 701 local EGIT_CLONE_TYPE=mirror
682 708
683 while [[ ${submodules[@]} ]]; do 709 while [[ ${submodules[@]} ]]; do
684 local subname=${submodules[0]} 710 local subname=${submodules[0]}
685 local url=${submodules[1]} 711 local url=${submodules[1]}
686 local path=${submodules[2]} 712 local path=${submodules[2]}
713
714 # use only submodules for which path does exist
715 # (this is in par with 'git submodule'), bug #551100
716 # note: git cat-file does not work for submodules
717 if [[ $(git ls-tree -d "${local_ref}" "${path}") ]]
718 then
687 local commit=$(git rev-parse "${local_ref}:${path}") 719 local commit=$(git rev-parse "${local_ref}:${path}" || die)
688 720
689 if [[ ! ${commit} ]]; then 721 if [[ ! ${commit} ]]; then
690 die "Unable to get commit id for submodule ${subname}" 722 die "Unable to get commit id for submodule ${subname}"
691 fi 723 fi
692 724
693 local subrepos 725 local subrepos
694 _git-r3_set_subrepos "${url}" "${repos[@]}" 726 _git-r3_set_subrepos "${url}" "${repos[@]}"
695 727
696 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" 728 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
729 fi
697 730
698 submodules=( "${submodules[@]:3}" ) # shift 731 submodules=( "${submodules[@]:3}" ) # shift
699 done 732 done
700 fi 733 fi
701} 734}
736 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} 769 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
737 770
738 local -x GIT_DIR 771 local -x GIT_DIR
739 _git-r3_set_gitdir "${repos[0]}" 772 _git-r3_set_gitdir "${repos[0]}"
740 773
741 einfo "Checking out ${repos[0]} to ${out_dir} ..." 774 einfo "Checking out \e[1m${repos[0]}\e[22m to \e[1m${out_dir}\[e22m ..."
742 775
743 if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then 776 if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
744 if [[ ${EVCS_OFFLINE} ]]; then 777 if [[ ${EVCS_OFFLINE} ]]; then
745 die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE." 778 die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE."
746 else 779 else
821 854
822 while [[ ${submodules[@]} ]]; do 855 while [[ ${submodules[@]} ]]; do
823 local subname=${submodules[0]} 856 local subname=${submodules[0]}
824 local url=${submodules[1]} 857 local url=${submodules[1]}
825 local path=${submodules[2]} 858 local path=${submodules[2]}
859
860 # use only submodules for which path does exist
861 # (this is in par with 'git submodule'), bug #551100
862 if [[ -d ${out_dir}/${path} ]]; then
826 local subrepos 863 local subrepos
827 _git-r3_set_subrepos "${url}" "${repos[@]}" 864 _git-r3_set_subrepos "${url}" "${repos[@]}"
828 865
829 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \ 866 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \
830 "${local_id}/${subname}" 867 "${local_id}/${subname}"
868 fi
831 869
832 submodules=( "${submodules[@]:3}" ) # shift 870 submodules=( "${submodules[@]:3}" ) # shift
833 done 871 done
834 fi 872 fi
835 873
876 914
877 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 915 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
878 916
879 local r success 917 local r success
880 for r in "${repos[@]}"; do 918 for r in "${repos[@]}"; do
881 einfo "Peeking ${remote_ref} on ${r} ..." >&2 919 einfo "Peeking \e[1m${remote_ref}\e[22m on \e[1m${r}\e[22m ..." >&2
882 920
883 local is_branch lookup_ref 921 local is_branch lookup_ref
884 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 922 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
885 then 923 then
886 is_branch=1 924 is_branch=1
926 git-r3_src_fetch 964 git-r3_src_fetch
927 git-r3_checkout 965 git-r3_checkout
928} 966}
929 967
930# https://bugs.gentoo.org/show_bug.cgi?id=482666 968# https://bugs.gentoo.org/show_bug.cgi?id=482666
931git-r3_pkg_outofdate() { 969git-r3_pkg_needrebuild() {
932 debug-print-function ${FUNCNAME} "$@" 970 debug-print-function ${FUNCNAME} "$@"
933 971
934 local new_commit_id=$(git-r3_peek_remote_ref) 972 local new_commit_id=$(git-r3_peek_remote_ref)
935 ewarn "old: ${EGIT_VERSION}" 973 [[ ${new_commit_id} && ${EGIT_VERSION} ]] || die "Lookup failed"
936 ewarn "new: ${new_commit_id}" 974
937 [[ ${new_commit_id} && ${old_commit_id} ]] || return 2 975 if [[ ${EGIT_VERSION} != ${new_commit_id} ]]; then
976 einfo "Update from \e[1m${EGIT_VERSION}\e[22m to \e[1m${new_commit_id}\e[22m"
977 else
978 einfo "Local and remote at \e[1m${EGIT_VERSION}\e[22m"
979 fi
938 980
939 [[ ${EGIT_VERSION} != ${new_commit_id} ]] 981 [[ ${EGIT_VERSION} != ${new_commit_id} ]]
940} 982}
983
984# 'export' locally until this gets into EAPI
985pkg_needrebuild() { git-r3_pkg_needrebuild; }
941 986
942_GIT_R3=1 987_GIT_R3=1
943fi 988fi

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

  ViewVC Help
Powered by ViewVC 1.1.20