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

Diff of /eclass/git-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.27
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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-2.eclass,v 1.1 2011/04/20 10:56:27 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.27 2011/12/14 23:40:18 vapier Exp $
4 4
5# @ECLASS: git-2.eclass 5# @ECLASS: git-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Tomas Chvatal <scarabeus@gentoo.org> 7# Donnie Berkholz <dberkholz@gentoo.org>
8# Michał Górny <mgorny@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 9# @BLURB: Eclass for fetching and unpacking git repositories.
9# @DESCRIPTION: 10# @DESCRIPTION:
10# Eclass for easing maitenance of live ebuilds using git as remote repository. 11# Eclass for easing maitenance of live ebuilds using git as remote repository.
11# Eclass support working with git submodules and branching. 12# Eclass support working with git submodules and branching.
12 13
44# Variable for specifying master branch. 45# Variable for specifying master branch.
45# Usefull when upstream don't have master branch or name it differently. 46# Usefull when upstream don't have master branch or name it differently.
46# 47#
47# EGIT_MASTER="master" 48# EGIT_MASTER="master"
48 49
50# @ECLASS-VARIABLE: EGIT_PROJECT
51# @DESCRIPTION:
52# Variable specifying name for the folder where we check out the git
53# repository. Value of this variable should be unique in the
54# EGIT_STORE_DIR as otherwise you would override another repository.
55#
56# EGIT_PROJECT="${EGIT_REPO_URI##*/}"
57
49# @ECLASS-VARIABLE: EGIT_DIR 58# @ECLASS-VARIABLE: EGIT_DIR
50# @DESCRIPTION: 59# @DESCRIPTION:
51# Directory where we want to store the git data. 60# Directory where we want to store the git data.
52# This should not be overriden unless really required. 61# This variable should not be overriden.
53# 62#
54# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_REPO_URI##*/}" 63# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
55 64
56# @ECLASS-VARIABLE: EGIT_REPO_URI 65# @ECLASS-VARIABLE: EGIT_REPO_URI
57# @REQUIRED 66# @REQUIRED
58# @DEFAULT_UNSET 67# @DEFAULT_UNSET
59# @DESCRIPTION: 68# @DESCRIPTION:
81# @DESCRIPTION: 90# @DESCRIPTION:
82# Variable containing commit hash/tag we want to check out. 91# Variable containing commit hash/tag we want to check out.
83# It can be overriden via env using packagename_LIVE_COMMIT 92# It can be overriden via env using packagename_LIVE_COMMIT
84# variable. 93# variable.
85# 94#
86# EGIT_BRANCH="${EGIT_BRANCH}" 95# EGIT_COMMIT="${EGIT_BRANCH}"
87 96
88# @ECLASS-VARIABLE: EGIT_REPACK 97# @ECLASS-VARIABLE: EGIT_REPACK
89# @DEFAULT_UNSET 98# @DEFAULT_UNSET
90# @DESCRIPTION: 99# @DESCRIPTION:
91# If non-empty this variable specifies that repository will be repacked to 100# If non-empty this variable specifies that repository will be repacked to
103# @DESCRIPTION: 112# @DESCRIPTION:
104# If non-empty this variable specifies that all checkouts will be done using 113# If non-empty this variable specifies that all checkouts will be done using
105# non bare repositories. This is useful if you can't operate with bare 114# non bare repositories. This is useful if you can't operate with bare
106# checkouts for some reason. 115# checkouts for some reason.
107 116
117# @ECLASS-VARIABLE: EGIT_NOUNPACK
118# @DEFAULT_UNSET
119# @DESCRIPTION:
120# If non-empty this variable bans unpacking of ${A} content into the srcdir.
121# Default behaviour is to unpack ${A} content.
122
108# @FUNCTION: git-2_init_variables 123# @FUNCTION: git-2_init_variables
124# @INTERNAL
109# @DESCRIPTION: 125# @DESCRIPTION:
110# Internal function initializing all git variables. 126# Internal function initializing all git variables.
111# We define it in function scope so user can define 127# We define it in function scope so user can define
112# all the variables before and after inherit. 128# all the variables before and after inherit.
113git-2_init_variables() { 129git-2_init_variables() {
114 debug-print-function ${FUNCNAME} "$@" 130 debug-print-function ${FUNCNAME} "$@"
115 131
116 local x 132 local esc_pn liverepo livebranch livecommit
133 esc_pn=${PN//[-+]/_}
117 134
118 : ${EGIT_SOURCEDIR="${S}"} 135 : ${EGIT_SOURCEDIR="${S}"}
119 136
120 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} 137 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"}
121 138
123 140
124 : ${EGIT_OPTIONS:=} 141 : ${EGIT_OPTIONS:=}
125 142
126 : ${EGIT_MASTER:=master} 143 : ${EGIT_MASTER:=master}
127 144
128 eval x="\$${PN//[-+]/_}_LIVE_REPO" 145 liverepo=${esc_pn}_LIVE_REPO
129 EGIT_REPO_URI=${x:-${EGIT_REPO_URI}} 146 EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}}
130 [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value" 147 [[ ${EGIT_REPO_URI} ]] || die "EGIT_REPO_URI must have some value"
131 148
132 : ${EVCS_OFFLINE:=} 149 : ${EVCS_OFFLINE:=}
133 150
134 eval x="\$${PN//[-+]/_}_LIVE_BRANCH" 151 livebranch=${esc_pn}_LIVE_BRANCH
135 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_BRANCH\" variable, you won't get any support" 152 [[ ${!livebranch} ]] && ewarn "QA: using \"${esc_pn}_LIVE_BRANCH\" variable, you won't get any support"
136 EGIT_BRANCH=${x:-${EGIT_BRANCH:-${EGIT_MASTER}}} 153 EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}}
137 154
138 eval x="\$${PN//[-+]/_}_LIVE_COMMIT" 155 livecommit=${esc_pn}_LIVE_COMMIT
139 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_COMMIT\" variable, you won't get any support" 156 [[ ${!livecommit} ]] && ewarn "QA: using \"${esc_pn}_LIVE_COMMIT\" variable, you won't get any support"
140 EGIT_COMMIT=${x:-${EGIT_COMMIT:-${EGIT_BRANCH}}} 157 EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}}
141 158
142 : ${EGIT_REPACK:=} 159 : ${EGIT_REPACK:=}
143 160
144 : ${EGIT_PRUNE:=} 161 : ${EGIT_PRUNE:=}
145} 162}
146 163
147# @FUNCTION: git-2_submodules 164# @FUNCTION: git-2_submodules
165# @INTERNAL
148# @DESCRIPTION: 166# @DESCRIPTION:
149# Internal function wrapping the submodule initialisation and update. 167# Internal function wrapping the submodule initialisation and update.
150git-2_submodules() { 168git-2_submodules() {
151 debug-print-function ${FUNCNAME} "$@" 169 debug-print-function ${FUNCNAME} "$@"
152 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then 170 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
153 if [[ -n ${EVCS_OFFLINE} ]]; then 171 if [[ ${EVCS_OFFLINE} ]]; then
154 # for submodules operations we need to be online 172 # for submodules operations we need to be online
155 debug-print "${FUNCNAME}: not updating submodules in offline mode" 173 debug-print "${FUNCNAME}: not updating submodules in offline mode"
156 return 1 174 return 1
157 fi 175 fi
158 176
169 popd > /dev/null 187 popd > /dev/null
170 fi 188 fi
171} 189}
172 190
173# @FUNCTION: git-2_branch 191# @FUNCTION: git-2_branch
192# @INTERNAL
174# @DESCRIPTION: 193# @DESCRIPTION:
175# Internal function that changes branch for the repo based on EGIT_COMMIT and 194# Internal function that changes branch for the repo based on EGIT_COMMIT and
176# EGIT_BRANCH variables. 195# EGIT_BRANCH variables.
177git-2_branch() { 196git-2_branch() {
178 debug-print-function ${FUNCNAME} "$@" 197 debug-print-function ${FUNCNAME} "$@"
198
199 local branchname src
179 200
180 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" 201 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\""
181 pushd "${EGIT_SOURCEDIR}" > /dev/null 202 pushd "${EGIT_SOURCEDIR}" > /dev/null
182 203
183 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} 204 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
188 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" 209 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}"
189 git checkout -b ${branchname} ${src} \ 210 git checkout -b ${branchname} ${src} \
190 || die "${FUNCNAME}: changing the branch failed" 211 || die "${FUNCNAME}: changing the branch failed"
191 212
192 popd > /dev/null 213 popd > /dev/null
193
194 unset branchname src
195} 214}
196 215
197# @FUNCTION: git-2_gc 216# @FUNCTION: git-2_gc
217# @INTERNAL
198# @DESCRIPTION: 218# @DESCRIPTION:
199# Internal function running garbage collector on checked out tree. 219# Internal function running garbage collector on checked out tree.
200git-2_gc() { 220git-2_gc() {
201 debug-print-function ${FUNCNAME} "$@" 221 debug-print-function ${FUNCNAME} "$@"
202 222
223 local args
224
225 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
203 pushd "${EGIT_DIR}" > /dev/null 226 pushd "${EGIT_DIR}" > /dev/null
204 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then
205 ebegin "Garbage collecting the repository" 227 ebegin "Garbage collecting the repository"
206 local args
207 [[ -n ${EGIT_PRUNE} ]] && args='--prune' 228 [[ ${EGIT_PRUNE} ]] && args='--prune'
208 debug-print "${FUNCNAME}: git gc ${args}" 229 debug-print "${FUNCNAME}: git gc ${args}"
209 git gc ${args} 230 git gc ${args}
210 eend $? 231 eend $?
211 fi
212 popd > /dev/null 232 popd > /dev/null
233 fi
213} 234}
214 235
215# @FUNCTION: git-2_prepare_storedir 236# @FUNCTION: git-2_prepare_storedir
237# @INTERNAL
216# @DESCRIPTION: 238# @DESCRIPTION:
217# Internal function preparing directory where we are going to store SCM 239# Internal function preparing directory where we are going to store SCM
218# repository. 240# repository.
219git-2_prepare_storedir() { 241git-2_prepare_storedir() {
220 debug-print-function ${FUNCNAME} "$@" 242 debug-print-function ${FUNCNAME} "$@"
224 # initial clone, we have to create master git storage directory and play 246 # initial clone, we have to create master git storage directory and play
225 # nicely with sandbox 247 # nicely with sandbox
226 if [[ ! -d ${EGIT_STORE_DIR} ]]; then 248 if [[ ! -d ${EGIT_STORE_DIR} ]]; then
227 debug-print "${FUNCNAME}: Creating git main storage directory" 249 debug-print "${FUNCNAME}: Creating git main storage directory"
228 addwrite / 250 addwrite /
229 mkdir -p "${EGIT_STORE_DIR}" \ 251 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
230 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 252 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
231 fi 253 fi
232 254
233 cd -P "${EGIT_STORE_DIR}" \
234 || die "${FUNCNAME}: can't chdir to \"${EGIT_STORE_DIR}\""
235 # allow writing into EGIT_STORE_DIR 255 # allow writing into EGIT_STORE_DIR
236 addwrite "${EGIT_STORE_DIR}" 256 addwrite "${EGIT_STORE_DIR}"
257
258 # calculate git.eclass store dir for data
259 # We will try to clone the old repository,
260 # and we will remove it if we don't need it anymore.
261 EGIT_OLD_CLONE=
262 if [[ ${EGIT_STORE_DIR} == */egit-src ]]; then
263 local old_store_dir=${EGIT_STORE_DIR/%egit-src/git-src}
264 local old_location=${old_store_dir}/${EGIT_PROJECT:-${PN}}
265
266 if [[ -d ${old_location} ]]; then
267 EGIT_OLD_CLONE=${old_location}
268 # required to remove the old clone
269 addwrite "${old_store_dir}"
270 fi
271 fi
272
237 # calculate the proper store dir for data 273 # calculate the proper store dir for data
238 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" 274 # If user didn't specify the EGIT_DIR, we check if he did specify
275 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
276 EGIT_REPO_URI=${EGIT_REPO_URI%/}
239 if [[ -z ${EGIT_DIR} ]]; then 277 if [[ ! ${EGIT_DIR} ]]; then
278 if [[ ${EGIT_PROJECT} ]]; then
279 clone_dir=${EGIT_PROJECT}
280 else
240 clone_dir=${EGIT_REPO_URI##*/} 281 clone_dir=${EGIT_REPO_URI##*/}
282 fi
241 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 283 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
284
285 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
286 elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
287 elog "It will be necessary to rebuild the package to fetch updates."
288 EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
289 fi
242 fi 290 fi
243 export EGIT_DIR=${EGIT_DIR} 291 export EGIT_DIR=${EGIT_DIR}
244 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 292 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
245} 293}
246 294
247# @FUNCTION: git-2_move_source 295# @FUNCTION: git-2_move_source
296# @INTERNAL
248# @DESCRIPTION: 297# @DESCRIPTION:
249# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 298# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
250git-2_move_source() { 299git-2_move_source() {
251 debug-print-function ${FUNCNAME} "$@" 300 debug-print-function ${FUNCNAME} "$@"
252 301
258 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 307 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
259 popd > /dev/null 308 popd > /dev/null
260} 309}
261 310
262# @FUNCTION: git-2_initial_clone 311# @FUNCTION: git-2_initial_clone
312# @INTERNAL
263# @DESCRIPTION: 313# @DESCRIPTION:
264# Internal function running initial clone on specified repo_uri. 314# Internal function running initial clone on specified repo_uri.
265git-2_initial_clone() { 315git-2_initial_clone() {
266 debug-print-function ${FUNCNAME} "$@" 316 debug-print-function ${FUNCNAME} "$@"
267 317
268 local repo_uri 318 local repo_uri
269 319
270 EGIT_REPO_URI_SELECTED="" 320 EGIT_REPO_URI_SELECTED=""
271 for repo_uri in ${EGIT_REPO_URI}; do 321 for repo_uri in ${EGIT_REPO_URI}; do
272 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 322 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
273 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 323 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
274 if [[ $? -eq 0 ]]; then
275 # global variable containing the repo_name we will be using 324 # global variable containing the repo_name we will be using
276 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 325 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
277 EGIT_REPO_URI_SELECTED="${repo_uri}" 326 EGIT_REPO_URI_SELECTED="${repo_uri}"
278 break 327 break
279 fi 328 fi
280 done 329 done
281 330
282 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 331 [[ ${EGIT_REPO_URI_SELECTED} ]] \
283 die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 332 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
284 fi
285} 333}
286 334
287# @FUNCTION: git-2_update_repo 335# @FUNCTION: git-2_update_repo
336# @INTERNAL
288# @DESCRIPTION: 337# @DESCRIPTION:
289# Internal function running update command on specified repo_uri. 338# Internal function running update command on specified repo_uri.
290git-2_update_repo() { 339git-2_update_repo() {
291 debug-print-function ${FUNCNAME} "$@" 340 debug-print-function ${FUNCNAME} "$@"
292 341
293 local repo_uri 342 local repo_uri
294 343
295 if [[ -n ${EGIT_NONBARE} ]]; then 344 if [[ ${EGIT_LOCAL_NONBARE} ]]; then
296 # checkout master branch and drop all other local branches 345 # checkout master branch and drop all other local branches
297 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}" 346 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
298 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do 347 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
299 debug-print "${FUNCNAME}: git branch -D ${x}" 348 debug-print "${FUNCNAME}: git branch -D ${x}"
300 git branch -D ${x} > /dev/null 349 git branch -D ${x} > /dev/null
304 EGIT_REPO_URI_SELECTED="" 353 EGIT_REPO_URI_SELECTED=""
305 for repo_uri in ${EGIT_REPO_URI}; do 354 for repo_uri in ${EGIT_REPO_URI}; do
306 # git urls might change, so reset it 355 # git urls might change, so reset it
307 git config remote.origin.url "${repo_uri}" 356 git config remote.origin.url "${repo_uri}"
308 357
309 debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}" 358 debug-print "${EGIT_UPDATE_CMD}"
310 ${EGIT_UPDATE_CMD} > /dev/null 359 if ${EGIT_UPDATE_CMD} > /dev/null; then
311 if [[ $? -eq 0 ]]; then
312 # global variable containing the repo_name we will be using 360 # global variable containing the repo_name we will be using
313 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 361 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
314 EGIT_REPO_URI_SELECTED="${repo_uri}" 362 EGIT_REPO_URI_SELECTED="${repo_uri}"
315 break 363 break
316 fi 364 fi
317 done 365 done
318 366
319 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 367 [[ ${EGIT_REPO_URI_SELECTED} ]] \
320 die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 368 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
321 fi
322} 369}
323 370
324# @FUNCTION: git-2_fetch 371# @FUNCTION: git-2_fetch
372# @INTERNAL
325# @DESCRIPTION: 373# @DESCRIPTION:
326# Internal function fetching repository from EGIT_REPO_URI and storing it in 374# Internal function fetching repository from EGIT_REPO_URI and storing it in
327# specified EGIT_STORE_DIR. 375# specified EGIT_STORE_DIR.
328git-2_fetch() { 376git-2_fetch() {
329 debug-print-function ${FUNCNAME} "$@" 377 debug-print-function ${FUNCNAME} "$@"
330 378
331 local oldsha cursha repo_type 379 local oldsha cursha repo_type
332 380
333 [[ -n ${EGIT_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository" 381 [[ ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
334 382
335 if [[ ! -d ${EGIT_DIR} ]]; then 383 if [[ ! -d ${EGIT_DIR} ]]; then
336 git-2_initial_clone 384 git-2_initial_clone
337 pushd "${EGIT_DIR}" > /dev/null 385 pushd "${EGIT_DIR}" > /dev/null
338 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 386 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
339 echo "GIT NEW clone -->" 387 echo "GIT NEW clone -->"
340 echo " repository: ${EGIT_REPO_URI_SELECTED}" 388 echo " repository: ${EGIT_REPO_URI_SELECTED}"
341 echo " at the commit: ${cursha}" 389 echo " at the commit: ${cursha}"
342 390
343 popd > /dev/null 391 popd > /dev/null
344 elif [[ -n ${EVCS_OFFLINE} ]]; then 392 elif [[ ${EVCS_OFFLINE} ]]; then
345 pushd "${EGIT_DIR}" > /dev/null 393 pushd "${EGIT_DIR}" > /dev/null
346 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 394 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
347 echo "GIT offline update -->" 395 echo "GIT offline update -->"
348 echo " repository: $(git config remote.origin.url)" 396 echo " repository: $(git config remote.origin.url)"
349 echo " at the commit: ${cursha}" 397 echo " at the commit: ${cursha}"
356 404
357 # fetch updates 405 # fetch updates
358 echo "GIT update -->" 406 echo "GIT update -->"
359 echo " repository: ${EGIT_REPO_URI_SELECTED}" 407 echo " repository: ${EGIT_REPO_URI_SELECTED}"
360 # write out message based on the revisions 408 # write out message based on the revisions
361 if [[ "${oldsha1}" != "${cursha1}" ]]; then 409 if [[ "${oldsha}" != "${cursha}" ]]; then
362 echo " updating from commit: ${oldsha}" 410 echo " updating from commit: ${oldsha}"
363 echo " to commit: ${cursha}" 411 echo " to commit: ${cursha}"
364 else 412 else
365 echo " at the commit: ${cursha}" 413 echo " at the commit: ${cursha}"
366 fi 414 fi
368 # print nice statistic of what was changed 416 # print nice statistic of what was changed
369 git --no-pager diff --stat ${oldsha}..${UPSTREAM_BRANCH} 417 git --no-pager diff --stat ${oldsha}..${UPSTREAM_BRANCH}
370 popd > /dev/null 418 popd > /dev/null
371 fi 419 fi
372 # export the version the repository is at 420 # export the version the repository is at
373 export EGIT_VERSION="${cursha1}" 421 export EGIT_VERSION="${cursha}"
374 # log the repo state 422 # log the repo state
375 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \ 423 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
376 && echo " commit: ${EGIT_COMMIT}" 424 && echo " commit: ${EGIT_COMMIT}"
377 echo " branch: ${EGIT_BRANCH}" 425 echo " branch: ${EGIT_BRANCH}"
378 echo " storage directory: \"${EGIT_DIR}\"" 426 echo " storage directory: \"${EGIT_DIR}\""
379 echo " checkout type: ${repo_type}" 427 echo " checkout type: ${repo_type}"
428
429 # Cleanup after git.eclass
430 if [[ ${EGIT_OLD_CLONE} ]]; then
431 einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
432 rm -rf "${EGIT_OLD_CLONE}"
433 fi
380} 434}
381 435
382# @FUNCTION: git_bootstrap 436# @FUNCTION: git_bootstrap
437# @INTERNAL
383# @DESCRIPTION: 438# @DESCRIPTION:
384# Internal function that runs bootstrap command on unpacked source. 439# Internal function that runs bootstrap command on unpacked source.
385git-2_bootstrap() { 440git-2_bootstrap() {
386 debug-print-function ${FUNCNAME} "$@" 441 debug-print-function ${FUNCNAME} "$@"
387 442
388 # @ECLASS_VARIABLE: EGIT_BOOTSTRAP 443 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
389 # @DESCRIPTION: 444 # @DESCRIPTION:
390 # Command to be executed after checkout and clone of the specified 445 # Command to be executed after checkout and clone of the specified
391 # repository. 446 # repository.
392 # enviroment the package will fail if there is no update, thus in 447 # enviroment the package will fail if there is no update, thus in
393 # combination with --keep-going it would lead in not-updating 448 # combination with --keep-going it would lead in not-updating
394 # pakcages that are up-to-date. 449 # pakcages that are up-to-date.
395 if [[ -n ${EGIT_BOOTSTRAP} ]]; then 450 if [[ ${EGIT_BOOTSTRAP} ]]; then
396 pushd "${EGIT_SOURCEDIR}" > /dev/null 451 pushd "${EGIT_SOURCEDIR}" > /dev/null
397 einfo "Starting bootstrap" 452 einfo "Starting bootstrap"
398 453
399 if [[ -f ${EGIT_BOOTSTRAP} ]]; then 454 if [[ -f ${EGIT_BOOTSTRAP} ]]; then
400 # we have file in the repo which we should execute 455 # we have file in the repo which we should execute
420 popd > /dev/null 475 popd > /dev/null
421 fi 476 fi
422} 477}
423 478
424# @FUNCTION: git-2_migrate_repository 479# @FUNCTION: git-2_migrate_repository
480# @INTERNAL
425# @DESCRIPTION: 481# @DESCRIPTION:
426# Internal function migrating between bare and normal checkout repository. 482# Internal function migrating between bare and normal checkout repository.
427# This is based on usage of EGIT_SUBMODULES, at least until they 483# This is based on usage of EGIT_SUBMODULES, at least until they
428# start to work with bare checkouts sanely. 484# start to work with bare checkouts sanely.
485# This function also set some global variables that differ between
486# bare and non-bare checkout.
429git-2_migrate_repository() { 487git-2_migrate_repository() {
430 debug-print-function ${FUNCNAME} "$@" 488 debug-print-function ${FUNCNAME} "$@"
431 489
432 local target returnstate 490 local bare returnstate
433 491
434 # first find out if we have submodules 492 # first find out if we have submodules
493 # or user explicitly wants us to use non-bare clones
435 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 494 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
436 target="bare" 495 bare=1
437 else
438 target="full"
439 fi 496 fi
440 [[ -n ${EGIT_NONBARE} ]] && target="full"
441 497
442 # test if we already have some repo and if so find out if we have 498 # test if we already have some repo and if so find out if we have
443 # to migrate the data 499 # to migrate the data
444 if [[ -d ${EGIT_DIR} ]]; then 500 if [[ -d ${EGIT_DIR} ]]; then
445 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 501 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
446 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 502 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
447 503
448 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 504 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
449 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 505 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
450 export GIT_DIR="${EGIT_DIR}.bare" 506 export GIT_DIR="${EGIT_DIR}.bare"
452 returnstate=$? 508 returnstate=$?
453 unset GIT_DIR 509 unset GIT_DIR
454 rm -rf "${EGIT_DIR}" 510 rm -rf "${EGIT_DIR}"
455 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 511 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
456 eend ${returnstate} 512 eend ${returnstate}
457 fi
458 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 513 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
459 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 514 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
460 515
461 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 516 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
462 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 517 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
463 returnstate=$? 518 returnstate=$?
473 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 528 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
474 rm -rf "${EGIT_DIR}" 529 rm -rf "${EGIT_DIR}"
475 fi 530 fi
476 531
477 # set various options to work with both targets 532 # set various options to work with both targets
478 if [[ ${target} == bare ]]; then 533 if [[ ${bare} ]]; then
479 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 534 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
480 EGIT_OPTIONS+=" --bare" 535 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
481 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 536 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
482 EGIT_UPDATE_CMD="git fetch -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 537 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
483 UPSTREAM_BRANCH="${EGIT_BRANCH}" 538 UPSTREAM_BRANCH="${EGIT_BRANCH}"
539 EGIT_LOCAL_NONBARE=
484 else 540 else
485 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 541 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
486 MOVE_COMMAND="cp -pPR ." 542 MOVE_COMMAND="cp -pPR ."
543 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
487 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 544 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
488 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 545 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
489 EGIT_NONBARE="true" 546 EGIT_LOCAL_NONBARE="true"
490 fi 547 fi
548}
549
550# @FUNCTION: git-2_cleanup
551# @INTERNAL
552# @DESCRIPTION:
553# Internal function cleaning up all the global variables
554# that are not required after the unpack has been done.
555git-2_cleanup() {
556 debug-print-function ${FUNCNAME} "$@"
557
558 # Here we can unset only variables that are GLOBAL
559 # defined by the eclass, BUT NOT subject to change
560 # by user (like EGIT_PROJECT).
561 # If ebuild writer polutes his environment it is
562 # his problem only.
563 unset EGIT_DIR
564 unset MOVE_COMMAND
565 unset EGIT_LOCAL_OPTIONS
566 unset EGIT_UPDATE_CMD
567 unset UPSTREAM_BRANCH
568 unset EGIT_LOCAL_NONBARE
491} 569}
492 570
493# @FUNCTION: git-2_src_unpack 571# @FUNCTION: git-2_src_unpack
494# @DESCRIPTION: 572# @DESCRIPTION:
495# Default git src_upack function. 573# Default git src_unpack function.
496git-2_src_unpack() { 574git-2_src_unpack() {
497 debug-print-function ${FUNCNAME} "$@" 575 debug-print-function ${FUNCNAME} "$@"
498 576
499 git-2_init_variables 577 git-2_init_variables
500 git-2_prepare_storedir 578 git-2_prepare_storedir
503 git-2_gc 581 git-2_gc
504 git-2_submodules 582 git-2_submodules
505 git-2_move_source 583 git-2_move_source
506 git-2_branch 584 git-2_branch
507 git-2_bootstrap 585 git-2_bootstrap
586 git-2_cleanup
508 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 587 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
588
589 # Users can specify some SRC_URI and we should
590 # unpack the files too.
591 if [[ ! ${EGIT_NOUNPACK} ]]; then
592 if has ${EAPI:-0} 0 1; then
593 [[ ${A} ]] && unpack ${A}
594 else
595 default_src_unpack
596 fi
597 fi
509} 598}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.20