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

Contents of /eclass/git-r3.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (show annotations) (download)
Sun Mar 2 11:46:15 2014 UTC (12 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.28: +43 -1 lines
Fix support for non-master default branch.

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.28 2014/03/02 11:45:41 mgorny Exp $
4
5 # @ECLASS: git-r3.eclass
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # @BLURB: Eclass for fetching and unpacking git repositories.
9 # @DESCRIPTION:
10 # Third generation eclass for easing maitenance of live ebuilds using
11 # git as remote repository.
12
13 case "${EAPI:-0}" in
14 0|1|2|3|4|5)
15 ;;
16 *)
17 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
18 ;;
19 esac
20
21 if [[ ! ${_GIT_R3} ]]; then
22
23 inherit eutils
24
25 fi
26
27 EXPORT_FUNCTIONS src_unpack
28
29 if [[ ! ${_GIT_R3} ]]; then
30
31 if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
32 DEPEND="dev-vcs/git"
33 fi
34
35 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
36 # @DESCRIPTION:
37 # Storage directory for git sources.
38 #
39 # This is intended to be set by user in make.conf. Ebuilds must not set
40 # it.
41 #
42 # EGIT3_STORE_DIR=${DISTDIR}/git3-src
43
44 # @ECLASS-VARIABLE: EGIT_REPO_URI
45 # @REQUIRED
46 # @DESCRIPTION:
47 # URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
48 # are provided, the eclass will consider them as fallback URIs to try
49 # if the first URI does not work.
50 #
51 # It can be overriden via env using ${PN}_LIVE_REPO variable.
52 #
53 # Can be a whitespace-separated list or an array.
54 #
55 # Example:
56 # @CODE
57 # EGIT_REPO_URI="git://a/b.git https://c/d.git"
58 # @CODE
59
60 # @ECLASS-VARIABLE: EVCS_OFFLINE
61 # @DEFAULT_UNSET
62 # @DESCRIPTION:
63 # If non-empty, this variable prevents any online operations.
64
65 # @ECLASS-VARIABLE: EGIT_BRANCH
66 # @DEFAULT_UNSET
67 # @DESCRIPTION:
68 # The branch name to check out. If unset, the upstream default (HEAD)
69 # will be used.
70 #
71 # It can be overriden via env using ${PN}_LIVE_BRANCH variable.
72
73 # @ECLASS-VARIABLE: EGIT_COMMIT
74 # @DEFAULT_UNSET
75 # @DESCRIPTION:
76 # The tag name or commit identifier to check out. If unset, newest
77 # commit from the branch will be used. If set, EGIT_BRANCH will
78 # be ignored.
79 #
80 # It can be overriden via env using ${PN}_LIVE_COMMIT variable.
81
82 # @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR
83 # @DESCRIPTION:
84 # The directory to check the git sources out to.
85 #
86 # EGIT_CHECKOUT_DIR=${WORKDIR}/${P}
87
88 # @FUNCTION: _git-r3_env_setup
89 # @INTERNAL
90 # @DESCRIPTION:
91 # Set the eclass variables as necessary for operation. This can involve
92 # setting EGIT_* to defaults or ${PN}_LIVE_* variables.
93 _git-r3_env_setup() {
94 debug-print-function ${FUNCNAME} "$@"
95
96 local esc_pn livevar
97 esc_pn=${PN//[-+]/_}
98
99 livevar=${esc_pn}_LIVE_REPO
100 EGIT_REPO_URI=${!livevar:-${EGIT_REPO_URI}}
101 [[ ${!livevar} ]] \
102 && ewarn "Using ${livevar}, no support will be provided"
103
104 livevar=${esc_pn}_LIVE_BRANCH
105 EGIT_BRANCH=${!livevar:-${EGIT_BRANCH}}
106 [[ ${!livevar} ]] \
107 && ewarn "Using ${livevar}, no support will be provided"
108
109 livevar=${esc_pn}_LIVE_COMMIT
110 EGIT_COMMIT=${!livevar:-${EGIT_COMMIT}}
111 [[ ${!livevar} ]] \
112 && ewarn "Using ${livevar}, no support will be provided"
113
114 # Migration helpers. Remove them when git-2 is removed.
115
116 if [[ ${EGIT_SOURCEDIR} ]]; then
117 eerror "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR. While updating"
118 eerror "your ebuild, please check whether the variable is necessary at all"
119 eerror "since the default has been changed from \${S} to \${WORKDIR}/\${P}."
120 eerror "Therefore, proper setting of S may be sufficient."
121 die "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR."
122 fi
123
124 if [[ ${EGIT_MASTER} ]]; then
125 eerror "EGIT_MASTER has been removed. Instead, the upstream default (HEAD)"
126 eerror "is used by the eclass. Please remove the assignment or use EGIT_BRANCH"
127 eerror "as necessary."
128 die "EGIT_MASTER has been removed."
129 fi
130
131 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
132 eerror "EGIT_HAS_SUBMODULES has been removed. The eclass no longer needs"
133 eerror "to switch the clone type in order to support submodules and therefore"
134 eerror "submodules are detected and fetched automatically."
135 die "EGIT_HAS_SUBMODULES is no longer necessary."
136 fi
137
138 if [[ ${EGIT_PROJECT} ]]; then
139 eerror "EGIT_PROJECT has been removed. Instead, the eclass determines"
140 eerror "the local clone path using path in canonical EGIT_REPO_URI."
141 eerror "If the current algorithm causes issues for you, please report a bug."
142 die "EGIT_PROJECT is no longer necessary."
143 fi
144
145 if [[ ${EGIT_BOOTSTRAP} ]]; then
146 eerror "EGIT_BOOTSTRAP has been removed. Please create proper src_prepare()"
147 eerror "instead."
148 die "EGIT_BOOTSTRAP has been removed."
149 fi
150
151 if [[ ${EGIT_NOUNPACK} ]]; then
152 eerror "EGIT_NOUNPACK has been removed. The eclass no longer calls default"
153 eerror "unpack function. If necessary, please declare proper src_unpack()."
154 die "EGIT_NOUNPACK has been removed."
155 fi
156 }
157
158 # @FUNCTION: _git-r3_set_gitdir
159 # @USAGE: <repo-uri>
160 # @INTERNAL
161 # @DESCRIPTION:
162 # Obtain the local repository path and set it as GIT_DIR. Creates
163 # a new repository if necessary.
164 #
165 # <repo-uri> may be used to compose the path. It should therefore be
166 # a canonical URI to the repository.
167 _git-r3_set_gitdir() {
168 debug-print-function ${FUNCNAME} "$@"
169
170 local repo_name=${1#*://*/}
171
172 # strip the trailing slash
173 repo_name=${repo_name%/}
174
175 # strip common prefixes to make paths more likely to match
176 # e.g. git://X/Y.git vs https://X/git/Y.git
177 # (but just one of the prefixes)
178 case "${repo_name}" in
179 # gnome.org... who else?
180 browse/*) repo_name=${repo_name#browse/};;
181 # cgit can proxy requests to git
182 cgit/*) repo_name=${repo_name#cgit/};;
183 # pretty common
184 git/*) repo_name=${repo_name#git/};;
185 # gentoo.org
186 gitroot/*) repo_name=${repo_name#gitroot/};;
187 # google code, sourceforge
188 p/*) repo_name=${repo_name#p/};;
189 # kernel.org
190 pub/scm/*) repo_name=${repo_name#pub/scm/};;
191 esac
192 # ensure a .git suffix, same reason
193 repo_name=${repo_name%.git}.git
194 # now replace all the slashes
195 repo_name=${repo_name//\//_}
196
197 local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
198 : ${EGIT3_STORE_DIR:=${distdir}/git3-src}
199
200 GIT_DIR=${EGIT3_STORE_DIR}/${repo_name}
201
202 if [[ ! -d ${EGIT3_STORE_DIR} ]]; then
203 (
204 addwrite /
205 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die
206 ) || die "Unable to create ${EGIT3_STORE_DIR}"
207 fi
208
209 addwrite "${EGIT3_STORE_DIR}"
210 if [[ -e ${GIT_DIR}/shallow ]]; then
211 einfo "${GIT_DIR} was a shallow clone, recreating..."
212 rm -r "${GIT_DIR}" || die
213 fi
214 if [[ ! -d ${GIT_DIR} ]]; then
215 mkdir "${GIT_DIR}" || die
216 git init --bare || die
217 fi
218 }
219
220 # @FUNCTION: _git-r3_set_submodules
221 # @USAGE: <file-contents>
222 # @INTERNAL
223 # @DESCRIPTION:
224 # Parse .gitmodules contents passed as <file-contents>
225 # as in "$(cat .gitmodules)"). Composes a 'submodules' array that
226 # contains in order (name, URL, path) for each submodule.
227 _git-r3_set_submodules() {
228 debug-print-function ${FUNCNAME} "$@"
229
230 local data=${1}
231
232 # ( name url path ... )
233 submodules=()
234
235 local l
236 while read l; do
237 # submodule.<path>.path=<path>
238 # submodule.<path>.url=<url>
239 [[ ${l} == submodule.*.url=* ]] || continue
240
241 l=${l#submodule.}
242 local subname=${l%%.url=*}
243
244 # skip modules that have 'update = none', bug #487262.
245 local upd=$(echo "${data}" | git config -f /dev/fd/0 \
246 submodule."${subname}".update)
247 [[ ${upd} == none ]] && continue
248
249 submodules+=(
250 "${subname}"
251 "$(echo "${data}" | git config -f /dev/fd/0 \
252 submodule."${subname}".url || die)"
253 "$(echo "${data}" | git config -f /dev/fd/0 \
254 submodule."${subname}".path || die)"
255 )
256 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
257 }
258
259 # @FUNCTION: _git-r3_is_local_repo
260 # @USAGE: <repo-uri>
261 # @INTERNAL
262 # @DESCRIPTION:
263 # Determine whether the given URI specifies a local (on-disk)
264 # repository.
265 _git-r3_is_local_repo() {
266 debug-print-function ${FUNCNAME} "$@"
267
268 local uri=${1}
269
270 [[ ${uri} == file://* || ${uri} == /* ]]
271 }
272
273 # @FUNCTION: _git-r3_update_head
274 # @USAGE: <remote-head-ref>
275 # @INTERNAL
276 # @DESCRIPTION:
277 # Given a ref to which remote HEAD was fetched, try to match
278 # a local branch and update symbolic HEAD appropriately.
279 _git-r3_update_head()
280 {
281 debug-print-function ${FUNCNAME} "$@"
282
283 local head_ref=${1}
284 local head_hash=$(git rev-parse --verify "${1}" || die)
285 local matching_ref
286
287 # TODO: some transports support peeking at symbolic remote refs
288 # find a way to use that rather than guessing
289
290 # (based on guess_remote_head() in git-1.9.0/remote.c)
291 local h ref
292 while read h ref; do
293 # look for matching head
294 if [[ ${h} == ${head_hash} ]]; then
295 # either take the first matching ref, or master if it is there
296 if [[ ! ${matching_ref} || ${ref} == refs/heads/master ]]; then
297 matching_ref=${ref}
298 fi
299 fi
300 done < <(git show-ref --heads || die)
301
302 if [[ ! ${matching_ref} ]]; then
303 die "Unable to find a matching branch for remote HEAD (${head_hash})"
304 fi
305
306 git symbolic-ref HEAD "${matching_ref}" || die
307 }
308
309 # @FUNCTION: git-r3_fetch
310 # @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]]
311 # @DESCRIPTION:
312 # Fetch new commits to the local clone of repository.
313 #
314 # <repo-uri> specifies the repository URIs to fetch from, as a space-
315 # -separated list. The first URI will be used as repository group
316 # identifier and therefore must be used consistently. When not
317 # specified, defaults to ${EGIT_REPO_URI}.
318 #
319 # <remote-ref> specifies the remote ref or commit id to fetch.
320 # It is preferred to use 'refs/heads/<branch-name>' for branches
321 # and 'refs/tags/<tag-name>' for tags. Other options are 'HEAD'
322 # for upstream default branch and hexadecimal commit SHA1. Defaults
323 # to the first of EGIT_COMMIT, EGIT_BRANCH or literal 'HEAD' that
324 # is set to a non-null value.
325 #
326 # <local-id> specifies the local branch identifier that will be used to
327 # locally store the fetch result. It should be unique to multiple
328 # fetches within the repository that can be performed at the same time
329 # (including parallel merges). It defaults to ${CATEGORY}/${PN}/${SLOT%/*}.
330 # This default should be fine unless you are fetching multiple trees
331 # from the same repository in the same ebuild.
332 #
333 # The fetch operation will affect the EGIT_STORE only. It will not touch
334 # the working copy, nor export any environment variables.
335 # If the repository contains submodules, they will be fetched
336 # recursively.
337 git-r3_fetch() {
338 debug-print-function ${FUNCNAME} "$@"
339
340 [[ ${EVCS_OFFLINE} ]] && return
341
342 local repos
343 if [[ ${1} ]]; then
344 repos=( ${1} )
345 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
346 repos=( "${EGIT_REPO_URI[@]}" )
347 else
348 repos=( ${EGIT_REPO_URI} )
349 fi
350
351 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
352 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
353 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
354 local local_ref=refs/git-r3/${local_id}/__main__
355
356 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
357
358 local -x GIT_DIR
359 _git-r3_set_gitdir "${repos[0]}"
360
361 # try to fetch from the remote
362 local r success
363 for r in "${repos[@]}"; do
364 einfo "Fetching ${r} ..."
365
366 local fetch_command=(
367 git fetch --prune "${r}"
368 # mirror the remote branches as local branches
369 "refs/heads/*:refs/heads/*"
370 # pull tags explicitly in order to prune them properly
371 "refs/tags/*:refs/tags/*"
372 # notes in case something needs them
373 "refs/notes/*:refs/notes/*"
374 # and HEAD in case we need the default branch
375 # (we keep it in refs/git-r3 since otherwise --prune interferes)
376 HEAD:refs/git-r3/HEAD
377 )
378
379 set -- "${fetch_command[@]}"
380 echo "${@}" >&2
381 if "${@}"; then
382 # find remote HEAD and update our HEAD properly
383 _git-r3_update_head refs/git-r3/HEAD
384
385 # now let's see what the user wants from us
386 local full_remote_ref=$(
387 git rev-parse --verify --symbolic-full-name "${remote_ref}"
388 )
389
390 if [[ ${full_remote_ref} ]]; then
391 # when we are given a ref, create a symbolic ref
392 # so that we preserve the actual argument
393 set -- git symbolic-ref "${local_ref}" "${full_remote_ref}"
394 else
395 # otherwise, we were likely given a commit id
396 set -- git update-ref --no-deref "${local_ref}" "${remote_ref}"
397 fi
398
399 echo "${@}" >&2
400 if ! "${@}"; then
401 die "Referencing ${remote_ref} failed (wrong ref?)."
402 fi
403
404 success=1
405 break
406 fi
407 done
408 [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
409
410 # recursively fetch submodules
411 if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
412 local submodules
413 _git-r3_set_submodules \
414 "$(git cat-file -p "${local_ref}":.gitmodules || die)"
415
416 while [[ ${submodules[@]} ]]; do
417 local subname=${submodules[0]}
418 local url=${submodules[1]}
419 local path=${submodules[2]}
420 local commit=$(git rev-parse "${local_ref}:${path}")
421
422 if [[ ! ${commit} ]]; then
423 die "Unable to get commit id for submodule ${subname}"
424 fi
425 if [[ ${url} == ./* || ${url} == ../* ]]; then
426 local subrepos=( "${repos[@]/%//${url}}" )
427 else
428 local subrepos=( "${url}" )
429 fi
430
431 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
432
433 submodules=( "${submodules[@]:3}" ) # shift
434 done
435 fi
436 }
437
438 # @FUNCTION: git-r3_checkout
439 # @USAGE: [<repo-uri> [<checkout-path> [<local-id>]]]
440 # @DESCRIPTION:
441 # Check the previously fetched tree to the working copy.
442 #
443 # <repo-uri> specifies the repository URIs, as a space-separated list.
444 # The first URI will be used as repository group identifier
445 # and therefore must be used consistently with git-r3_fetch.
446 # The remaining URIs are not used and therefore may be omitted.
447 # When not specified, defaults to ${EGIT_REPO_URI}.
448 #
449 # <checkout-path> specifies the path to place the checkout. It defaults
450 # to ${EGIT_CHECKOUT_DIR} if set, otherwise to ${WORKDIR}/${P}.
451 #
452 # <local-id> needs to specify the local identifier that was used
453 # for respective git-r3_fetch.
454 #
455 # The checkout operation will write to the working copy, and export
456 # the repository state into the environment. If the repository contains
457 # submodules, they will be checked out recursively.
458 git-r3_checkout() {
459 debug-print-function ${FUNCNAME} "$@"
460
461 local repos
462 if [[ ${1} ]]; then
463 repos=( ${1} )
464 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
465 repos=( "${EGIT_REPO_URI[@]}" )
466 else
467 repos=( ${EGIT_REPO_URI} )
468 fi
469
470 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
471 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
472
473 local -x GIT_DIR
474 _git-r3_set_gitdir "${repos[0]}"
475
476 einfo "Checking out ${repos[0]} to ${out_dir} ..."
477
478 if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
479 if [[ ${EVCS_OFFLINE} ]]; then
480 die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE."
481 else
482 die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?"
483 fi
484 fi
485 local remote_ref=$(
486 git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__
487 )
488 local new_commit_id=$(
489 git rev-parse --verify refs/git-r3/"${local_id}"/__main__
490 )
491
492 git-r3_sub_checkout() {
493 local orig_repo=${GIT_DIR}
494 local -x GIT_DIR=${out_dir}/.git
495 local -x GIT_WORK_TREE=${out_dir}
496
497 mkdir -p "${out_dir}" || die
498
499 # use git init+fetch instead of clone since the latter doesn't like
500 # non-empty directories.
501
502 git init --quiet || die
503 # setup 'alternates' to avoid copying objects
504 echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die
505 # now copy the refs
506 # [htn]* safely catches heads, tags, notes without complaining
507 # on non-existing ones, and omits internal 'git-r3' ref
508 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
509
510 # (no need to copy HEAD, we will set it via checkout)
511
512 set -- git checkout --quiet
513 if [[ ${remote_ref} ]]; then
514 set -- "${@}" "${remote_ref#refs/heads/}"
515 else
516 set -- "${@}" "${new_commit_id}"
517 fi
518 echo "${@}" >&2
519 "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed"
520 }
521 git-r3_sub_checkout
522
523 local old_commit_id=$(
524 git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__
525 )
526 if [[ ! ${old_commit_id} ]]; then
527 echo "GIT NEW branch -->"
528 echo " repository: ${repos[0]}"
529 echo " at the commit: ${new_commit_id}"
530 else
531 # diff against previous revision
532 echo "GIT update -->"
533 echo " repository: ${repos[0]}"
534 # write out message based on the revisions
535 if [[ "${old_commit_id}" != "${new_commit_id}" ]]; then
536 echo " updating from commit: ${old_commit_id}"
537 echo " to commit: ${new_commit_id}"
538
539 git --no-pager diff --stat \
540 ${old_commit_id}..${new_commit_id}
541 else
542 echo " at the commit: ${new_commit_id}"
543 fi
544 fi
545 git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die
546
547 # recursively checkout submodules
548 if [[ -f ${out_dir}/.gitmodules ]]; then
549 local submodules
550 _git-r3_set_submodules \
551 "$(<"${out_dir}"/.gitmodules)"
552
553 while [[ ${submodules[@]} ]]; do
554 local subname=${submodules[0]}
555 local url=${submodules[1]}
556 local path=${submodules[2]}
557
558 if [[ ${url} == ./* || ${url} == ../* ]]; then
559 url=${repos[0]%%/}/${url}
560 fi
561
562 git-r3_checkout "${url}" "${out_dir}/${path}" \
563 "${local_id}/${subname}"
564
565 submodules=( "${submodules[@]:3}" ) # shift
566 done
567 fi
568
569 # keep this *after* submodules
570 export EGIT_DIR=${GIT_DIR}
571 export EGIT_VERSION=${new_commit_id}
572 }
573
574 # @FUNCTION: git-r3_peek_remote_ref
575 # @USAGE: [<repo-uri> [<remote-ref>]]
576 # @DESCRIPTION:
577 # Peek the reference in the remote repository and print the matching
578 # (newest) commit SHA1.
579 #
580 # <repo-uri> specifies the repository URIs to fetch from, as a space-
581 # -separated list. When not specified, defaults to ${EGIT_REPO_URI}.
582 #
583 # <remote-ref> specifies the remote ref to peek. It is preferred to use
584 # 'refs/heads/<branch-name>' for branches and 'refs/tags/<tag-name>'
585 # for tags. Alternatively, 'HEAD' may be used for upstream default
586 # branch. Defaults to the first of EGIT_COMMIT, EGIT_BRANCH or literal
587 # 'HEAD' that is set to a non-null value.
588 #
589 # The operation will be done purely on the remote, without using local
590 # storage. If commit SHA1 is provided as <remote-ref>, the function will
591 # fail due to limitations of git protocol.
592 #
593 # On success, the function returns 0 and writes hexadecimal commit SHA1
594 # to stdout. On failure, the function returns 1.
595 git-r3_peek_remote_ref() {
596 debug-print-function ${FUNCNAME} "$@"
597
598 local repos
599 if [[ ${1} ]]; then
600 repos=( ${1} )
601 elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
602 repos=( "${EGIT_REPO_URI[@]}" )
603 else
604 repos=( ${EGIT_REPO_URI} )
605 fi
606
607 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
608 local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
609
610 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
611
612 local r success
613 for r in "${repos[@]}"; do
614 einfo "Peeking ${remote_ref} on ${r} ..." >&2
615
616 local is_branch lookup_ref
617 if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
618 then
619 is_branch=1
620 lookup_ref=${remote_ref}
621 else
622 # ls-remote by commit is going to fail anyway,
623 # so we may as well pass refs/tags/ABCDEF...
624 lookup_ref=refs/tags/${remote_ref}
625 fi
626
627 # split on whitespace
628 local ref=(
629 $(git ls-remote "${r}" "${lookup_ref}")
630 )
631
632 if [[ ${ref[0]} ]]; then
633 echo "${ref[0]}"
634 return 0
635 fi
636 done
637
638 return 1
639 }
640
641 git-r3_src_fetch() {
642 debug-print-function ${FUNCNAME} "$@"
643
644 if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then
645 ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider"
646 ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use"
647 ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones"
648 ewarn "when git-2 eclass becomes deprecated."
649 fi
650
651 _git-r3_env_setup
652 git-r3_fetch
653 }
654
655 git-r3_src_unpack() {
656 debug-print-function ${FUNCNAME} "$@"
657
658 _git-r3_env_setup
659 git-r3_src_fetch
660 git-r3_checkout
661 }
662
663 # https://bugs.gentoo.org/show_bug.cgi?id=482666
664 git-r3_pkg_outofdate() {
665 debug-print-function ${FUNCNAME} "$@"
666
667 local new_commit_id=$(git-r3_peek_remote_ref)
668 ewarn "old: ${EGIT_VERSION}"
669 ewarn "new: ${new_commit_id}"
670 [[ ${new_commit_id} && ${old_commit_id} ]] || return 2
671
672 [[ ${EGIT_VERSION} != ${new_commit_id} ]]
673 }
674
675 _GIT_R3=1
676 fi

  ViewVC Help
Powered by ViewVC 1.1.20