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

Contents of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Thu Mar 19 11:51:13 2009 UTC (5 years, 11 months ago) by scarabeus
Branch: MAIN
Changes since 1.15: +9 -3 lines
Update --depth 1 behavior for only working cases.

1 ferdy 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 scarabeus 1.16 # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.15 2009/02/19 17:07:28 scarabeus 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.16 EGIT_FETCH_CMD="git clone --bare"
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 scarabeus 1.16 # determine whether to perform shallow clone
193     local EGIT_FETCH_OPTS
194     if [[ ${EGIT_BRANCH} = ${EGIT_TREE} ]] && [[ ${EGIT_BRANCH} = master ]] ; then
195     EGIT_FETCH_OPTS="--depth 1"
196     fi
197    
198 ferdy 1.1 debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\""
199    
200 zlin 1.12 export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
201 ferdy 1.1
202     if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then
203     # first clone
204     einfo "git clone start -->"
205     einfo " repository: ${EGIT_REPO_URI}"
206    
207 scarabeus 1.16 ${EGIT_FETCH_CMD} ${EGIT_FETCH_OPTS} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \
208 ferdy 1.1 || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."
209    
210     # We use --bare cloning, so git doesn't do this for us.
211 ferdy 1.7 git config remote.origin.url "${EGIT_REPO_URI}"
212 robbat2 1.9 elif [[ -n ${EGIT_OFFLINE} ]] ; then
213     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
214     einfo "git update offline mode -->"
215     einfo " repository: ${EGIT_REPO_URI}"
216     einfo " commit: ${oldsha1}"
217 ferdy 1.1 else
218 ferdy 1.7 # Git urls might change, so unconditionally set it here
219     git config remote.origin.url "${EGIT_REPO_URI}"
220    
221 ferdy 1.1 # fetch updates
222     einfo "git update start -->"
223     einfo " repository: ${EGIT_REPO_URI}"
224    
225     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
226    
227     ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \
228     || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
229    
230 ferdy 1.3 # piping through cat is needed to avoid a stupid Git feature
231     ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} | cat
232 ferdy 1.1 fi
233    
234     einfo " local clone: ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
235    
236 ferdy 1.6 if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then
237     ebegin "Garbage collecting the repository"
238     git gc $(${EGIT_PRUNE} && echo '--prune')
239 ferdy 1.1 eend $?
240     fi
241    
242     einfo " committish: ${EGIT_TREE}"
243    
244     # export to the ${WORKDIR}
245 zlin 1.14 mkdir -p "${S}"
246     git archive --format=tar ${EGIT_TREE} | ( cd "${S}" ; tar xf - )
247 vapier 1.5
248     echo ">>> Unpacked to ${S}"
249 ferdy 1.1
250     }
251    
252    
253     ## -- git_bootstrap() ------------------------------------------------ #
254    
255     git_bootstrap() {
256    
257     local patch lpatch
258    
259     cd "${S}"
260    
261     if [[ -n ${EGIT_PATCHES} ]] ; then
262     einfo "apply patches -->"
263    
264     for patch in ${EGIT_PATCHES} ; do
265     if [[ -f ${patch} ]] ; then
266     epatch ${patch}
267     else
268     for lpatch in "${FILESDIR}"/${patch} ; do
269     if [[ -f ${lpatch} ]] ; then
270     epatch ${lpatch}
271     else
272     die "${EGIT}: ${patch} is not found"
273     fi
274     done
275     fi
276     done
277     echo
278     fi
279    
280     if [[ -n ${EGIT_BOOTSTRAP} ]] ; then
281     einfo "begin bootstrap -->"
282    
283     if [[ -f ${EGIT_BOOTSTRAP} ]] && [[ -x ${EGIT_BOOTSTRAP} ]] ; then
284     einfo " bootstrap with a file: ${EGIT_BOOTSTRAP}"
285     eval "./${EGIT_BOOTSTRAP}" \
286     || die "${EGIT}: can't execute EGIT_BOOTSTRAP."
287     else
288     einfo " bootstrap with commands: ${EGIT_BOOTSTRAP}"
289     eval "${EGIT_BOOTSTRAP}" \
290     || die "${EGIT}: can't eval EGIT_BOOTSTRAP."
291     fi
292     fi
293    
294     }
295    
296    
297     ## -- git_src_unpack() ------------------------------------------------ #
298    
299     git_src_unpack() {
300    
301     git_fetch || die "${EGIT}: unknown problem in git_fetch()."
302     git_bootstrap || die "${EGIT}: unknown problem in git_bootstrap()."
303    
304     }

  ViewVC Help
Powered by ViewVC 1.1.20