/[gentoo-x86]/eclass/git.eclass
Gentoo

Diff of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.18 Revision 1.28
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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/Attic/git.eclass,v 1.18 2009/04/06 00:00:47 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/git.eclass,v 1.28 2009/08/24 21:48:58 scarabeus Exp $
4 4
5# @ECLASS: git.eclass 5# @ECLASS: git.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Tomas Chvatal <scarabeus@gentoo.org> 7# Tomas Chvatal <scarabeus@gentoo.org>
8# Donnie Berkholz <dberkholz@gentoo.org> 8# Donnie Berkholz <dberkholz@gentoo.org>
9# @BLURB: This eclass provides functions for fetch and unpack git repozitories 9# @BLURB: This eclass provides functions for fetch and unpack git repositories
10# @DESCRIPTION: 10# @DESCRIPTION:
11# The eclass is based on subversion eclass. 11# The eclass is based on subversion eclass.
12# If you use this eclass, the ${S} is ${WORKDIR}/${P}. 12# If you use this eclass, the ${S} is ${WORKDIR}/${P}.
13# It is necessary to define the EGIT_REPO_URI variable at least. 13# It is necessary to define the EGIT_REPO_URI variable at least.
14# @THANKS TO: 14# @THANKS TO:
18 18
19EGIT="git.eclass" 19EGIT="git.eclass"
20 20
21EXPORTED_FUNCTIONS="src_unpack" 21EXPORTED_FUNCTIONS="src_unpack"
22case "${EAPI:-0}" in 22case "${EAPI:-0}" in
23 2) EXPORT_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;; 23 2) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;;
24 0|1) ;; 24 0|1) ;;
25 *) die "Unknown EAPI, Bug eclass maintainers." ;; 25 *) die "Unknown EAPI, Bug eclass maintainers." ;;
26esac 26esac
27EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS} 27EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
28 28
39: ${EGIT_QUIET:="OFF"} 39: ${EGIT_QUIET:="OFF"}
40 40
41# @ECLASS-VARIABLE: EGIT_STORE_DIR 41# @ECLASS-VARIABLE: EGIT_STORE_DIR
42# @DESCRIPTION: 42# @DESCRIPTION:
43# Storage directory for git sources. 43# Storage directory for git sources.
44# Can be redefined.
44EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" 45[[ -z ${EGIT_STORE_DIR} ]] && EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src"
45 46
46# @ECLASS-VARIABLE: EGIT_FETCH_CMD 47# @ECLASS-VARIABLE: EGIT_FETCH_CMD
47# @DESCRIPTION: 48# @DESCRIPTION:
48# Command for cloning the repository. 49# Command for cloning the repository.
49EGIT_FETCH_CMD="git clone --bare" 50: ${EGIT_FETCH_CMD:="git clone --bare"}
50 51
51# @ECLASS-VARIABLE: EGIT_UPDATE_CMD 52# @ECLASS-VARIABLE: EGIT_UPDATE_CMD
52# @DESCRIPTION: 53# @DESCRIPTION:
53# Git fetch command. 54# Git fetch command.
54EGIT_UPDATE_CMD="git fetch -f -u" 55EGIT_UPDATE_CMD="git fetch -f -u"
72# https:// 73# https://
73# git:// 74# git://
74# git+ssh:// 75# git+ssh://
75# rsync:// 76# rsync://
76# ssh:// 77# ssh://
77: ${EGIT_REPO_URI:=} 78eval X="\$${PN//-/_}_LIVE_REPO"
78 79if [[ ${X} = "" ]]; then
80 EGIT_REPO_URI=${EGIT_REPO_URI:=}
81else
82 EGIT_REPO_URI="${X}"
83fi
79# @ECLASS-VARIABLE: EGIT_PROJECT 84# @ECLASS-VARIABLE: EGIT_PROJECT
80# @DESCRIPTION: 85# @DESCRIPTION:
81# Project name of your ebuild. 86# Project name of your ebuild.
82# Git eclass will check out the git repository like: 87# Git eclass will check out the git repository like:
83# ${EGIT_STORE_DIR}/${EGIT_PROJECT}/${EGIT_REPO_URI##*/} 88# ${EGIT_STORE_DIR}/${EGIT_PROJECT}/${EGIT_REPO_URI##*/}
106# Please take note that this variable should be bash array. 111# Please take note that this variable should be bash array.
107 112
108# @ECLASS-VARIABLE: EGIT_BRANCH 113# @ECLASS-VARIABLE: EGIT_BRANCH
109# @DESCRIPTION: 114# @DESCRIPTION:
110# git eclass can fetch any branch in git_fetch(). 115# git eclass can fetch any branch in git_fetch().
111: ${EGIT_BRANCH:=master} 116eval X="\$${PN//-/_}_LIVE_BRANCH"
117if [[ ${X} = "" ]]; then
118 EGIT_BRANCH=${EGIT_BRANCH:=master}
119else
120 EGIT_BRANCH="${X}"
121fi
112 122
113# @ECLASS-VARIABLE: EGIT_TREE 123# @ECLASS-VARIABLE: EGIT_TREE
114# @DESCRIPTION: 124# @DESCRIPTION:
115# git eclass can checkout any tree. 125# git eclass can checkout any tree (commit).
126eval X="\$${PN//-/_}_LIVE_TREE"
127if [[ ${X} = "" ]]; then
116: ${EGIT_TREE:=${EGIT_BRANCH}} 128 : ${EGIT_TREE:=${EGIT_BRANCH}}
129else
130 EGIT_TREE="${X}"
131fi
117 132
118# @ECLASS-VARIABLE: EGIT_REPACK 133# @ECLASS-VARIABLE: EGIT_REPACK
119# @DESCRIPTION: 134# @DESCRIPTION:
120# git eclass will repack objects to save disk space. However this can take a 135# git eclass will repack objects to save disk space. However this can take a
121# long time with VERY big repositories. 136# long time with VERY big repositories.
142 elogcmd="elog" 157 elogcmd="elog"
143 fi 158 fi
144 159
145 # If we have same branch and the tree we can do --depth 1 clone 160 # If we have same branch and the tree we can do --depth 1 clone
146 # which outputs into really smaller data transfers. 161 # which outputs into really smaller data transfers.
147 # Sadly we can do shallow copy for now because quite few packages need .git 162 # Sadly we can do shallow copy for now because quite a few packages need .git
148 # folder. 163 # folder.
149 #[[ ${EGIT_TREE} = ${EGIT_BRANCH} ]] && \ 164 #[[ ${EGIT_TREE} = ${EGIT_BRANCH} ]] && \
150 # EGIT_FETCH_CMD="${EGIT_FETCH_CMD} --depth 1" 165 # EGIT_FETCH_CMD="${EGIT_FETCH_CMD} --depth 1"
151 166
152 # EGIT_REPO_URI is empty. 167 # EGIT_REPO_URI is empty.
181 196
182 debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"" 197 debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\""
183 198
184 export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" 199 export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
185 200
201 # we also have to remove all shallow copied repositories
202 # and fetch them again
203 if [[ -e "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}/shallow" ]]; then
204 rm -rf "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
205 einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching."
206 fi
207
186 if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then 208 if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then
187 # first clone 209 # first clone
188 ${elogcmd} "GIT NEW clone -->" 210 ${elogcmd} "GIT NEW clone -->"
189 ${elogcmd} " repository: ${EGIT_REPO_URI}" 211 ${elogcmd} " repository: ${EGIT_REPO_URI}"
190 212
191 ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \ 213 ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \
192 || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." 214 || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."
193 215
194 oldsha1=$(git rev-parse ${EGIT_BRANCH}) 216 cursha1=$(git rev-parse ${EGIT_BRANCH})
195 ${elogcmd} " at the commit: ${oldsha1}" 217 ${elogcmd} " at the commit: ${cursha1}"
196
197 # We use --bare cloning, so git doesn't do this for us. 218 # We use --bare cloning, so git doesn't do this for us.
198 git config remote.origin.url "${EGIT_REPO_URI}" 219 git config remote.origin.url "${EGIT_REPO_URI}"
199 elif [[ -n ${EGIT_OFFLINE} ]] ; then 220 elif [[ -n ${EGIT_OFFLINE} ]] ; then
200 oldsha1=$(git rev-parse ${EGIT_BRANCH}) 221 cursha1=$(git rev-parse ${EGIT_BRANCH})
201 ${elogcmd} "GIT offline update -->" 222 ${elogcmd} "GIT offline update -->"
202 ${elogcmd} " repository: ${EGIT_REPO_URI}" 223 ${elogcmd} " repository: ${EGIT_REPO_URI}"
203 ${elogcmd} " at the commit: ${oldsha1}" 224 ${elogcmd} " at the commit: ${cursha1}"
204 else 225 else
205 # Git urls might change, so unconditionally set it here 226 # Git urls might change, so unconditionally set it here
206 git config remote.origin.url "${EGIT_REPO_URI}" 227 git config remote.origin.url "${EGIT_REPO_URI}"
207 228
208 # fetch updates 229 # fetch updates
209 ${elogcmd} "GIT update -->" 230 ${elogcmd} "GIT update -->"
210 ${elogcmd} " repository: ${EGIT_REPO_URI}" 231 ${elogcmd} " repository: ${EGIT_REPO_URI}"
211 232
212 oldsha1=$(git rev-parse ${EGIT_BRANCH}) 233 oldsha1=$(git rev-parse ${EGIT_BRANCH})
213 234
235 ${elogcmd} ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH}
214 ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \ 236 ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \
215 || die "${EGIT}: can't update from ${EGIT_REPO_URI}." 237 || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
216 238
217 cursha1=$(git rev-parse ${EGIT_BRANCH}) 239 cursha1=$(git rev-parse ${EGIT_BRANCH})
218 240
220 if [[ ${oldsha1} != ${cursha1} ]]; then 242 if [[ ${oldsha1} != ${cursha1} ]]; then
221 ${elogcmd} " updating from commit: ${oldsha1}" 243 ${elogcmd} " updating from commit: ${oldsha1}"
222 ${elogcmd} " to commit: ${cursha1}" 244 ${elogcmd} " to commit: ${cursha1}"
223 else 245 else
224 ${elogcmd} " at the commit: ${cursha1}" 246 ${elogcmd} " at the commit: ${cursha1}"
247 # @ECLASS_VARIABLE: LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED
248 # @DESCRIPTION:
249 # If this variable is set to TRUE in make.conf or somewhere in
250 # enviroment the package will fail if there is no update, thus in
251 # combination with --keep-going it would lead in not-updating
252 # pakcages that are up-to-date.
253 # TODO: this can lead to issues if more projects/packages use same repo
254 [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \
255 debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \
256 die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping."
225 fi 257 fi
226 # piping through cat is needed to avoid a stupid Git feature
227 ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} 258 ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH}
228 fi 259 fi
229 260
230 if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then 261 if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then
231 ebegin "Garbage collecting the repository" 262 ebegin "Garbage collecting the repository"
232 git gc $(${EGIT_PRUNE} && echo '--prune') 263 git gc $(${EGIT_PRUNE} && echo '--prune')
233 eend $? 264 eend $?
234 fi 265 fi
266
267 # export the git version
268 export EGIT_VERSION="${cursha1}"
235 269
236 [[ ${EGIT_TREE} != ${EGIT_BRANCH} ]] && elog " tree: ${EGIT_TREE}" 270 [[ ${EGIT_TREE} != ${EGIT_BRANCH} ]] && elog " tree: ${EGIT_TREE}"
237 ${elogcmd} " branch: ${EGIT_BRANCH}" 271 ${elogcmd} " branch: ${EGIT_BRANCH}"
238 ${elogcmd} " storage directory: \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\"" 272 ${elogcmd} " storage directory: \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\""
239 273
240 # export to the ${WORKDIR} 274 # unpack to the ${S}
241 mkdir -p "${S}" 275 unset GIT_DIR
242 276 debug-print "git clone -l -s -n \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\" \"${S}\""
243 # git data are used in some packages for various variables definition. So we 277 git clone -l -s -n "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" "${S}"
244 # copy also .git folder. 278
279 # set correct branch and the tree ebuild specified
245 pushd "${S}" > /dev/null 280 pushd "${S}" > /dev/null
246 git clone --bare ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR} .git 281 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
282 if [[ ${EGIT_TREE} != ${EGIT_BRANCH} ]]; then
283 branchname=tree-${EGIT_TREE}
284 src=${EGIT_TREE}
285 fi
286 debug-print "git checkout -b ${branchname} ${src}"
287 git checkout -b ${branchname} ${src} 2>&1 > /dev/null
288 debug-print "git submodule init"
289 git submodule init 2>&1 > /dev/null
290 debug-print "git submodule update"
291 git submodule update 2>&1 > /dev/null
247 popd > /dev/null 292 popd > /dev/null
248 293
249 git archive --format=tar ${EGIT_TREE} | ( cd "${S}" ; tar xf - ) 294 unset branchname src
250 295
251 echo ">>> Unpacked to ${S}" 296 echo ">>> Unpacked to ${S}"
252} 297}
253 298
254# @FUNCTION: git_bootstrap 299# @FUNCTION: git_bootstrap
326# @FUNCTION: git_src_prepare 371# @FUNCTION: git_src_prepare
327# @DESCRIPTION: 372# @DESCRIPTION:
328# src_prepare function for git stuff. Patches, bootstrap... 373# src_prepare function for git stuff. Patches, bootstrap...
329git_src_prepare() { 374git_src_prepare() {
330 debug-print-function ${FUNCNAME} "$@" 375 debug-print-function ${FUNCNAME} "$@"
331 376
332 git_apply_patches 377 git_apply_patches
333 git_bootstrap 378 git_bootstrap
334} 379}

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.20