/[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.43 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.43 2014/06/01 22:07:59 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 ;;
112# @ECLASS-VARIABLE: EGIT_REPO_URI 112# @ECLASS-VARIABLE: EGIT_REPO_URI
113# @REQUIRED 113# @REQUIRED
114# @DESCRIPTION: 114# @DESCRIPTION:
115# 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
116# 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
117# 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).
118# 119#
119# It can be overriden via env using ${PN}_LIVE_REPO variable. 120# It can be overriden via env using ${PN}_LIVE_REPO variable.
120# 121#
121# Can be a whitespace-separated list or an array. 122# Can be a whitespace-separated list or an array.
122# 123#
127 128
128# @ECLASS-VARIABLE: EVCS_OFFLINE 129# @ECLASS-VARIABLE: EVCS_OFFLINE
129# @DEFAULT_UNSET 130# @DEFAULT_UNSET
130# @DESCRIPTION: 131# @DESCRIPTION:
131# 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.
132 144
133# @ECLASS-VARIABLE: EGIT_BRANCH 145# @ECLASS-VARIABLE: EGIT_BRANCH
134# @DEFAULT_UNSET 146# @DEFAULT_UNSET
135# @DESCRIPTION: 147# @DESCRIPTION:
136# 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)
171 case "${EGIT_MIN_CLONE_TYPE}" in 183 case "${EGIT_MIN_CLONE_TYPE}" in
172 shallow) 184 shallow)
173 ;; 185 ;;
174 single) 186 single)
175 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then 187 if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
176 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"
177 EGIT_CLONE_TYPE=single 189 EGIT_CLONE_TYPE=single
178 fi 190 fi
179 ;; 191 ;;
180 single+tags) 192 single+tags)
181 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then 193 if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then
182 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"
183 EGIT_CLONE_TYPE=single+tags 195 EGIT_CLONE_TYPE=single+tags
184 fi 196 fi
185 ;; 197 ;;
186 mirror) 198 mirror)
187 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then 199 if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
188 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"
189 EGIT_CLONE_TYPE=mirror 201 EGIT_CLONE_TYPE=mirror
190 fi 202 fi
191 ;; 203 ;;
192 *) 204 *)
193 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}" 205 die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
300 GIT_DIR=${EGIT3_STORE_DIR}/${repo_name} 312 GIT_DIR=${EGIT3_STORE_DIR}/${repo_name}
301 313
302 if [[ ! -d ${EGIT3_STORE_DIR} ]]; then 314 if [[ ! -d ${EGIT3_STORE_DIR} ]]; then
303 ( 315 (
304 addwrite / 316 addwrite /
305 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die 317 mkdir -p "${EGIT3_STORE_DIR}" || die
306 ) || die "Unable to create ${EGIT3_STORE_DIR}" 318 ) || die "Unable to create ${EGIT3_STORE_DIR}"
307 fi 319 fi
308 320
309 addwrite "${EGIT3_STORE_DIR}" 321 addwrite "${EGIT3_STORE_DIR}"
310 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
311 mkdir "${GIT_DIR}" || die 328 mkdir "${GIT_DIR}" || die
312 git init --bare || die 329 git init --bare || die
330 if [[ ${saved_umask} ]]; then
331 umask "${saved_umask}" || die
332 fi
313 fi 333 fi
314} 334}
315 335
316# @FUNCTION: _git-r3_set_submodules 336# @FUNCTION: _git-r3_set_submodules
317# @USAGE: <file-contents> 337# @USAGE: <file-contents>
504 "${repos[@]}" 524 "${repos[@]}"
505 ) 525 )
506 fi 526 fi
507 527
508 # try to fetch from the remote 528 # try to fetch from the remote
509 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
510 for r in "${repos[@]}"; do 534 for r in "${repos[@]}"; do
511 einfo "Fetching ${r} ..." 535 einfo "Fetching \e[1m${r}\e[22m ..."
512 536
513 local fetch_command=( git fetch "${r}" ) 537 local fetch_command=( git fetch "${r}" )
514 local clone_type=${EGIT_CLONE_TYPE} 538 local clone_type=${EGIT_CLONE_TYPE}
515 539
516 if [[ ${r} == https://* ]] && ! has_version 'dev-vcs/git[curl]'; then 540 if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then
517 eerror "git-r3: fetching from https:// requested. In order to support https," 541 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:" 542 eerror "dev-vcs/git needs to be built with USE=curl. Example solution:"
519 eerror 543 eerror
520 eerror " echo dev-vcs/git curl >> /etc/portage/package.use" 544 eerror " echo dev-vcs/git curl >> /etc/portage/package.use"
521 eerror " emerge -1v dev-vcs/git" 545 eerror " emerge -1v dev-vcs/git"
527 # 1) can't handle shallow clones at all, 551 # 1) can't handle shallow clones at all,
528 # 2) fetches duplicately when tags are pulled in with branch 552 # 2) fetches duplicately when tags are pulled in with branch
529 # so automatically switch to single+tags mode. 553 # so automatically switch to single+tags mode.
530 if [[ ${clone_type} == shallow ]]; then 554 if [[ ${clone_type} == shallow ]]; then
531 einfo " Google Code does not support shallow clones" 555 einfo " Google Code does not support shallow clones"
532 einfo " using EGIT_CLONE_TYPE=single+tags" 556 einfo " using \e[1mEGIT_CLONE_TYPE=single+tags\e[22m"
533 clone_type=single+tags 557 clone_type=single+tags
534 elif [[ ${clone_type} == single ]]; then 558 elif [[ ${clone_type} == single ]]; then
535 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"
536 einfo " using EGIT_CLONE_TYPE=single+tags" 560 einfo " using \e[1mEGIT_CLONE_TYPE=single+tags\e[22m"
537 clone_type=single+tags 561 clone_type=single+tags
538 fi 562 fi
539 fi 563 fi
540 564
541 if [[ ${clone_type} == mirror ]]; then 565 if [[ ${clone_type} == mirror ]]; then
665 689
666 success=1 690 success=1
667 break 691 break
668 fi 692 fi
669 done 693 done
694 if [[ ${saved_umask} ]]; then
695 umask "${saved_umask}" || die
696 fi
670 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" 697 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
671 698
672 # submodules can reference commits in any branch 699 # submodules can reference commits in any branch
673 # always use the 'clone' mode to accomodate that, bug #503332 700 # always use the 'clone' mode to accomodate that, bug #503332
674 local EGIT_CLONE_TYPE=mirror 701 local EGIT_CLONE_TYPE=mirror
681 708
682 while [[ ${submodules[@]} ]]; do 709 while [[ ${submodules[@]} ]]; do
683 local subname=${submodules[0]} 710 local subname=${submodules[0]}
684 local url=${submodules[1]} 711 local url=${submodules[1]}
685 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
686 local commit=$(git rev-parse "${local_ref}:${path}") 719 local commit=$(git rev-parse "${local_ref}:${path}" || die)
687 720
688 if [[ ! ${commit} ]]; then 721 if [[ ! ${commit} ]]; then
689 die "Unable to get commit id for submodule ${subname}" 722 die "Unable to get commit id for submodule ${subname}"
690 fi 723 fi
691 724
692 local subrepos 725 local subrepos
693 _git-r3_set_subrepos "${url}" "${repos[@]}" 726 _git-r3_set_subrepos "${url}" "${repos[@]}"
694 727
695 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" 728 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
729 fi
696 730
697 submodules=( "${submodules[@]:3}" ) # shift 731 submodules=( "${submodules[@]:3}" ) # shift
698 done 732 done
699 fi 733 fi
700} 734}
735 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} 769 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
736 770
737 local -x GIT_DIR 771 local -x GIT_DIR
738 _git-r3_set_gitdir "${repos[0]}" 772 _git-r3_set_gitdir "${repos[0]}"
739 773
740 einfo "Checking out ${repos[0]} to ${out_dir} ..." 774 einfo "Checking out \e[1m${repos[0]}\e[22m to \e[1m${out_dir}\[e22m ..."
741 775
742 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
743 if [[ ${EVCS_OFFLINE} ]]; then 777 if [[ ${EVCS_OFFLINE} ]]; then
744 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."
745 else 779 else
820 854
821 while [[ ${submodules[@]} ]]; do 855 while [[ ${submodules[@]} ]]; do
822 local subname=${submodules[0]} 856 local subname=${submodules[0]}
823 local url=${submodules[1]} 857 local url=${submodules[1]}
824 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
825 local subrepos 863 local subrepos
826 _git-r3_set_subrepos "${url}" "${repos[@]}" 864 _git-r3_set_subrepos "${url}" "${repos[@]}"
827 865
828 git-r3_checkout "${url}" "${out_dir}/${path}" \ 866 git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \
829 "${local_id}/${subname}" 867 "${local_id}/${subname}"
868 fi
830 869
831 submodules=( "${submodules[@]:3}" ) # shift 870 submodules=( "${submodules[@]:3}" ) # shift
832 done 871 done
833 fi 872 fi
834 873
875 914
876 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 915 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
877 916
878 local r success 917 local r success
879 for r in "${repos[@]}"; do 918 for r in "${repos[@]}"; do
880 einfo "Peeking ${remote_ref} on ${r} ..." >&2 919 einfo "Peeking \e[1m${remote_ref}\e[22m on \e[1m${r}\e[22m ..." >&2
881 920
882 local is_branch lookup_ref 921 local is_branch lookup_ref
883 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]] 922 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
884 then 923 then
885 is_branch=1 924 is_branch=1
925 git-r3_src_fetch 964 git-r3_src_fetch
926 git-r3_checkout 965 git-r3_checkout
927} 966}
928 967
929# https://bugs.gentoo.org/show_bug.cgi?id=482666 968# https://bugs.gentoo.org/show_bug.cgi?id=482666
930git-r3_pkg_outofdate() { 969git-r3_pkg_needrebuild() {
931 debug-print-function ${FUNCNAME} "$@" 970 debug-print-function ${FUNCNAME} "$@"
932 971
933 local new_commit_id=$(git-r3_peek_remote_ref) 972 local new_commit_id=$(git-r3_peek_remote_ref)
934 ewarn "old: ${EGIT_VERSION}" 973 [[ ${new_commit_id} && ${EGIT_VERSION} ]] || die "Lookup failed"
935 ewarn "new: ${new_commit_id}" 974
936 [[ ${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
937 980
938 [[ ${EGIT_VERSION} != ${new_commit_id} ]] 981 [[ ${EGIT_VERSION} != ${new_commit_id} ]]
939} 982}
983
984# 'export' locally until this gets into EAPI
985pkg_needrebuild() { git-r3_pkg_needrebuild; }
940 986
941_GIT_R3=1 987_GIT_R3=1
942fi 988fi

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

  ViewVC Help
Powered by ViewVC 1.1.20