| 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/git.eclass,v 1.41 2010/01/31 10:13:57 scarabeus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.42 2010/02/23 00:43:54 abcd 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> |
| … | |
… | |
| 15 | # Fernando J. Pereda <ferdy@gentoo.org> |
15 | # Fernando J. Pereda <ferdy@gentoo.org> |
| 16 | |
16 | |
| 17 | inherit eutils |
17 | inherit eutils |
| 18 | |
18 | |
| 19 | EGIT="git.eclass" |
19 | EGIT="git.eclass" |
|
|
20 | |
|
|
21 | # We DEPEND on at least a bit recent git version |
|
|
22 | DEPEND=">=dev-util/git-1.6" |
| 20 | |
23 | |
| 21 | EXPORTED_FUNCTIONS="src_unpack" |
24 | EXPORTED_FUNCTIONS="src_unpack" |
| 22 | case "${EAPI:-0}" in |
25 | case "${EAPI:-0}" in |
| 23 | 3|2) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;; |
26 | 3|2) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;; |
| 24 | 1|0) ;; |
27 | 1|0) ;; |
| … | |
… | |
| 27 | EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS} |
30 | EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS} |
| 28 | |
31 | |
| 29 | # define some nice defaults but only if nothing is set already |
32 | # define some nice defaults but only if nothing is set already |
| 30 | : ${HOMEPAGE:=http://git-scm.com/} |
33 | : ${HOMEPAGE:=http://git-scm.com/} |
| 31 | |
34 | |
| 32 | # We DEPEND on at least a bit recent git version |
|
|
| 33 | DEPEND=">=dev-util/git-1.6" |
|
|
| 34 | |
|
|
| 35 | # @ECLASS-VARIABLE: EGIT_QUIET |
35 | # @ECLASS-VARIABLE: EGIT_QUIET |
| 36 | # @DESCRIPTION: |
36 | # @DESCRIPTION: |
| 37 | # Enables user specified verbosity for the eclass elog informations. |
37 | # Enables user specified verbosity for the eclass elog informations. |
| 38 | # The user just needs to add EGIT_QUIET="ON" to the /etc/make.conf. |
38 | # The user just needs to add EGIT_QUIET="ON" to the /etc/make.conf. |
| 39 | : ${EGIT_QUIET:="OFF"} |
39 | : ${EGIT_QUIET:="OFF"} |
| … | |
… | |
| 42 | # @DESCRIPTION: |
42 | # @DESCRIPTION: |
| 43 | # Storage directory for git sources. |
43 | # Storage directory for git sources. |
| 44 | # Can be redefined. |
44 | # Can be redefined. |
| 45 | [[ -z ${EGIT_STORE_DIR} ]] && EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
45 | [[ -z ${EGIT_STORE_DIR} ]] && EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
| 46 | |
46 | |
|
|
47 | # @ECLASS-VARIABLE: EGIT_HAS_SUBMODULES |
|
|
48 | # @DESCRIPTION: |
|
|
49 | # Set this to "true" to enable the (slower) submodule support. |
|
|
50 | # This variable should be set before inheriting git.eclass |
|
|
51 | : ${EGIT_HAS_SUBMODULES:=false} |
|
|
52 | |
| 47 | # @ECLASS-VARIABLE: EGIT_FETCH_CMD |
53 | # @ECLASS-VARIABLE: EGIT_FETCH_CMD |
| 48 | # @DESCRIPTION: |
54 | # @DESCRIPTION: |
| 49 | # Command for cloning the repository. |
55 | # Command for cloning the repository. |
| 50 | : ${EGIT_FETCH_CMD:="git clone"} |
56 | : ${EGIT_FETCH_CMD:="git clone"} |
| 51 | |
57 | |
| 52 | # @ECLASS-VARIABLE: EGIT_UPDATE_CMD |
58 | # @ECLASS-VARIABLE: EGIT_UPDATE_CMD |
| 53 | # @DESCRIPTION: |
59 | # @DESCRIPTION: |
| 54 | # Git fetch command. |
60 | # Git fetch command. |
|
|
61 | if ${EGIT_HAS_SUBMODULES}; then |
| 55 | EGIT_UPDATE_CMD="git pull -f -u" |
62 | EGIT_UPDATE_CMD="git pull -f -u" |
|
|
63 | else |
|
|
64 | EGIT_UPDATE_CMD="git fetch -f -u" |
|
|
65 | fi |
| 56 | |
66 | |
| 57 | # @ECLASS-VARIABLE: EGIT_DIFFSTAT_CMD |
67 | # @ECLASS-VARIABLE: EGIT_DIFFSTAT_CMD |
| 58 | # @DESCRIPTION: |
68 | # @DESCRIPTION: |
| 59 | # Git command for diffstat. |
69 | # Git command for diffstat. |
| 60 | EGIT_DIFFSTAT_CMD="git --no-pager diff --stat" |
70 | EGIT_DIFFSTAT_CMD="git --no-pager diff --stat" |
| … | |
… | |
| 150 | |
160 | |
| 151 | # @FUNCTION: git_submodules |
161 | # @FUNCTION: git_submodules |
| 152 | # @DESCRIPTION: |
162 | # @DESCRIPTION: |
| 153 | # Internal function wrapping the submodule initialisation and update |
163 | # Internal function wrapping the submodule initialisation and update |
| 154 | git_submodules() { |
164 | git_submodules() { |
|
|
165 | if ${EGIT_HAS_SUBMODULES}; then |
| 155 | debug-print "git submodule init" |
166 | debug-print "git submodule init" |
| 156 | git submodule init |
167 | git submodule init |
| 157 | debug-print "git submodule update" |
168 | debug-print "git submodule update" |
| 158 | git submodule update |
169 | git submodule update |
|
|
170 | fi |
| 159 | } |
171 | } |
| 160 | |
172 | |
| 161 | # @FUNCTION: git_branch |
173 | # @FUNCTION: git_branch |
| 162 | # @DESCRIPTION: |
174 | # @DESCRIPTION: |
| 163 | # Internal function that changes branch for the repo based on EGIT_TREE and |
175 | # Internal function that changes branch for the repo based on EGIT_TREE and |
| … | |
… | |
| 178 | # @DESCRIPTION: |
190 | # @DESCRIPTION: |
| 179 | # Gets repository from EGIT_REPO_URI and store it in specified EGIT_STORE_DIR |
191 | # Gets repository from EGIT_REPO_URI and store it in specified EGIT_STORE_DIR |
| 180 | git_fetch() { |
192 | git_fetch() { |
| 181 | debug-print-function ${FUNCNAME} "$@" |
193 | debug-print-function ${FUNCNAME} "$@" |
| 182 | |
194 | |
| 183 | local GIT_DIR EGIT_CLONE_DIR oldsha1 cursha1 |
195 | local GIT_DIR EGIT_CLONE_DIR oldsha1 cursha1 extra_clone_opts upstream_branch |
|
|
196 | ${EGIT_USE_SUBMODULES} || export GIT_DIR |
| 184 | |
197 | |
| 185 | # choose if user wants elog or just einfo. |
198 | # choose if user wants elog or just einfo. |
| 186 | if [[ ${EGIT_QUIET} != OFF ]]; then |
199 | if [[ ${EGIT_QUIET} != OFF ]]; then |
| 187 | elogcmd="einfo" |
200 | elogcmd="einfo" |
| 188 | else |
201 | else |
| … | |
… | |
| 239 | if [[ -e "${GIT_DIR}/shallow" ]]; then |
252 | if [[ -e "${GIT_DIR}/shallow" ]]; then |
| 240 | rm -rf "${GIT_DIR}" |
253 | rm -rf "${GIT_DIR}" |
| 241 | einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching." |
254 | einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching." |
| 242 | fi |
255 | fi |
| 243 | # repack from bare copy to normal one |
256 | # repack from bare copy to normal one |
| 244 | if [[ -d ${GIT_DIR} && ! -d "${GIT_DIR}/.git/" ]]; then |
257 | if ${EGIT_HAS_SUBMODULES} && [[ -d ${GIT_DIR} && ! -d "${GIT_DIR}/.git/" ]]; then |
| 245 | rm -rf "${GIT_DIR}" |
258 | rm -rf "${GIT_DIR}" |
| 246 | einfo "The ${EGIT_CLONE_DIR} was bare copy. Refetching." |
259 | einfo "The ${EGIT_CLONE_DIR} was bare copy. Refetching." |
|
|
260 | fi |
|
|
261 | if ! ${EGIT_HAS_SUBMODULES} && [[ -d ${GIT_DIR} && -d ${GIT_DIR}/.git ]]; then |
|
|
262 | rm -rf "${GIT_DIR}" |
|
|
263 | einfo "The ${EGIT_CLONE_DIR} was not a bare copy. Refetching." |
|
|
264 | fi |
|
|
265 | |
|
|
266 | if ${EGIT_HAS_SUBMODULES}; then |
|
|
267 | upstream_branch=origin/${EGIT_BRANCH} |
|
|
268 | else |
|
|
269 | upstream_branch=${EGIT_BRANCH} |
|
|
270 | extra_clone_opts=--bare |
| 247 | fi |
271 | fi |
| 248 | |
272 | |
| 249 | if [[ ! -d ${GIT_DIR} ]] ; then |
273 | if [[ ! -d ${GIT_DIR} ]] ; then |
| 250 | # first clone |
274 | # first clone |
| 251 | ${elogcmd} "GIT NEW clone -->" |
275 | ${elogcmd} "GIT NEW clone -->" |
| 252 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
276 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 253 | |
277 | |
| 254 | debug-print "${EGIT_FETCH_CMD} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" ${GIT_DIR}" |
278 | debug-print "${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" ${GIT_DIR}" |
| 255 | ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${GIT_DIR} \ |
279 | ${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${GIT_DIR} \ |
| 256 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
280 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
| 257 | |
281 | |
| 258 | pushd "${GIT_DIR}" &> /dev/null |
282 | pushd "${GIT_DIR}" &> /dev/null |
| 259 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
283 | cursha1=$(git rev-parse ${upstream_branch}) |
| 260 | ${elogcmd} " at the commit: ${cursha1}" |
284 | ${elogcmd} " at the commit: ${cursha1}" |
| 261 | |
285 | |
| 262 | git_submodules |
286 | git_submodules |
| 263 | popd &> /dev/null |
287 | popd &> /dev/null |
| 264 | elif [[ -n ${EGIT_OFFLINE} ]] ; then |
288 | elif [[ -n ${EGIT_OFFLINE} ]] ; then |
| 265 | pushd "${GIT_DIR}" &> /dev/null |
289 | pushd "${GIT_DIR}" &> /dev/null |
| 266 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
290 | cursha1=$(git rev-parse ${upstream_branch}) |
| 267 | ${elogcmd} "GIT offline update -->" |
291 | ${elogcmd} "GIT offline update -->" |
| 268 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
292 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 269 | ${elogcmd} " at the commit: ${cursha1}" |
293 | ${elogcmd} " at the commit: ${cursha1}" |
| 270 | popd &> /dev/null |
294 | popd &> /dev/null |
| 271 | else |
295 | else |
| … | |
… | |
| 274 | git config remote.origin.url "${EGIT_REPO_URI}" |
298 | git config remote.origin.url "${EGIT_REPO_URI}" |
| 275 | |
299 | |
| 276 | # fetch updates |
300 | # fetch updates |
| 277 | ${elogcmd} "GIT update -->" |
301 | ${elogcmd} "GIT update -->" |
| 278 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
302 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 279 | |
|
|
| 280 | oldsha1=$(git rev-parse origin/${EGIT_BRANCH}) |
|
|
| 281 | |
303 | |
|
|
304 | oldsha1=$(git rev-parse ${upstream_branch}) |
|
|
305 | |
|
|
306 | if ${EGIT_HAS_SUBMODULES}; then |
| 282 | debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}" |
307 | debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}" |
| 283 | # fix branching |
308 | # fix branching |
| 284 | git checkout ${EGIT_MASTER} |
309 | git checkout ${EGIT_MASTER} |
| 285 | for x in $(git branch |grep -v "* ${EGIT_MASTER}" |tr '\n' ' '); do |
310 | for x in $(git branch |grep -v "* ${EGIT_MASTER}" |tr '\n' ' '); do |
| 286 | git branch -D ${x} |
311 | git branch -D ${x} |
| 287 | done |
312 | done |
| 288 | ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} \ |
313 | ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} \ |
| 289 | || die "${EGIT}: can't update from ${EGIT_REPO_URI}." |
314 | || die "${EGIT}: can't update from ${EGIT_REPO_URI}." |
|
|
315 | else |
|
|
316 | debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH}" |
|
|
317 | ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \ |
|
|
318 | || die "${EGIT}: can't update from ${EGIT_REPO_URI}." |
|
|
319 | fi |
| 290 | |
320 | |
| 291 | git_submodules |
321 | git_submodules |
| 292 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
322 | cursha1=$(git rev-parse ${upstream_branch}) |
| 293 | |
323 | |
| 294 | # write out message based on the revisions |
324 | # write out message based on the revisions |
| 295 | if [[ ${oldsha1} != ${cursha1} ]]; then |
325 | if [[ ${oldsha1} != ${cursha1} ]]; then |
| 296 | ${elogcmd} " updating from commit: ${oldsha1}" |
326 | ${elogcmd} " updating from commit: ${oldsha1}" |
| 297 | ${elogcmd} " to commit: ${cursha1}" |
327 | ${elogcmd} " to commit: ${cursha1}" |
| … | |
… | |
| 306 | # TODO: this can lead to issues if more projects/packages use same repo |
336 | # TODO: this can lead to issues if more projects/packages use same repo |
| 307 | [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \ |
337 | [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \ |
| 308 | debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \ |
338 | debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \ |
| 309 | die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." |
339 | die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." |
| 310 | fi |
340 | fi |
| 311 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..origin/${EGIT_BRANCH} |
341 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${upstream_branch} |
| 312 | popd &> /dev/null |
342 | popd &> /dev/null |
| 313 | fi |
343 | fi |
| 314 | |
344 | |
| 315 | pushd "${GIT_DIR}" &> /dev/null |
345 | pushd "${GIT_DIR}" &> /dev/null |
| 316 | if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then |
346 | if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then |
| 317 | ebegin "Garbage collecting the repository" |
347 | ebegin "Garbage collecting the repository" |
| 318 | git gc $(${EGIT_PRUNE} && echo '--prune') |
348 | git gc $(${EGIT_PRUNE} && echo '--prune') |
| 319 | eend $? |
349 | eend $? |
| … | |
… | |
| 326 | # log the repo state |
356 | # log the repo state |
| 327 | [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] && elog " commit: ${EGIT_COMMIT}" |
357 | [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] && elog " commit: ${EGIT_COMMIT}" |
| 328 | ${elogcmd} " branch: ${EGIT_BRANCH}" |
358 | ${elogcmd} " branch: ${EGIT_BRANCH}" |
| 329 | ${elogcmd} " storage directory: \"${GIT_DIR}\"" |
359 | ${elogcmd} " storage directory: \"${GIT_DIR}\"" |
| 330 | |
360 | |
|
|
361 | if ${EGIT_HAS_SUBMODULES}; then |
| 331 | pushd "${GIT_DIR}" &> /dev/null |
362 | pushd "${GIT_DIR}" &> /dev/null |
| 332 | debug-print "rsync -rlpgo . \"${S}\"" |
363 | debug-print "rsync -rlpgo . \"${S}\"" |
| 333 | time rsync -rlpgo . "${S}" |
364 | time rsync -rlpgo . "${S}" |
| 334 | popd &> /dev/null |
365 | popd &> /dev/null |
|
|
366 | else |
|
|
367 | unset GIT_DIR |
|
|
368 | debug-print "git clone -l -s -n \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\" \"${S}\"" |
|
|
369 | git clone -l -s -n "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" "${S}" |
|
|
370 | fi |
| 335 | |
371 | |
| 336 | pushd "${S}" &> /dev/null |
372 | pushd "${S}" &> /dev/null |
| 337 | git_branch |
373 | git_branch |
| 338 | # submodules always reqire net (thanks to branches changing) |
374 | # submodules always reqire net (thanks to branches changing) |
| 339 | [[ -n ${EGIT_OFFLINE} ]] || git_submodules |
375 | [[ -n ${EGIT_OFFLINE} ]] || git_submodules |