| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2009 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.31 2009/10/20 10:05:47 scarabeus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/git.eclass,v 1.32 2009/12/16 20:35:38 scarabeus Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: git.eclass |
5 | # @ECLASS: git.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Tomas Chvatal <scarabeus@gentoo.org> |
7 | # Tomas Chvatal <scarabeus@gentoo.org> |
| 8 | # Donnie Berkholz <dberkholz@gentoo.org> |
8 | # Donnie Berkholz <dberkholz@gentoo.org> |
| … | |
… | |
| 45 | [[ -z ${EGIT_STORE_DIR} ]] && EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
45 | [[ -z ${EGIT_STORE_DIR} ]] && EGIT_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src" |
| 46 | |
46 | |
| 47 | # @ECLASS-VARIABLE: EGIT_FETCH_CMD |
47 | # @ECLASS-VARIABLE: EGIT_FETCH_CMD |
| 48 | # @DESCRIPTION: |
48 | # @DESCRIPTION: |
| 49 | # Command for cloning the repository. |
49 | # Command for cloning the repository. |
| 50 | : ${EGIT_FETCH_CMD:="git clone --bare"} |
50 | : ${EGIT_FETCH_CMD:="git clone"} |
| 51 | |
51 | |
| 52 | # @ECLASS-VARIABLE: EGIT_UPDATE_CMD |
52 | # @ECLASS-VARIABLE: EGIT_UPDATE_CMD |
| 53 | # @DESCRIPTION: |
53 | # @DESCRIPTION: |
| 54 | # Git fetch command. |
54 | # Git fetch command. |
| 55 | EGIT_UPDATE_CMD="git fetch -f -u" |
55 | EGIT_UPDATE_CMD="git pull -f -u" |
| 56 | |
56 | |
| 57 | # @ECLASS-VARIABLE: EGIT_DIFFSTAT_CMD |
57 | # @ECLASS-VARIABLE: EGIT_DIFFSTAT_CMD |
| 58 | # @DESCRIPTION: |
58 | # @DESCRIPTION: |
| 59 | # Git command for diffstat. |
59 | # Git command for diffstat. |
| 60 | EGIT_DIFFSTAT_CMD="git --no-pager diff --stat" |
60 | EGIT_DIFFSTAT_CMD="git --no-pager diff --stat" |
| … | |
… | |
| 118 | EGIT_BRANCH=${EGIT_BRANCH:=master} |
118 | EGIT_BRANCH=${EGIT_BRANCH:=master} |
| 119 | else |
119 | else |
| 120 | EGIT_BRANCH="${X}" |
120 | EGIT_BRANCH="${X}" |
| 121 | fi |
121 | fi |
| 122 | |
122 | |
| 123 | # @ECLASS-VARIABLE: EGIT_TREE |
123 | # @ECLASS-VARIABLE: EGIT_COMMIT |
| 124 | # @DESCRIPTION: |
124 | # @DESCRIPTION: |
| 125 | # git eclass can checkout any tree (commit). |
125 | # git eclass can checkout any commit. |
| 126 | eval X="\$${PN//[-+]/_}_LIVE_TREE" |
126 | eval X="\$${PN//[-+]/_}_LIVE_COMMIT" |
| 127 | if [[ ${X} = "" ]]; then |
127 | if [[ ${X} = "" ]]; then |
| 128 | : ${EGIT_TREE:=${EGIT_BRANCH}} |
128 | : ${EGIT_COMMIT:=${EGIT_BRANCH}} |
| 129 | else |
129 | else |
| 130 | EGIT_TREE="${X}" |
130 | EGIT_COMMIT="${X}" |
| 131 | fi |
131 | fi |
| 132 | |
132 | |
| 133 | # @ECLASS-VARIABLE: EGIT_REPACK |
133 | # @ECLASS-VARIABLE: EGIT_REPACK |
| 134 | # @DESCRIPTION: |
134 | # @DESCRIPTION: |
| 135 | # git eclass will repack objects to save disk space. However this can take a |
135 | # git eclass will repack objects to save disk space. However this can take a |
| 136 | # long time with VERY big repositories. |
136 | # long time with VERY big repositories. |
| 137 | : ${EGIT_REPACK:=false} |
137 | : ${EGIT_REPACK:=false} |
| 138 | |
138 | |
| 139 | # @ECLASS-VARIABLE: EGIT_PRUNE |
139 | # @ECLASS-VARIABLE: EGIT_PRUNE |
| 140 | # @DESCRIPTION: |
140 | # @DESCRIPTION: |
| 141 | # git.eclass can prune the local clone. This is useful if upstream rewinds and |
141 | # git eclass can prune the local clone. This is useful if upstream rewinds and |
| 142 | # rebases branches too often. |
142 | # rebases branches too often. |
| 143 | : ${EGIT_PRUNE:=false} |
143 | : ${EGIT_PRUNE:=false} |
|
|
144 | |
|
|
145 | # @FUNCTION: git_submodules |
|
|
146 | # @DESCRIPTION: |
|
|
147 | # Internal function wrapping the submodule initialisation and update |
|
|
148 | git_sumbodules() { |
|
|
149 | debug-print "git submodule init" |
|
|
150 | git submodule init |
|
|
151 | debug-print "git submodule update" |
|
|
152 | git submodule update |
|
|
153 | } |
| 144 | |
154 | |
| 145 | # @FUNCTION: git_fetch |
155 | # @FUNCTION: git_fetch |
| 146 | # @DESCRIPTION: |
156 | # @DESCRIPTION: |
| 147 | # Gets repository from EGIT_REPO_URI and store it in specified EGIT_STORE_DIR |
157 | # Gets repository from EGIT_REPO_URI and store it in specified EGIT_STORE_DIR |
| 148 | git_fetch() { |
158 | git_fetch() { |
| 149 | debug-print-function ${FUNCNAME} "$@" |
159 | debug-print-function ${FUNCNAME} "$@" |
| 150 | |
160 | |
| 151 | local EGIT_CLONE_DIR oldsha1 cursha1 |
161 | local GIT_DIR EGIT_CLONE_DIR oldsha1 cursha1 |
| 152 | |
162 | |
| 153 | # choose if user wants elog or just einfo. |
163 | # choose if user wants elog or just einfo. |
| 154 | if [[ ${EGIT_QUIET} != OFF ]]; then |
164 | if [[ ${EGIT_QUIET} != OFF ]]; then |
| 155 | elogcmd="einfo" |
165 | elogcmd="einfo" |
| 156 | else |
166 | else |
| … | |
… | |
| 159 | |
169 | |
| 160 | # If we have same branch and the tree we can do --depth 1 clone |
170 | # If we have same branch and the tree we can do --depth 1 clone |
| 161 | # which outputs into really smaller data transfers. |
171 | # which outputs into really smaller data transfers. |
| 162 | # Sadly we can do shallow copy for now because quite a few packages need .git |
172 | # Sadly we can do shallow copy for now because quite a few packages need .git |
| 163 | # folder. |
173 | # folder. |
| 164 | #[[ ${EGIT_TREE} = ${EGIT_BRANCH} ]] && \ |
174 | #[[ ${EGIT_COMMIT} = ${EGIT_BRANCH} ]] && \ |
| 165 | # EGIT_FETCH_CMD="${EGIT_FETCH_CMD} --depth 1" |
175 | # EGIT_FETCH_CMD="${EGIT_FETCH_CMD} --depth 1" |
|
|
176 | if [[ ! -z ${EGIT_TREE} ]] ; then |
|
|
177 | EGIT_COMMIT=${EGIT_TREE} |
|
|
178 | eqawarn "Usage of deprecated EGIT_TREE variable detected." |
|
|
179 | eqawarn "Use EGIT_COMMIT variable instead." |
|
|
180 | fi |
| 166 | |
181 | |
| 167 | # EGIT_REPO_URI is empty. |
182 | # EGIT_REPO_URI is empty. |
| 168 | [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty." |
183 | [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty." |
| 169 | |
184 | |
| 170 | # check for the protocol or pull from a local repo. |
185 | # check for the protocol or pull from a local repo. |
| … | |
… | |
| 194 | [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" |
209 | [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" |
| 195 | EGIT_CLONE_DIR="${EGIT_PROJECT}" |
210 | EGIT_CLONE_DIR="${EGIT_PROJECT}" |
| 196 | |
211 | |
| 197 | debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"" |
212 | debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"" |
| 198 | |
213 | |
| 199 | export GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
214 | GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
| 200 | |
215 | pushd ${EGIT_STORE_DIR} &> /dev/null |
| 201 | # we also have to remove all shallow copied repositories |
216 | # we also have to remove all shallow copied repositories |
| 202 | # and fetch them again |
217 | # and fetch them again |
| 203 | if [[ -e "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}/shallow" ]]; then |
218 | if [[ -e "${GIT_DIR}/shallow" ]]; then |
| 204 | rm -rf "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" |
219 | rm -rf "${GIT_DIR}" |
| 205 | einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching." |
220 | einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching." |
| 206 | fi |
221 | fi |
|
|
222 | # repack from bare copy to normal one |
|
|
223 | if [[ -d ${GIT_DIR} && ! -d "${GIT_DIR}/.git/" ]]; then |
|
|
224 | rm -rf "${GIT_DIR}" |
|
|
225 | einfo "The ${EGIT_CLONE_DIR} was bare copy. Refetching." |
|
|
226 | fi |
| 207 | |
227 | |
| 208 | if [[ ! -d ${EGIT_CLONE_DIR} ]] ; then |
228 | if [[ ! -d ${GIT_DIR} ]] ; then |
| 209 | # first clone |
229 | # first clone |
| 210 | ${elogcmd} "GIT NEW clone -->" |
230 | ${elogcmd} "GIT NEW clone -->" |
| 211 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
231 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 212 | |
232 | |
|
|
233 | debug-print "${EGIT_FETCH_CMD} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" ${GIT_DIR}" |
| 213 | ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${EGIT_PROJECT} \ |
234 | ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${GIT_DIR} \ |
| 214 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
235 | || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}." |
| 215 | |
236 | |
|
|
237 | pushd "${GIT_DIR}" &> /dev/null |
| 216 | cursha1=$(git rev-parse ${EGIT_BRANCH}) |
238 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
| 217 | ${elogcmd} " at the commit: ${cursha1}" |
239 | ${elogcmd} " at the commit: ${cursha1}" |
| 218 | # We use --bare cloning, so git doesn't do this for us. |
240 | |
| 219 | git config remote.origin.url "${EGIT_REPO_URI}" |
241 | git_sumbodules |
|
|
242 | popd &> /dev/null |
| 220 | elif [[ -n ${EGIT_OFFLINE} ]] ; then |
243 | elif [[ -n ${EGIT_OFFLINE} ]] ; then |
|
|
244 | pushd "${GIT_DIR}" &> /dev/null |
| 221 | cursha1=$(git rev-parse ${EGIT_BRANCH}) |
245 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
| 222 | ${elogcmd} "GIT offline update -->" |
246 | ${elogcmd} "GIT offline update -->" |
| 223 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
247 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 224 | ${elogcmd} " at the commit: ${cursha1}" |
248 | ${elogcmd} " at the commit: ${cursha1}" |
|
|
249 | popd &> /dev/null |
| 225 | else |
250 | else |
|
|
251 | pushd "${GIT_DIR}" &> /dev/null |
| 226 | # Git urls might change, so unconditionally set it here |
252 | # Git urls might change, so unconditionally set it here |
| 227 | git config remote.origin.url "${EGIT_REPO_URI}" |
253 | git config remote.origin.url "${EGIT_REPO_URI}" |
| 228 | |
254 | |
| 229 | # fetch updates |
255 | # fetch updates |
| 230 | ${elogcmd} "GIT update -->" |
256 | ${elogcmd} "GIT update -->" |
| 231 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
257 | ${elogcmd} " repository: ${EGIT_REPO_URI}" |
| 232 | |
258 | |
| 233 | oldsha1=$(git rev-parse ${EGIT_BRANCH}) |
259 | oldsha1=$(git rev-parse origin/${EGIT_BRANCH}) |
| 234 | |
260 | |
| 235 | ${elogcmd} ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} |
261 | debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}" |
| 236 | ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \ |
262 | ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} \ |
| 237 | || die "${EGIT}: can't update from ${EGIT_REPO_URI}." |
263 | || die "${EGIT}: can't update from ${EGIT_REPO_URI}." |
| 238 | |
264 | |
|
|
265 | git_sumbodules |
| 239 | cursha1=$(git rev-parse ${EGIT_BRANCH}) |
266 | cursha1=$(git rev-parse origin/${EGIT_BRANCH}) |
| 240 | |
267 | |
| 241 | # write out message based on the revisions |
268 | # write out message based on the revisions |
| 242 | if [[ ${oldsha1} != ${cursha1} ]]; then |
269 | if [[ ${oldsha1} != ${cursha1} ]]; then |
| 243 | ${elogcmd} " updating from commit: ${oldsha1}" |
270 | ${elogcmd} " updating from commit: ${oldsha1}" |
| 244 | ${elogcmd} " to commit: ${cursha1}" |
271 | ${elogcmd} " to commit: ${cursha1}" |
| … | |
… | |
| 253 | # TODO: this can lead to issues if more projects/packages use same repo |
280 | # TODO: this can lead to issues if more projects/packages use same repo |
| 254 | [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \ |
281 | [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && \ |
| 255 | debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \ |
282 | debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && \ |
| 256 | die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." |
283 | die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." |
| 257 | fi |
284 | fi |
| 258 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${EGIT_BRANCH} |
285 | ${EGIT_DIFFSTAT_CMD} ${oldsha1}..origin/${EGIT_BRANCH} |
|
|
286 | popd &> /dev/null |
| 259 | fi |
287 | fi |
| 260 | |
288 | |
|
|
289 | pushd "${GIT_DIR}" &> /dev/null |
| 261 | if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then |
290 | if ${EGIT_REPACK} || ${EGIT_PRUNE} ; then |
| 262 | ebegin "Garbage collecting the repository" |
291 | ebegin "Garbage collecting the repository" |
| 263 | git gc $(${EGIT_PRUNE} && echo '--prune') |
292 | git gc $(${EGIT_PRUNE} && echo '--prune') |
| 264 | eend $? |
293 | eend $? |
| 265 | fi |
294 | fi |
|
|
295 | popd &> /dev/null |
| 266 | |
296 | |
| 267 | # export the git version |
297 | # export the git version |
| 268 | export EGIT_VERSION="${cursha1}" |
298 | export EGIT_VERSION="${cursha1}" |
| 269 | |
299 | |
| 270 | [[ ${EGIT_TREE} != ${EGIT_BRANCH} ]] && elog " tree: ${EGIT_TREE}" |
300 | [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] && elog " commit: ${EGIT_COMMIT}" |
| 271 | ${elogcmd} " branch: ${EGIT_BRANCH}" |
301 | ${elogcmd} " branch: ${EGIT_BRANCH}" |
| 272 | ${elogcmd} " storage directory: \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\"" |
302 | ${elogcmd} " storage directory: \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\"" |
| 273 | |
303 | |
| 274 | # unpack to the ${S} |
304 | # unpack to the ${S} |
| 275 | unset GIT_DIR |
305 | popd &> /dev/null |
| 276 | debug-print "git clone -l -s -n \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\" \"${S}\"" |
306 | debug-print "cp -aR \"${GIT_DIR}\" \"${S}\"" |
| 277 | git clone -l -s -n "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" "${S}" |
307 | cp -aR "${GIT_DIR}" "${S}" |
| 278 | |
308 | |
| 279 | # set correct branch and the tree ebuild specified |
309 | # set correct branch and the tree ebuild specified |
| 280 | pushd "${S}" > /dev/null |
310 | pushd "${S}" > /dev/null |
| 281 | local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} |
311 | local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} |
| 282 | if [[ ${EGIT_TREE} != ${EGIT_BRANCH} ]]; then |
312 | if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then |
| 283 | branchname=tree-${EGIT_TREE} |
313 | branchname=tree-${EGIT_COMMIT} |
| 284 | src=${EGIT_TREE} |
314 | src=${EGIT_COMMIT} |
| 285 | fi |
315 | fi |
| 286 | debug-print "git checkout -b ${branchname} ${src}" |
316 | debug-print "git checkout -b ${branchname} ${src}" |
| 287 | git checkout -b ${branchname} ${src} 2>&1 > /dev/null |
317 | git checkout -b ${branchname} ${src} 2>&1 > /dev/null |
| 288 | debug-print "git submodule init" |
318 | git_sumbodules |
| 289 | git submodule init 2>&1 > /dev/null |
|
|
| 290 | debug-print "git submodule update" |
|
|
| 291 | git submodule update 2>&1 > /dev/null |
|
|
| 292 | popd > /dev/null |
319 | popd > /dev/null |
| 293 | |
320 | |
| 294 | unset branchname src |
321 | unset branchname src |
| 295 | |
322 | |
| 296 | echo ">>> Unpacked to ${S}" |
323 | echo ">>> Unpacked to ${S}" |