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

Contents of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Apr 24 16:35:01 2007 UTC (7 years, 8 months ago) by ferdy
Branch: MAIN
Changes since 1.5: +6 -13 lines
Fix for bug #152615. Thanks to Avuton Olrich <avuton@gmail.com>

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

  ViewVC Help
Powered by ViewVC 1.1.20