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

Contents of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Thu Feb 19 17:07:28 2009 UTC (5 years, 6 months ago) by scarabeus
Branch: MAIN
Changes since 1.14: +3 -2 lines
Update git.eclass. Now consumes less bandwitch. Per bug #255451. Thanks to reavertm for the patch. Also add myself as maintainer.

1 ferdy 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 scarabeus 1.15 # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.14 2008/06/16 11:22:38 zlin Exp $
4 ferdy 1.1
5     ## --------------------------------------------------------------------------- #
6     # subversion.eclass author: Akinori Hattori <hattya@gentoo.org>
7     # modified for git by Donnie Berkholz <spyderous@gentoo.org>
8     # improved by Fernando J. Pereda <ferdy@gentoo.org>
9 scarabeus 1.15 # you should currently poke with updates Tomas Chvatal <scarabeus@gentoo.org>
10 ferdy 1.1 #
11     # The git eclass is written to fetch the software sources from
12     # git repositories like the subversion eclass.
13     #
14     #
15     # Description:
16     # If you use this eclass, the ${S} is ${WORKDIR}/${P}.
17     # It is necessary to define the EGIT_REPO_URI variable at least.
18     #
19     ## --------------------------------------------------------------------------- #
20    
21     inherit eutils
22    
23     EGIT="git.eclass"
24    
25     EXPORT_FUNCTIONS src_unpack
26    
27     HOMEPAGE="http://git.or.cz/"
28     DESCRIPTION="Based on the ${ECLASS} eclass"
29    
30    
31     ## -- add git in DEPEND
32     #
33 ferdy 1.6 DEPEND=">=dev-util/git-1.5"
34 ferdy 1.1
35    
36     ## -- EGIT_STORE_DIR: git sources store directory
37     #
38     EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src"
39    
40    
41     ## -- EGIT_FETCH_CMD: git clone command
42     #
43 scarabeus 1.15 EGIT_FETCH_CMD="git clone --bare --depth 1"
44 ferdy 1.1
45     ## -- EGIT_UPDATE_CMD: git fetch command
46     #
47     EGIT_UPDATE_CMD="git fetch -f -u"
48    
49     ## -- EGIT_DIFFSTAT_CMD: Command to get diffstat output
50     #
51 ferdy 1.3 EGIT_DIFFSTAT_CMD="git diff --stat"
52 ferdy 1.1
53    
54     ## -- EGIT_OPTIONS:
55     #
56     # the options passed to clone and fetch
57     #
58     : ${EGIT_OPTIONS:=}
59    
60    
61     ## -- EGIT_REPO_URI: repository uri
62     #
63     # e.g. http://foo, git://bar
64     #
65     # supported protocols:
66     # http://
67     # https://
68     # git://
69     # git+ssh://
70     # rsync://
71     # ssh://
72     #
73     : ${EGIT_REPO_URI:=}
74    
75    
76     ## -- EGIT_PROJECT: project name of your ebuild
77     #
78     # git eclass will check out the git repository like:
79     #
80     # ${EGIT_STORE_DIR}/${EGIT_PROJECT}/${EGIT_REPO_URI##*/}
81     #
82     # so if you define EGIT_REPO_URI as http://git.collab.net/repo/git or
83     # http://git.collab.net/repo/git. and PN is subversion-git.
84     # it will check out like:
85     #
86     # ${EGIT_STORE_DIR}/subversion
87     #
88     # default: ${PN/-git}.
89     #
90     : ${EGIT_PROJECT:=${PN/-git}}
91    
92    
93     ## -- EGIT_BOOTSTRAP:
94     #
95     # bootstrap script or command like autogen.sh or etc..
96     #
97     : ${EGIT_BOOTSTRAP:=}
98    
99 robbat2 1.9 # @ECLASS-VARIABLE: EGIT_OFFLINE
100     # @DESCRIPTION:
101     # Set this variable to a non-empty value to disable the automatic updating of
102 robbat2 1.10 # an GIT source tree. This is intended to be set outside the git source
103 robbat2 1.9 # tree by users.
104     EGIT_OFFLINE="${EGIT_OFFLINE:-${ESCM_OFFLINE}}"
105 ferdy 1.1
106     ## -- EGIT_PATCHES:
107     #
108     # git eclass can apply pathces in git_bootstrap().
109     # you can use regexp in this valiable like *.diff or *.patch or etc.
110     # NOTE: this patches will apply before eval EGIT_BOOTSTRAP.
111     #
112     # the process of applying the patch is:
113     # 1. just epatch it, if the patch exists in the path.
114     # 2. scan it under FILESDIR and epatch it, if the patch exists in FILESDIR.
115     # 3. die.
116     #
117     : ${EGIT_PATCHES:=}
118    
119    
120     ## -- EGIT_BRANCH:
121     #
122     # git eclass can fetch any branch in git_fetch().
123 robbat2 1.8 # If set, it must be before 'inherit git', otherwise both EGIT_BRANCH and
124     # EGIT_TREE must be set after 'inherit git'.
125 ferdy 1.1 # Defaults to 'master'
126     #
127     : ${EGIT_BRANCH:=master}
128    
129    
130     ## -- EGIT_TREE:
131     #
132     # git eclass can checkout any tree.
133     # Defaults to EGIT_BRANCH.
134     #
135     : ${EGIT_TREE:=${EGIT_BRANCH}}
136    
137    
138     ## - EGIT_REPACK:
139     #
140     # git eclass will repack objects to save disk space. However this can take a
141     # long time with VERY big repositories. If this is your case set:
142     # EGIT_REPACK=false
143     #
144     : ${EGIT_REPACK:=false}
145    
146     ## - EGIT_PRUNE:
147     #
148     # git eclass can prune the local clone. This is useful if upstream rewinds and
149     # rebases branches too often. If you don't want this to happen, set:
150     # EGIT_PRUNE=false
151     #
152     : ${EGIT_PRUNE:=false}
153    
154    
155     ## -- git_fetch() ------------------------------------------------- #
156    
157     git_fetch() {
158    
159     local EGIT_CLONE_DIR
160    
161     # EGIT_REPO_URI is empty.
162     [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty."
163    
164 ferdy 1.4 # check for the protocol or pull from a local repo.
165     if [[ -z ${EGIT_REPO_URI%%:*} ]] ; then
166     case ${EGIT_REPO_URI%%:*} in
167     git*|http|https|rsync|ssh)
168     ;;
169     *)
170     die "${EGIT}: fetch from "${EGIT_REPO_URI%:*}" is not yet implemented."
171     ;;
172     esac
173     fi
174 ferdy 1.1
175     if [[ ! -d ${EGIT_STORE_DIR} ]] ; then
176     debug-print "${FUNCNAME}: initial clone. creating git directory"
177     addwrite /
178     mkdir -p "${EGIT_STORE_DIR}" \
179     || die "${EGIT}: can't mkdir ${EGIT_STORE_DIR}."
180     export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
181     fi
182    
183     cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}"
184     EGIT_STORE_DIR=${PWD}
185    
186     # every time
187     addwrite "${EGIT_STORE_DIR}"
188    
189     [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}"
190     EGIT_CLONE_DIR="${EGIT_PROJECT}"
191    
192     debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\""
193    
194 zlin 1.12 export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
195 ferdy 1.1
196     if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then
197     # first clone
198     einfo "git clone start -->"
199     einfo " repository: ${EGIT_REPO_URI}"
200    
201     ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \
202     || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."
203    
204     # We use --bare cloning, so git doesn't do this for us.
205 ferdy 1.7 git config remote.origin.url "${EGIT_REPO_URI}"
206 robbat2 1.9 elif [[ -n ${EGIT_OFFLINE} ]] ; then
207     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
208     einfo "git update offline mode -->"
209     einfo " repository: ${EGIT_REPO_URI}"
210     einfo " commit: ${oldsha1}"
211 ferdy 1.1 else
212 ferdy 1.7 # Git urls might change, so unconditionally set it here
213     git config remote.origin.url "${EGIT_REPO_URI}"
214    
215 ferdy 1.1 # fetch updates
216     einfo "git update start -->"
217     einfo " repository: ${EGIT_REPO_URI}"
218    
219     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
220    
221     ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \
222     || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
223    
224 ferdy 1.3 # piping through cat is needed to avoid a stupid Git feature
225     ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} | cat
226 ferdy 1.1 fi
227    
228     einfo " local clone: ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
229    
230 ferdy 1.6 if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then
231     ebegin "Garbage collecting the repository"
232     git gc $(${EGIT_PRUNE} && echo '--prune')
233 ferdy 1.1 eend $?
234     fi
235    
236     einfo " committish: ${EGIT_TREE}"
237    
238     # export to the ${WORKDIR}
239 zlin 1.14 mkdir -p "${S}"
240     git archive --format=tar ${EGIT_TREE} | ( cd "${S}" ; tar xf - )
241 vapier 1.5
242     echo ">>> Unpacked to ${S}"
243 ferdy 1.1
244     }
245    
246    
247     ## -- git_bootstrap() ------------------------------------------------ #
248    
249     git_bootstrap() {
250    
251     local patch lpatch
252    
253     cd "${S}"
254    
255     if [[ -n ${EGIT_PATCHES} ]] ; then
256     einfo "apply patches -->"
257    
258     for patch in ${EGIT_PATCHES} ; do
259     if [[ -f ${patch} ]] ; then
260     epatch ${patch}
261     else
262     for lpatch in "${FILESDIR}"/${patch} ; do
263     if [[ -f ${lpatch} ]] ; then
264     epatch ${lpatch}
265     else
266     die "${EGIT}: ${patch} is not found"
267     fi
268     done
269     fi
270     done
271     echo
272     fi
273    
274     if [[ -n ${EGIT_BOOTSTRAP} ]] ; then
275     einfo "begin bootstrap -->"
276    
277     if [[ -f ${EGIT_BOOTSTRAP} ]] && [[ -x ${EGIT_BOOTSTRAP} ]] ; then
278     einfo " bootstrap with a file: ${EGIT_BOOTSTRAP}"
279     eval "./${EGIT_BOOTSTRAP}" \
280     || die "${EGIT}: can't execute EGIT_BOOTSTRAP."
281     else
282     einfo " bootstrap with commands: ${EGIT_BOOTSTRAP}"
283     eval "${EGIT_BOOTSTRAP}" \
284     || die "${EGIT}: can't eval EGIT_BOOTSTRAP."
285     fi
286     fi
287    
288     }
289    
290    
291     ## -- git_src_unpack() ------------------------------------------------ #
292    
293     git_src_unpack() {
294    
295     git_fetch || die "${EGIT}: unknown problem in git_fetch()."
296     git_bootstrap || die "${EGIT}: unknown problem in git_bootstrap()."
297    
298     }

  ViewVC Help
Powered by ViewVC 1.1.20