| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.5 2007/04/10 11:42:29 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.16 2009/03/19 11:51:13 scarabeus Exp $ |
| 4 | |
4 | |
| 5 | ## --------------------------------------------------------------------------- # |
5 | ## --------------------------------------------------------------------------- # |
| 6 | # subversion.eclass author: Akinori Hattori <hattya@gentoo.org> |
6 | # subversion.eclass author: Akinori Hattori <hattya@gentoo.org> |
| 7 | # modified for git by Donnie Berkholz <spyderous@gentoo.org> |
7 | # modified for git by Donnie Berkholz <spyderous@gentoo.org> |
| 8 | # improved by Fernando J. Pereda <ferdy@gentoo.org> |
8 | # improved by Fernando J. Pereda <ferdy@gentoo.org> |
|
|
9 | # you should currently poke with updates Tomas Chvatal <scarabeus@gentoo.org> |
| 9 | # |
10 | # |
| 10 | # The git eclass is written to fetch the software sources from |
11 | # The git eclass is written to fetch the software sources from |
| 11 | # git repositories like the subversion eclass. |
12 | # git repositories like the subversion eclass. |
| 12 | # |
13 | # |
| 13 | # |
14 | # |
| … | |
… | |
| 27 | DESCRIPTION="Based on the ${ECLASS} eclass" |
28 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 28 | |
29 | |
| 29 | |
30 | |
| 30 | ## -- add git in DEPEND |
31 | ## -- add git in DEPEND |
| 31 | # |
32 | # |
| 32 | DEPEND=">=dev-util/git-1.4.0" |
33 | DEPEND=">=dev-util/git-1.5" |
| 33 | |
34 | |
| 34 | |
35 | |
| 35 | ## -- EGIT_STORE_DIR: git sources store directory |
36 | ## -- EGIT_STORE_DIR: git sources store directory |
| 36 | # |
37 | # |
| 37 | EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
38 | EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
| … | |
… | |
| 93 | # |
94 | # |
| 94 | # bootstrap script or command like autogen.sh or etc.. |
95 | # bootstrap script or command like autogen.sh or etc.. |
| 95 | # |
96 | # |
| 96 | : ${EGIT_BOOTSTRAP:=} |
97 | : ${EGIT_BOOTSTRAP:=} |
| 97 | |
98 | |
|
|
99 | # @ECLASS-VARIABLE: EGIT_OFFLINE |
|
|
100 | # @DESCRIPTION: |
|
|
101 | # Set this variable to a non-empty value to disable the automatic updating of |
|
|
102 | # an GIT source tree. This is intended to be set outside the git source |
|
|
103 | # tree by users. |
|
|
104 | EGIT_OFFLINE="${EGIT_OFFLINE:-${ESCM_OFFLINE}}" |
| 98 | |
105 | |
| 99 | ## -- EGIT_PATCHES: |
106 | ## -- EGIT_PATCHES: |
| 100 | # |
107 | # |
| 101 | # git eclass can apply pathces in git_bootstrap(). |
108 | # git eclass can apply pathces in git_bootstrap(). |
| 102 | # you can use regexp in this valiable like *.diff or *.patch or etc. |
109 | # you can use regexp in this valiable like *.diff or *.patch or etc. |
| … | |
… | |
| 111 | |
118 | |
| 112 | |
119 | |
| 113 | ## -- EGIT_BRANCH: |
120 | ## -- EGIT_BRANCH: |
| 114 | # |
121 | # |
| 115 | # git eclass can fetch any branch in git_fetch(). |
122 | # git eclass can fetch any branch in git_fetch(). |
|
|
123 | # If set, it must be before 'inherit git', otherwise both EGIT_BRANCH and |
|
|
124 | # EGIT_TREE must be set after 'inherit git'. |
| 116 | # Defaults to 'master' |
125 | # Defaults to 'master' |
| 117 | # |
126 | # |
| 118 | : ${EGIT_BRANCH:=master} |
127 | : ${EGIT_BRANCH:=master} |
| 119 | |
128 | |
| 120 | |
129 | |
| … | |
… | |
| 166 | if [[ ! -d ${EGIT_STORE_DIR} ]] ; then |
175 | if [[ ! -d ${EGIT_STORE_DIR} ]] ; then |
| 167 | debug-print "${FUNCNAME}: initial clone. creating git directory" |
176 | debug-print "${FUNCNAME}: initial clone. creating git directory" |
| 168 | addwrite / |
177 | addwrite / |
| 169 | mkdir -p "${EGIT_STORE_DIR}" \ |
178 | mkdir -p "${EGIT_STORE_DIR}" \ |
| 170 | || die "${EGIT}: can't mkdir ${EGIT_STORE_DIR}." |
179 | || 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%%:/}" |
180 | export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}" |
| 174 | fi |
181 | fi |
| 175 | |
182 | |
| 176 | cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}" |
183 | cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}" |
| 177 | EGIT_STORE_DIR=${PWD} |
184 | EGIT_STORE_DIR=${PWD} |
| … | |
… | |
| 180 | addwrite "${EGIT_STORE_DIR}" |
187 | addwrite "${EGIT_STORE_DIR}" |
| 181 | |
188 | |
| 182 | [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" |
189 | [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" |
| 183 | EGIT_CLONE_DIR="${EGIT_PROJECT}" |
190 | EGIT_CLONE_DIR="${EGIT_PROJECT}" |
| 184 | |
191 | |
|
|
192 | # 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 | |
| 185 | debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"" |
198 | debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"" |
| 186 | |
199 | |
| 187 | export GIT_DIR="${EGIT_CLONE_DIR}" |
200 | export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
| 188 | |
201 | |
| 189 | if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then |
202 | if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then |
| 190 | # first clone |
203 | # first clone |
| 191 | einfo "git clone start -->" |
204 | einfo "git clone start -->" |
| 192 | einfo " repository: ${EGIT_REPO_URI}" |
205 | einfo " repository: ${EGIT_REPO_URI}" |
| 193 | |
206 | |
| 194 | ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \ |
207 | ${EGIT_FETCH_CMD} ${EGIT_FETCH_OPTS} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \ |
| 195 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
208 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
| 196 | |
209 | |
| 197 | # We use --bare cloning, so git doesn't do this for us. |
210 | # We use --bare cloning, so git doesn't do this for us. |
| 198 | git repo-config remote.origin.url "${EGIT_REPO_URI}" |
211 | git config remote.origin.url "${EGIT_REPO_URI}" |
|
|
212 | 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}" |
| 199 | else |
217 | else |
|
|
218 | # Git urls might change, so unconditionally set it here |
|
|
219 | git config remote.origin.url "${EGIT_REPO_URI}" |
|
|
220 | |
| 200 | # fetch updates |
221 | # fetch updates |
| 201 | einfo "git update start -->" |
222 | einfo "git update start -->" |
| 202 | einfo " repository: ${EGIT_REPO_URI}" |
223 | einfo " repository: ${EGIT_REPO_URI}" |
| 203 | |
224 | |
| 204 | local oldsha1=$(git rev-parse ${EGIT_BRANCH}) |
225 | local oldsha1=$(git rev-parse ${EGIT_BRANCH}) |
| … | |
… | |
| 210 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} | cat |
231 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} | cat |
| 211 | fi |
232 | fi |
| 212 | |
233 | |
| 213 | einfo " local clone: ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
234 | einfo " local clone: ${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
| 214 | |
235 | |
| 215 | if ${EGIT_REPACK} ; then |
236 | if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then |
| 216 | ebegin "Repacking objects" |
237 | ebegin "Garbage collecting the repository" |
| 217 | # Strangely enough mv asks confirmation |
238 | git gc $(${EGIT_PRUNE} && echo '--prune') |
| 218 | yes y | git repack -a -d -f -q > /dev/null |
|
|
| 219 | eend $? |
|
|
| 220 | fi |
|
|
| 221 | |
|
|
| 222 | if ${EGIT_PRUNE} ; then |
|
|
| 223 | ebegin "Removing unreachable objects" |
|
|
| 224 | git prune |
|
|
| 225 | eend $? |
239 | eend $? |
| 226 | fi |
240 | fi |
| 227 | |
241 | |
| 228 | einfo " committish: ${EGIT_TREE}" |
242 | einfo " committish: ${EGIT_TREE}" |
| 229 | |
243 | |
| 230 | # export to the ${WORKDIR} |
244 | # export to the ${WORKDIR} |
| 231 | mkdir -p "${S}" |
245 | mkdir -p "${S}" |
| 232 | git tar-tree ${EGIT_TREE} | ( cd "${S}" ; tar xf - ) |
246 | git archive --format=tar ${EGIT_TREE} | ( cd "${S}" ; tar xf - ) |
| 233 | |
247 | |
| 234 | echo ">>> Unpacked to ${S}" |
248 | echo ">>> Unpacked to ${S}" |
| 235 | |
249 | |
| 236 | } |
250 | } |
| 237 | |
251 | |