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

Contents of /eclass/git.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (hide annotations) (download)
Mon Jun 16 11:22:38 2008 UTC (6 years, 3 months ago) by zlin
Branch: MAIN
Changes since 1.13: +2 -3 lines
Revert last commit as it turns out it breaks with latest stable git (1.5.4.x and below).

1 ferdy 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 zlin 1.13 # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.12 2008/06/15 17:47:57 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     #
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 robbat2 1.9 # @ECLASS-VARIABLE: EGIT_OFFLINE
99     # @DESCRIPTION:
100     # Set this variable to a non-empty value to disable the automatic updating of
101 robbat2 1.10 # an GIT source tree. This is intended to be set outside the git source
102 robbat2 1.9 # tree by users.
103     EGIT_OFFLINE="${EGIT_OFFLINE:-${ESCM_OFFLINE}}"
104 ferdy 1.1
105     ## -- EGIT_PATCHES:
106     #
107     # git eclass can apply pathces in git_bootstrap().
108     # you can use regexp in this valiable like *.diff or *.patch or etc.
109     # NOTE: this patches will apply before eval EGIT_BOOTSTRAP.
110     #
111     # the process of applying the patch is:
112     # 1. just epatch it, if the patch exists in the path.
113     # 2. scan it under FILESDIR and epatch it, if the patch exists in FILESDIR.
114     # 3. die.
115     #
116     : ${EGIT_PATCHES:=}
117    
118    
119     ## -- EGIT_BRANCH:
120     #
121     # git eclass can fetch any branch in git_fetch().
122 robbat2 1.8 # If set, it must be before 'inherit git', otherwise both EGIT_BRANCH and
123     # EGIT_TREE must be set after 'inherit git'.
124 ferdy 1.1 # Defaults to 'master'
125     #
126     : ${EGIT_BRANCH:=master}
127    
128    
129     ## -- EGIT_TREE:
130     #
131     # git eclass can checkout any tree.
132     # Defaults to EGIT_BRANCH.
133     #
134     : ${EGIT_TREE:=${EGIT_BRANCH}}
135    
136    
137     ## - EGIT_REPACK:
138     #
139     # git eclass will repack objects to save disk space. However this can take a
140     # long time with VERY big repositories. If this is your case set:
141     # EGIT_REPACK=false
142     #
143     : ${EGIT_REPACK:=false}
144    
145     ## - EGIT_PRUNE:
146     #
147     # git eclass can prune the local clone. This is useful if upstream rewinds and
148     # rebases branches too often. If you don't want this to happen, set:
149     # EGIT_PRUNE=false
150     #
151     : ${EGIT_PRUNE:=false}
152    
153    
154     ## -- git_fetch() ------------------------------------------------- #
155    
156     git_fetch() {
157    
158     local EGIT_CLONE_DIR
159    
160     # EGIT_REPO_URI is empty.
161     [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty."
162    
163 ferdy 1.4 # check for the protocol or pull from a local repo.
164     if [[ -z ${EGIT_REPO_URI%%:*} ]] ; then
165     case ${EGIT_REPO_URI%%:*} in
166     git*|http|https|rsync|ssh)
167     ;;
168     *)
169     die "${EGIT}: fetch from "${EGIT_REPO_URI%:*}" is not yet implemented."
170     ;;
171     esac
172     fi
173 ferdy 1.1
174     if [[ ! -d ${EGIT_STORE_DIR} ]] ; then
175     debug-print "${FUNCNAME}: initial clone. creating git directory"
176     addwrite /
177     mkdir -p "${EGIT_STORE_DIR}" \
178     || die "${EGIT}: can't mkdir ${EGIT_STORE_DIR}."
179     export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
180     fi
181    
182     cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}"
183     EGIT_STORE_DIR=${PWD}
184    
185     # every time
186     addwrite "${EGIT_STORE_DIR}"
187    
188     [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}"
189     EGIT_CLONE_DIR="${EGIT_PROJECT}"
190    
191     debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\""
192    
193 zlin 1.12 export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
194 ferdy 1.1
195     if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then
196     # first clone
197     einfo "git clone start -->"
198     einfo " repository: ${EGIT_REPO_URI}"
199    
200     ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \
201     || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."
202    
203     # We use --bare cloning, so git doesn't do this for us.
204 ferdy 1.7 git config remote.origin.url "${EGIT_REPO_URI}"
205 robbat2 1.9 elif [[ -n ${EGIT_OFFLINE} ]] ; then
206     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
207     einfo "git update offline mode -->"
208     einfo " repository: ${EGIT_REPO_URI}"
209     einfo " commit: ${oldsha1}"
210 ferdy 1.1 else
211 ferdy 1.7 # Git urls might change, so unconditionally set it here
212     git config remote.origin.url "${EGIT_REPO_URI}"
213    
214 ferdy 1.1 # fetch updates
215     einfo "git update start -->"
216     einfo " repository: ${EGIT_REPO_URI}"
217    
218     local oldsha1=$(git rev-parse ${EGIT_BRANCH})
219    
220     ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \
221     || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
222    
223 ferdy 1.3 # piping through cat is needed to avoid a stupid Git feature
224     ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} | cat
225 ferdy 1.1 fi
226    
227     einfo " local clone: ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}"
228    
229 ferdy 1.6 if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then
230     ebegin "Garbage collecting the repository"
231     git gc $(${EGIT_PRUNE} && echo '--prune')
232 ferdy 1.1 eend $?
233     fi
234    
235     einfo " committish: ${EGIT_TREE}"
236    
237     # export to the ${WORKDIR}
238 zlin 1.14 mkdir -p "${S}"
239     git archive --format=tar ${EGIT_TREE} | ( cd "${S}" ; tar xf - )
240 vapier 1.5
241     echo ">>> Unpacked to ${S}"
242 ferdy 1.1
243     }
244    
245    
246     ## -- git_bootstrap() ------------------------------------------------ #
247    
248     git_bootstrap() {
249    
250     local patch lpatch
251    
252     cd "${S}"
253    
254     if [[ -n ${EGIT_PATCHES} ]] ; then
255     einfo "apply patches -->"
256    
257     for patch in ${EGIT_PATCHES} ; do
258     if [[ -f ${patch} ]] ; then
259     epatch ${patch}
260     else
261     for lpatch in "${FILESDIR}"/${patch} ; do
262     if [[ -f ${lpatch} ]] ; then
263     epatch ${lpatch}
264     else
265     die "${EGIT}: ${patch} is not found"
266     fi
267     done
268     fi
269     done
270     echo
271     fi
272    
273     if [[ -n ${EGIT_BOOTSTRAP} ]] ; then
274     einfo "begin bootstrap -->"
275    
276     if [[ -f ${EGIT_BOOTSTRAP} ]] && [[ -x ${EGIT_BOOTSTRAP} ]] ; then
277     einfo " bootstrap with a file: ${EGIT_BOOTSTRAP}"
278     eval "./${EGIT_BOOTSTRAP}" \
279     || die "${EGIT}: can't execute EGIT_BOOTSTRAP."
280     else
281     einfo " bootstrap with commands: ${EGIT_BOOTSTRAP}"
282     eval "${EGIT_BOOTSTRAP}" \
283     || die "${EGIT}: can't eval EGIT_BOOTSTRAP."
284     fi
285     fi
286    
287     }
288    
289    
290     ## -- git_src_unpack() ------------------------------------------------ #
291    
292     git_src_unpack() {
293    
294     git_fetch || die "${EGIT}: unknown problem in git_fetch()."
295     git_bootstrap || die "${EGIT}: unknown problem in git_bootstrap()."
296    
297     }

  ViewVC Help
Powered by ViewVC 1.1.20