Gentoo Archives: gentoo-commits

From: "Michal Gorny (mgorny)" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: ChangeLog git-r3.eclass
Date: Sun, 23 Feb 2014 22:06:00
Message-Id: 20140223220555.AD3322004C@flycatcher.gentoo.org
1 mgorny 14/02/23 22:05:55
2
3 Modified: ChangeLog git-r3.eclass
4 Log:
5 Use complete git clones, and clone them onto the checkout directory. This makes it possible for build system to lookup all repository information as requested in bug #489100. Remove shallow clone support since it would require too much effort and make code hard to understand. Additionally obsoletes bug #489100 and git-r3 part of bug #494934.
6
7 Revision Changes Path
8 1.1146 eclass/ChangeLog
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1146&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1146&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?r1=1.1145&r2=1.1146
13
14 Index: ChangeLog
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v
17 retrieving revision 1.1145
18 retrieving revision 1.1146
19 diff -u -r1.1145 -r1.1146
20 --- ChangeLog 22 Feb 2014 17:01:58 -0000 1.1145
21 +++ ChangeLog 23 Feb 2014 22:05:55 -0000 1.1146
22 @@ -1,6 +1,13 @@
23 # ChangeLog for eclass directory
24 # Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2
25 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1145 2014/02/22 17:01:58 floppym Exp $
26 +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1146 2014/02/23 22:05:55 mgorny Exp $
27 +
28 + 23 Feb 2014; Michał Górny <mgorny@g.o> git-r3.eclass:
29 + Use complete git clones, and clone them onto the checkout directory. This
30 + makes it possible for build system to lookup all repository information as
31 + requested in bug #489100. Remove shallow clone support since it would require
32 + too much effort and make code hard to understand. Additionally obsoletes bug
33 + #489100 and git-r3 part of bug #494934.
34
35 22 Feb 2014; Mike Gilbert <floppym@g.o> python-utils-r1.eclass:
36 Add support for python3.4.
37
38
39
40 1.24 eclass/git-r3.eclass
41
42 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.24&view=markup
43 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.24&content-type=text/plain
44 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?r1=1.23&r2=1.24
45
46 Index: git-r3.eclass
47 ===================================================================
48 RCS file: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v
49 retrieving revision 1.23
50 retrieving revision 1.24
51 diff -u -r1.23 -r1.24
52 --- git-r3.eclass 15 Nov 2013 23:03:23 -0000 1.23
53 +++ git-r3.eclass 23 Feb 2014 22:05:55 -0000 1.24
54 @@ -1,6 +1,6 @@
55 -# Copyright 1999-2013 Gentoo Foundation
56 +# Copyright 1999-2014 Gentoo Foundation
57 # Distributed under the terms of the GNU General Public License v2
58 -# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.23 2013/11/15 23:03:23 mgorny Exp $
59 +# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.24 2014/02/23 22:05:55 mgorny Exp $
60
61 # @ECLASS: git-r3.eclass
62 # @MAINTAINER:
63 @@ -8,8 +8,7 @@
64 # @BLURB: Eclass for fetching and unpacking git repositories.
65 # @DESCRIPTION:
66 # Third generation eclass for easing maitenance of live ebuilds using
67 -# git as remote repository. The eclass supports lightweight (shallow)
68 -# clones and bare clones of submodules.
69 +# git as remote repository.
70
71 case "${EAPI:-0}" in
72 0|1|2|3|4|5)
73 @@ -30,7 +29,7 @@
74 if [[ ! ${_GIT_R3} ]]; then
75
76 if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
77 - DEPEND=">=dev-vcs/git-1.8.2.1"
78 + DEPEND="dev-vcs/git"
79 fi
80
81 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
82 @@ -83,18 +82,6 @@
83 #
84 # EGIT_CHECKOUT_DIR=${WORKDIR}/${P}
85
86 -# @ECLASS-VARIABLE: EGIT_NONSHALLOW
87 -# @DEFAULT_UNSET
88 -# @DESCRIPTION:
89 -# Disable performing shallow fetches/clones. Shallow clones have
90 -# a fair number of limitations. Therefore, if you'd like the eclass to
91 -# perform complete clones instead, set this to a non-null value.
92 -#
93 -# This variable can be set in make.conf and ebuilds. The make.conf
94 -# value specifies user-specific default, while ebuilds may use it
95 -# to force deep clones when the server does not support shallow clones
96 -# (e.g. Google Code).
97 -
98 # @FUNCTION: _git-r3_env_setup
99 # @INTERNAL
100 # @DESCRIPTION:
101 @@ -217,14 +204,13 @@
102 fi
103
104 addwrite "${EGIT3_STORE_DIR}"
105 + if [[ -e ${GIT_DIR}/shallow ]]; then
106 + einfo "${GIT_DIR} was a shallow clone, recreating..."
107 + rm -r "${GIT_DIR}" || die
108 + fi
109 if [[ ! -d ${GIT_DIR} ]]; then
110 mkdir "${GIT_DIR}" || die
111 git init --bare || die
112 -
113 - if [[ ! ${EGIT_NONSHALLOW} ]]; then
114 - # avoid auto-unshallow :)
115 - touch "${GIT_DIR}"/shallow || die
116 - fi
117 fi
118 }
119
120 @@ -267,93 +253,6 @@
121 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
122 }
123
124 -# @FUNCTION: _git-r3_smart_fetch
125 -# @USAGE: <git-fetch-args>...
126 -# @DESCRIPTION:
127 -# Try fetching without '--depth' and switch to '--depth 1' if that
128 -# will involve less objects fetched.
129 -_git-r3_smart_fetch() {
130 - debug-print-function ${FUNCNAME} "$@"
131 -
132 - local sed_regexp='.*Counting objects: \([0-9]*\), done\..*'
133 -
134 - # start the main fetch
135 - local cmd=( git fetch --progress "${@}" )
136 - echo "${cmd[@]}" >&2
137 -
138 - # we copy the output to the 'sed' pipe for parsing. whenever sed finds
139 - # the process count, it quits quickly to avoid delays in writing it.
140 - # then, we start a dummy 'cat' to keep the pipe alive
141 -
142 - "${cmd[@]}" 2>&1 \
143 - | tee >(
144 - sed -n -e "/${sed_regexp}/{s/${sed_regexp}/\1/p;q}" \
145 - > "${T}"/git-r3_main.count
146 - exec cat >/dev/null
147 - ) &
148 - local main_pid=${!}
149 -
150 - # start the helper process
151 - _git-r3_sub_fetch() {
152 - # wait for main fetch to get object count; if the server doesn't
153 - # output it, we won't even launch the parallel process
154 - while [[ ! -s ${T}/git-r3_main.count ]]; do
155 - sleep 0.25
156 - done
157 -
158 - # ok, let's see if parallel fetch gives us smaller count
159 - # --dry-run will prevent it from writing to the local clone
160 - # and sed should terminate git with SIGPIPE
161 - local sub_count=$(git fetch --progress --dry-run --depth 1 "${@}" 2>&1 \
162 - | sed -n -e "/${sed_regexp}/{s/${sed_regexp}/\1/p;q}")
163 - local main_count=$(<"${T}"/git-r3_main.count)
164 -
165 - # let's be real sure that '--depth 1' will be good for us.
166 - # note that we have purely objects counts, and '--depth 1'
167 - # may involve much bigger objects
168 - if [[ ${main_count} && ${main_count} -ge $(( sub_count * 3/2 )) ]]
169 - then
170 - # signal that we want shallow fetch instead,
171 - # and terminate the non-shallow fetch process
172 - touch "${T}"/git-r3_want_shallow || die
173 - kill ${main_pid} &>/dev/null
174 - exit 0
175 - fi
176 -
177 - exit 1
178 - }
179 - _git-r3_sub_fetch "${@}" &
180 - local sub_pid=${!}
181 -
182 - # wait for main process to terminate, either of its own
183 - # or by signal from subprocess
184 - wait ${main_pid}
185 - local main_ret=${?}
186 -
187 - # wait for subprocess to terminate, killing it if necessary.
188 - # if main fetch finished before it, there's no point in keeping
189 - # it alive. if main fetch was killed by it, it's done anyway
190 - kill ${sub_pid} &>/dev/null
191 - wait ${sub_pid}
192 -
193 - # now see if subprocess wanted to tell us something...
194 - if [[ -f ${T}/git-r3_want_shallow ]]; then
195 - rm "${T}"/git-r3_want_shallow || die
196 -
197 - # if fetch finished already (wasn't killed), ignore it
198 - [[ ${main_ret} -eq 0 ]] && return 0
199 -
200 - # otherwise, restart as shallow fetch
201 - einfo "Restarting fetch using --depth 1 to save bandwidth ..."
202 - local cmd=( git fetch --progress --depth 1 "${@}" )
203 - echo "${cmd[@]}" >&2
204 - "${cmd[@]}"
205 - main_ret=${?}
206 - fi
207 -
208 - return ${main_ret}
209 -}
210 -
211 # @FUNCTION: _git-r3_is_local_repo
212 # @USAGE: <repo-uri>
213 # @INTERNAL
214 @@ -413,7 +312,7 @@
215 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
216 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
217 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
218 - local local_ref=refs/heads/${local_id}/__main__
219 + local local_ref=refs/git-r3/${local_id}/__main__
220
221 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
222
223 @@ -423,93 +322,36 @@
224 # try to fetch from the remote
225 local r success
226 for r in "${repos[@]}"; do
227 - einfo "Fetching ${remote_ref} from ${r} ..."
228 -
229 - local is_branch lookup_ref
230 - if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
231 - then
232 - is_branch=1
233 - lookup_ref=${remote_ref}
234 - else
235 - # ls-remote by commit is going to fail anyway,
236 - # so we may as well pass refs/tags/ABCDEF...
237 - lookup_ref=refs/tags/${remote_ref}
238 - fi
239 + einfo "Fetching ${r} ..."
240
241 - # first, try ls-remote to see if ${remote_ref} is a real ref
242 - # and not a commit id. if it succeeds, we can pass ${remote_ref}
243 - # to 'fetch'. otherwise, we will just fetch everything
244 -
245 - # split on whitespace
246 - local ref=(
247 - $(git ls-remote "${r}" "${lookup_ref}" || echo __FAIL__)
248 + local fetch_command=(
249 + git fetch --prune "${r}"
250 + # mirror the remote branches as local branches
251 + "refs/heads/*:refs/heads/*"
252 + # pull tags explicitly in order to prune them properly
253 + "refs/tags/*:refs/tags/*"
254 )
255
256 - # normally, ref[0] is a hash, so we can do magic strings here
257 - [[ ${ref[0]} == __FAIL__ ]] && continue
258 -
259 - local nonshallow=${EGIT_NONSHALLOW}
260 - local ref_param=()
261 - if [[ ! ${ref[0]} ]]; then
262 - nonshallow=1
263 - fi
264 -
265 - # trying to do a shallow clone of a local repo makes git try to
266 - # write to the repo. we don't want that to happen.
267 - _git-r3_is_local_repo "${r}" && nonshallow=1
268 -
269 - # 1. if we need a non-shallow clone and we have a shallow one,
270 - # we need to unshallow it explicitly.
271 - # 2. if we want a shallow clone, we just pass '--depth 1'
272 - # to the first fetch in the repo. passing '--depth'
273 - # to further requests usually results in more data being
274 - # downloaded than without it.
275 - # 3. if we update a shallow clone, we try without '--depth'
276 - # first since that usually transfers less data. however,
277 - # we use git-r3_smart_fetch that can switch into '--depth 1'
278 - # if that looks beneficial.
279 -
280 - local fetch_command=( git fetch )
281 - if [[ ${nonshallow} ]]; then
282 - if [[ -f ${GIT_DIR}/shallow ]]; then
283 - ref_param+=( --unshallow )
284 - fi
285 - # fetch all branches
286 - ref_param+=( "refs/heads/*:refs/remotes/origin/*" )
287 - else
288 - # 'git show-ref --heads' returns 1 when there are no branches
289 - if ! git show-ref --heads -q; then
290 - ref_param+=( --depth 1 )
291 + set -- "${fetch_command[@]}"
292 + echo "${@}" >&2
293 + if "${@}"; then
294 + # now let's see what the user wants from us
295 + local full_remote_ref=$(
296 + git rev-parse --verify --symbolic-full-name "${remote_ref}"
297 + )
298 +
299 + if [[ ${full_remote_ref} ]]; then
300 + # when we are given a ref, create a symbolic ref
301 + # so that we preserve the actual argument
302 + set -- git symbolic-ref "${local_ref}" "${full_remote_ref}"
303 else
304 - fetch_command=( _git-r3_smart_fetch )
305 + # otherwise, we were likely given a commit id
306 + set -- git update-ref --no-deref "${local_ref}" "${remote_ref}"
307 fi
308 - fi
309 -
310 - # now, another important thing. we may only fetch a remote
311 - # branch directly to a local branch. Otherwise, we need to fetch
312 - # the commit and re-create the branch on top of it.
313
314 - if [[ ${ref[0]} ]]; then
315 - if [[ ${is_branch} ]]; then
316 - ref_param+=( -f "${remote_ref}:${local_id}/__main__" )
317 - else
318 - ref_param+=( "refs/tags/${remote_ref}" )
319 - fi
320 - fi
321 -
322 - # if ${remote_ref} is branch or tag, ${ref[@]} will contain
323 - # the respective commit id. otherwise, it will be an empty
324 - # array, so the following won't evaluate to a parameter.
325 - set -- "${fetch_command[@]}" --no-tags "${r}" "${ref_param[@]}"
326 - echo "${@}" >&2
327 - if "${@}"; then
328 - if [[ ! ${is_branch} ]]; then
329 - set -- git branch -f "${local_id}/__main__" \
330 - "${ref[0]:-${remote_ref}}"
331 - echo "${@}" >&2
332 - if ! "${@}"; then
333 - die "Creating branch for ${remote_ref} failed (wrong ref?)."
334 - fi
335 + echo "${@}" >&2
336 + if ! "${@}"; then
337 + die "Referencing ${remote_ref} failed (wrong ref?)."
338 fi
339
340 success=1
341 @@ -581,53 +423,53 @@
342 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
343 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
344
345 - local -x GIT_DIR GIT_WORK_TREE
346 + local -x GIT_DIR
347 _git-r3_set_gitdir "${repos[0]}"
348 - GIT_WORK_TREE=${out_dir}
349 - mkdir -p "${GIT_WORK_TREE}" || die
350
351 einfo "Checking out ${repos[0]} to ${out_dir} ..."
352
353 - if ! git cat-file -e refs/heads/"${local_id}"/__main__
354 - then
355 + if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
356 if [[ ${EVCS_OFFLINE} ]]; then
357 die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE."
358 else
359 die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?"
360 fi
361 fi
362 + local remote_ref=$(
363 + git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__
364 + )
365 + local new_commit_id=$(
366 + git rev-parse --verify refs/git-r3/"${local_id}"/__main__
367 + )
368
369 - # Note: this is a hack to avoid parallel checkout issues.
370 - # I will try to handle it without locks when I have more time.
371 - local lockfile=${GIT_DIR}/.git-r3_checkout_lock
372 - local lockfile_l=${lockfile}.${BASHPID}
373 - touch "${lockfile_l}" || die
374 - until ln "${lockfile_l}" "${lockfile}" &>/dev/null; do
375 - sleep 1
376 - done
377 - rm "${lockfile_l}" || die
378 -
379 - set -- git checkout -f "${local_id}"/__main__ .
380 + set -- git clone --quiet --shared --no-checkout "${GIT_DIR}" "${out_dir}"/
381 echo "${@}" >&2
382 - "${@}"
383 - local ret=${?}
384 + "${@}" || die "git clone (for checkout) failed"
385
386 - # Remove the lock!
387 - rm "${lockfile}" || die
388 -
389 - [[ ${ret} == 0 ]] || die "git checkout ${local_id}/__main__ failed"
390 + git-r3_sub_checkout() {
391 + local -x GIT_DIR=${out_dir}/.git
392 + local -x GIT_WORK_TREE=${out_dir}
393 +
394 + set -- git checkout --quiet
395 + if [[ ${remote_ref} ]]; then
396 + set -- "${@}" "${remote_ref#refs/heads/}"
397 + else
398 + set -- "${@}" "${new_commit_id}"
399 + fi
400 + echo "${@}" >&2
401 + "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed"
402 + }
403 + git-r3_sub_checkout
404
405 - # diff against previous revision (if any)
406 - local new_commit_id=$(git rev-parse --verify "${local_id}"/__main__)
407 local old_commit_id=$(
408 - git rev-parse --verify "${local_id}"/__old__ 2>/dev/null
409 + git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__
410 )
411 -
412 if [[ ! ${old_commit_id} ]]; then
413 echo "GIT NEW branch -->"
414 echo " repository: ${repos[0]}"
415 echo " at the commit: ${new_commit_id}"
416 else
417 + # diff against previous revision
418 echo "GIT update -->"
419 echo " repository: ${repos[0]}"
420 # write out message based on the revisions
421 @@ -641,13 +483,13 @@
422 echo " at the commit: ${new_commit_id}"
423 fi
424 fi
425 - git branch -f "${local_id}"/{__old__,__main__} || die
426 + git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die
427
428 # recursively checkout submodules
429 - if [[ -f ${GIT_WORK_TREE}/.gitmodules ]]; then
430 + if [[ -f ${out_dir}/.gitmodules ]]; then
431 local submodules
432 _git-r3_set_submodules \
433 - "$(<"${GIT_WORK_TREE}"/.gitmodules)"
434 + "$(<"${out_dir}"/.gitmodules)"
435
436 while [[ ${submodules[@]} ]]; do
437 local subname=${submodules[0]}
438 @@ -658,7 +500,7 @@
439 url=${repos[0]%%/}/${url}
440 fi
441
442 - git-r3_checkout "${url}" "${GIT_WORK_TREE}/${path}" \
443 + git-r3_checkout "${url}" "${out_dir}/${path}" \
444 "${local_id}/${subname}"
445
446 submodules=( "${submodules[@]:3}" ) # shift
447 @@ -668,11 +510,6 @@
448 # keep this *after* submodules
449 export EGIT_DIR=${GIT_DIR}
450 export EGIT_VERSION=${new_commit_id}
451 -
452 - # create a fake '.git' directory to satisfy 'git rev-parse HEAD'
453 - GIT_DIR=${GIT_WORK_TREE}/.git
454 - git init || die
455 - echo "${EGIT_VERSION}" > "${GIT_WORK_TREE}"/.git/HEAD || die
456 }
457
458 # @FUNCTION: git-r3_peek_remote_ref