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

Contents of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.63 - (show annotations) (download)
Sat Oct 5 18:39:30 2013 UTC (13 months, 3 weeks ago) by mgorny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.62: +1 -1 lines
FILE REMOVED
Remove lastrited git.eclass.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.62 2013/08/02 15:41:17 mgorny Exp $
4
5 # @DEAD
6 # Michał Górny <mgorny@gentoo.org> (2 Aug 2013)
7 # This eclass has been superseded by git-2 eclass and will be removed
8 # on 2013-09-02. Please modify your ebuilds to use git-2 instead.
9 # Bug #479474.
10
11 # @ECLASS: git.eclass
12 # @MAINTAINER:
13 # Donnie Berkholz <dberkholz@gentoo.org>
14 # @BLURB: Fetching and unpacking of git repositories
15 # @DESCRIPTION:
16 # The git eclass provides functions to fetch, patch and bootstrap
17 # software sources from git repositories and is based on the subversion eclass.
18 # It is necessary to define at least the EGIT_REPO_URI variable.
19 #
20 # THANKS TO:
21 # Fernando J. Pereda <ferdy@gentoo.org>
22
23 inherit eutils
24
25 EGIT="git.eclass"
26
27 # We DEPEND on a not too ancient git version
28 DEPEND=">=dev-vcs/git-1.6"
29
30 EXPORTED_FUNCTIONS="src_unpack"
31 case "${EAPI:-0}" in
32 2|3|4|5) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;;
33 1|0) ;;
34 *) die "EAPI=${EAPI} is not supported" ;;
35 esac
36 EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
37
38 # define some nice defaults but only if nothing is set already
39 : ${HOMEPAGE:=http://git-scm.com/}
40
41 # @ECLASS-VARIABLE: EGIT_QUIET
42 # @DESCRIPTION:
43 # Set to non-empty value to supress some eclass messages.
44 : ${EGIT_QUIET:=${ESCM_QUIET}}
45
46 # @ECLASS-VARIABLE: EGIT_STORE_DIR
47 # @DESCRIPTION:
48 # Storage directory for git sources.
49 # Can be redefined.
50 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src"}
51
52 # @ECLASS-VARIABLE: EGIT_UNPACK_DIR
53 # @DESCRIPTION:
54 # Directory to unpack git sources in.
55
56 # @ECLASS-VARIABLE: EGIT_HAS_SUBMODULES
57 # @DESCRIPTION:
58 # Set this to non-empty value to enable submodule support (slower).
59 : ${EGIT_HAS_SUBMODULES:=}
60
61 # @ECLASS-VARIABLE: EGIT_FETCH_CMD
62 # @DESCRIPTION:
63 # Command for cloning the repository.
64 : ${EGIT_FETCH_CMD:="git clone"}
65
66 # @ECLASS-VARIABLE: EGIT_UPDATE_CMD
67 # @DESCRIPTION:
68 # Git fetch command.
69 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then
70 EGIT_UPDATE_CMD="git pull -f -u"
71 else
72 EGIT_UPDATE_CMD="git fetch -f -u"
73 fi
74
75 # @ECLASS-VARIABLE: EGIT_DIFFSTAT_CMD
76 # @DESCRIPTION:
77 # Git command for diffstat.
78 EGIT_DIFFSTAT_CMD="git --no-pager diff --stat"
79
80 # @ECLASS-VARIABLE: EGIT_OPTIONS
81 # @DESCRIPTION:
82 # This variable value is passed to clone and fetch.
83 : ${EGIT_OPTIONS:=}
84
85 # @ECLASS-VARIABLE: EGIT_MASTER
86 # @DESCRIPTION:
87 # Variable for specifying master branch.
88 # Usefull when upstream don't have master branch.
89 : ${EGIT_MASTER:=master}
90
91 # @ECLASS-VARIABLE: EGIT_REPO_URI
92 # @DESCRIPTION:
93 # URI for the repository
94 # e.g. http://foo, git://bar
95 # Supported protocols:
96 # http://
97 # https://
98 # git://
99 # git+ssh://
100 # rsync://
101 # ssh://
102 eval X="\$${PN//[-+]/_}_LIVE_REPO"
103 if [[ ${X} = "" ]]; then
104 : ${EGIT_REPO_URI:=}
105 else
106 EGIT_REPO_URI="${X}"
107 fi
108 # @ECLASS-VARIABLE: EGIT_PROJECT
109 # @DESCRIPTION:
110 # Project name, it must be unique across EGIT_STORE_DIR.
111 # Git eclass will check out the git repository into ${EGIT_STORE_DIR}/${EGIT_PROJECT}/${EGIT_REPO_URI##*/}
112 # Default is ${PN}.
113 : ${EGIT_PROJECT:=${PN}}
114
115 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
116 # @DESCRIPTION:
117 # bootstrap script or command like autogen.sh or etc...
118 : ${EGIT_BOOTSTRAP:=}
119
120 # @ECLASS-VARIABLE: EGIT_OFFLINE
121 # @DESCRIPTION:
122 # Set this variable to a non-empty value to disable the automatic updating of
123 # an GIT source tree. This is intended to be set outside the git source
124 # tree by users.
125 : ${EGIT_OFFLINE:=${ESCM_OFFLINE}}
126
127 # @ECLASS-VARIABLE: EGIT_PATCHES
128 # @DESCRIPTION:
129 # Similar to PATCHES array from base.eclass
130 # Only difference is that this patches are applied before bootstrap.
131 # Please take note that this variable should be bash array.
132
133 # @ECLASS-VARIABLE: EGIT_BRANCH
134 # @DESCRIPTION:
135 # git eclass can fetch any branch in git_fetch().
136 eval X="\$${PN//[-+]/_}_LIVE_BRANCH"
137 if [[ "${X}" = "" ]]; then
138 : ${EGIT_BRANCH:=master}
139 else
140 EGIT_BRANCH="${X}"
141 fi
142
143 # @ECLASS-VARIABLE: EGIT_COMMIT
144 # @DESCRIPTION:
145 # git eclass can checkout any commit.
146 eval X="\$${PN//[-+]/_}_LIVE_COMMIT"
147 if [[ "${X}" = "" ]]; then
148 : ${EGIT_COMMIT:=${EGIT_BRANCH}}
149 else
150 EGIT_COMMIT="${X}"
151 fi
152
153 # @ECLASS-VARIABLE: EGIT_REPACK
154 # @DESCRIPTION:
155 # Set to non-empty value to repack objects to save disk space. However this can
156 # take a long time with VERY big repositories.
157 : ${EGIT_REPACK:=}
158
159 # @ECLASS-VARIABLE: EGIT_PRUNE
160 # @DESCRIPTION:
161 # Set to non-empty value to prune loose objects on each fetch. This is useful
162 # if upstream rewinds and rebases branches often.
163 : ${EGIT_PRUNE:=}
164
165 # @FUNCTION: git_submodules
166 # @DESCRIPTION:
167 # Internal function wrapping the submodule initialisation and update
168 git_submodules() {
169 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then
170 debug-print "git submodule init"
171 git submodule init
172 debug-print "git submodule sync"
173 git submodule sync
174 debug-print "git submodule update"
175 git submodule update
176 fi
177 }
178
179 # @FUNCTION: git_branch
180 # @DESCRIPTION:
181 # Internal function that changes branch for the repo based on EGIT_TREE and
182 # EGIT_BRANCH variables.
183 git_branch() {
184 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
185 if [[ "${EGIT_COMMIT}" != "${EGIT_BRANCH}" ]]; then
186 branchname=tree-${EGIT_COMMIT}
187 src=${EGIT_COMMIT}
188 fi
189 debug-print "git checkout -b ${branchname} ${src}"
190 git checkout -b ${branchname} ${src} &> /dev/null
191
192 unset branchname src
193 }
194
195 # @FUNCTION: git_fetch
196 # @DESCRIPTION:
197 # Gets repository from EGIT_REPO_URI and store it in specified EGIT_STORE_DIR
198 git_fetch() {
199 debug-print-function ${FUNCNAME} "$@"
200
201 eqawarn "git.eclass is deprecated."
202 eqawarn "Please update your ebuilds to use git-2 instead. For details, see"
203 eqawarn "http://archives.gentoo.org/gentoo-dev/msg_b7ba363cae580845819ae3501fb157e9.xml"
204
205 local GIT_DIR EGIT_CLONE_DIR oldsha1 cursha1 extra_clone_opts upstream_branch
206 [[ -z ${EGIT_HAS_SUBMODULES} ]] && export GIT_DIR
207
208 # choose if user wants elog or just einfo.
209 if [[ -n ${EGIT_QUIET} ]]; then
210 elogcmd="einfo"
211 else
212 elogcmd="elog"
213 fi
214
215 # If we have same branch and the tree we can do --depth 1 clone
216 # which outputs into really smaller data transfers.
217 # Sadly we can do shallow copy for now because quite a few packages need .git
218 # folder.
219 #[[ ${EGIT_COMMIT} = ${EGIT_BRANCH} ]] && \
220 # EGIT_FETCH_CMD="${EGIT_FETCH_CMD} --depth 1"
221 if [[ -n ${EGIT_TREE} ]] ; then
222 EGIT_COMMIT=${EGIT_TREE}
223 ewarn "QA: Usage of deprecated EGIT_TREE variable detected."
224 ewarn "QA: Use EGIT_COMMIT variable instead."
225 fi
226
227 # EGIT_REPO_URI is empty.
228 [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty."
229
230 # check for the protocol or pull from a local repo.
231 if [[ -z ${EGIT_REPO_URI%%:*} ]] ; then
232 case ${EGIT_REPO_URI%%:*} in
233 git*|http|https|rsync|ssh) ;;
234 *) die "${EGIT}: protocol for fetch from "${EGIT_REPO_URI%:*}" is not yet implemented in eclass." ;;
235 esac
236 fi
237
238 # initial clone, we have to create master git storage directory and play
239 # nicely with sandbox
240 if [[ ! -d ${EGIT_STORE_DIR} ]] ; then
241 debug-print "${FUNCNAME}: initial clone. creating git directory"
242 addwrite /
243 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
244 || die "${EGIT}: can't mkdir ${EGIT_STORE_DIR}."
245 export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
246 fi
247
248 cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}"
249 EGIT_STORE_DIR=${PWD}
250
251 # allow writing into EGIT_STORE_DIR
252 addwrite "${EGIT_STORE_DIR}"
253
254 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}"
255 EGIT_CLONE_DIR="${EGIT_PROJECT}"
256
257 debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\""
258
259 GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
260 # we also have to remove all shallow copied repositories
261 # and fetch them again
262 if [[ -e "${GIT_DIR}/shallow" ]]; then
263 rm -rf "${GIT_DIR}"
264 einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching."
265 fi
266 # repack from bare copy to normal one
267 if [[ -n ${EGIT_HAS_SUBMODULES} ]] && [[ -d ${GIT_DIR} && ! -d ${GIT_DIR}/.git ]]; then
268 rm -rf "${GIT_DIR}"
269 einfo "The ${EGIT_CLONE_DIR} was bare copy. Refetching."
270 fi
271 if [[ -z ${EGIT_HAS_SUBMODULES} ]] && [[ -d ${GIT_DIR} && -d ${GIT_DIR}/.git ]]; then
272 rm -rf "${GIT_DIR}"
273 einfo "The ${EGIT_CLONE_DIR} was not a bare copy. Refetching."
274 fi
275
276 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then
277 upstream_branch=origin/${EGIT_BRANCH}
278 else
279 upstream_branch=${EGIT_BRANCH}
280 extra_clone_opts=--bare
281 fi
282
283 if [[ ! -d ${GIT_DIR} ]] ; then
284 # first clone
285 ${elogcmd} "GIT NEW clone -->"
286 ${elogcmd} " repository: ${EGIT_REPO_URI}"
287
288 debug-print "${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" ${GIT_DIR}"
289 ${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${GIT_DIR} \
290 || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."
291
292 pushd "${GIT_DIR}" &> /dev/null
293 cursha1=$(git rev-parse ${upstream_branch})
294 ${elogcmd} " at the commit: ${cursha1}"
295
296 git_submodules
297 popd &> /dev/null
298 elif [[ -n ${EGIT_OFFLINE} ]] ; then
299 pushd "${GIT_DIR}" &> /dev/null
300 cursha1=$(git rev-parse ${upstream_branch})
301 ${elogcmd} "GIT offline update -->"
302 ${elogcmd} " repository: ${EGIT_REPO_URI}"
303 ${elogcmd} " at the commit: ${cursha1}"
304 popd &> /dev/null
305 else
306 pushd "${GIT_DIR}" &> /dev/null
307 # Git urls might change, so unconditionally set it here
308 git config remote.origin.url "${EGIT_REPO_URI}"
309
310 # fetch updates
311 ${elogcmd} "GIT update -->"
312 ${elogcmd} " repository: ${EGIT_REPO_URI}"
313
314 oldsha1=$(git rev-parse ${upstream_branch})
315
316 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then
317 debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}"
318 # fix branching
319 git checkout ${EGIT_MASTER}
320 for x in $(git branch |grep -v "* ${EGIT_MASTER}" |tr '\n' ' '); do
321 git branch -D ${x}
322 done
323 ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} \
324 || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
325 else
326 debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
327 ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \
328 || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
329 fi
330
331 git_submodules
332 cursha1=$(git rev-parse ${upstream_branch})
333
334 # write out message based on the revisions
335 if [[ "${oldsha1}" != "${cursha1}" ]]; then
336 ${elogcmd} " updating from commit: ${oldsha1}"
337 ${elogcmd} " to commit: ${cursha1}"
338 else
339 ${elogcmd} " at the commit: ${cursha1}"
340 # @ECLASS-VARIABLE: LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED
341 # @DESCRIPTION:
342 # If this variable is set to TRUE in make.conf or somewhere in
343 # enviroment the package will fail if there is no update, thus in
344 # combination with --keep-going it would lead in not-updating
345 # pakcages that are up-to-date.
346 # TODO: this can lead to issues if more projects/packages use same repo
347 [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \
348 debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \
349 die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping."
350 fi
351 ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${upstream_branch}
352 popd &> /dev/null
353 fi
354
355 pushd "${GIT_DIR}" &> /dev/null
356 if [[ -n ${EGIT_REPACK} ]] || [[ -n ${EGIT_PRUNE} ]]; then
357 ebegin "Garbage collecting the repository"
358 local args
359 [[ -n ${EGIT_PRUNE} ]] && args='--prune'
360 git gc ${args}
361 eend $?
362 fi
363 popd &> /dev/null
364
365 # export the git version
366 export EGIT_VERSION="${cursha1}"
367
368 # log the repo state
369 [[ "${EGIT_COMMIT}" != "${EGIT_BRANCH}" ]] && ${elogcmd} " commit: ${EGIT_COMMIT}"
370 ${elogcmd} " branch: ${EGIT_BRANCH}"
371 ${elogcmd} " storage directory: \"${GIT_DIR}\""
372
373 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then
374 pushd "${GIT_DIR}" &> /dev/null
375 debug-print "rsync -rlpgo . \"${EGIT_UNPACK_DIR:-${S}}\""
376 time rsync -rlpgo . "${EGIT_UNPACK_DIR:-${S}}"
377 popd &> /dev/null
378 else
379 unset GIT_DIR
380 debug-print "git clone -l -s -n \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\" \"${EGIT_UNPACK_DIR:-${S}}\""
381 git clone -l -s -n "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" "${EGIT_UNPACK_DIR:-${S}}"
382 fi
383
384 pushd "${EGIT_UNPACK_DIR:-${S}}" &> /dev/null
385 git_branch
386 # submodules always reqire net (thanks to branches changing)
387 [[ -z ${EGIT_OFFLINE} ]] && git_submodules
388 popd &> /dev/null
389
390 echo ">>> Unpacked to ${EGIT_UNPACK_DIR:-${S}}"
391 }
392
393 # @FUNCTION: git_bootstrap
394 # @DESCRIPTION:
395 # Runs bootstrap command if EGIT_BOOTSTRAP variable contains some value
396 # Remember that what ever gets to the EGIT_BOOTSTRAP variable gets evaled by bash.
397 git_bootstrap() {
398 debug-print-function ${FUNCNAME} "$@"
399
400 if [[ -n ${EGIT_BOOTSTRAP} ]] ; then
401 pushd "${S}" > /dev/null
402 einfo "Starting bootstrap"
403
404 if [[ -f ${EGIT_BOOTSTRAP} ]]; then
405 # we have file in the repo which we should execute
406 debug-print "$FUNCNAME: bootstraping with file \"${EGIT_BOOTSTRAP}\""
407
408 if [[ -x ${EGIT_BOOTSTRAP} ]]; then
409 eval "./${EGIT_BOOTSTRAP}" \
410 || die "${EGIT}: bootstrap script failed"
411 else
412 eerror "\"${EGIT_BOOTSTRAP}\" is not executable."
413 eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command."
414 die "${EGIT}: \"${EGIT_BOOTSTRAP}\" is not executable."
415 fi
416 else
417 # we execute some system command
418 debug-print "$FUNCNAME: bootstraping with commands \"${EGIT_BOOTSTRAP}\""
419
420 eval "${EGIT_BOOTSTRAP}" \
421 || die "${EGIT}: bootstrap commands failed."
422
423 fi
424
425 einfo "Bootstrap finished"
426 popd > /dev/null
427 fi
428 }
429
430 # @FUNCTION: git_apply_patches
431 # @DESCRIPTION:
432 # Apply patches from EGIT_PATCHES bash array.
433 # Preferred is using the variable as bash array but for now it allows to write
434 # it also as normal space separated string list. (This part of code should be
435 # removed when all ebuilds get converted on bash array).
436 git_apply_patches() {
437 debug-print-function ${FUNCNAME} "$@"
438
439 pushd "${EGIT_UNPACK_DIR:-${S}}" > /dev/null
440 if [[ ${#EGIT_PATCHES[@]} -gt 1 ]] ; then
441 for i in "${EGIT_PATCHES[@]}"; do
442 debug-print "$FUNCNAME: git_autopatch: patching from ${i}"
443 epatch "${i}"
444 done
445 elif [[ -n ${EGIT_PATCHES} ]]; then
446 # no need for loop if space separated string is passed.
447 debug-print "$FUNCNAME: git_autopatch: patching from ${EGIT_PATCHES}"
448 epatch "${EGIT_PATCHES}"
449 fi
450
451 popd > /dev/null
452 }
453
454 # @FUNCTION: git_src_unpack
455 # @DESCRIPTION:
456 # src_upack function, calls src_prepare one if EAPI!=2.
457 git_src_unpack() {
458 debug-print-function ${FUNCNAME} "$@"
459
460 git_fetch || die "${EGIT}: unknown problem in git_fetch()."
461
462 has src_prepare ${EXPORTED_FUNCTIONS} || git_src_prepare
463 }
464
465 # @FUNCTION: git_src_prepare
466 # @DESCRIPTION:
467 # src_prepare function for git stuff. Patches, bootstrap...
468 git_src_prepare() {
469 debug-print-function ${FUNCNAME} "$@"
470
471 git_apply_patches
472 git_bootstrap
473 }

  ViewVC Help
Powered by ViewVC 1.1.20