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

Contents of /eclass/git-r3.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (hide annotations) (download)
Sun Mar 2 11:44:19 2014 UTC (17 months, 4 weeks ago) by mgorny
Branch: MAIN
Changes since 1.26: +4 -1 lines
Improve docs.

1 mgorny 1.24 # Copyright 1999-2014 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.27 # $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.26 2014/02/25 13:01:49 mgorny Exp $
4 mgorny 1.1
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 mgorny 1.24 # git as remote repository.
12 mgorny 1.1
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 mgorny 1.14 if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
32 mgorny 1.24 DEPEND="dev-vcs/git"
33 mgorny 1.14 fi
34 mgorny 1.13
35 mgorny 1.1 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
36     # @DESCRIPTION:
37     # Storage directory for git sources.
38     #
39 mgorny 1.27 # This is intended to be set by user in make.conf. Ebuilds must not set
40     # it.
41     #
42 mgorny 1.1 # 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 mgorny 1.9 # Can be a whitespace-separated list or an array.
54     #
55 mgorny 1.1 # 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 mgorny 1.7 # strip the trailing slash
173     repo_name=${repo_name%/}
174    
175 mgorny 1.1 # 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 mgorny 1.8 # gnome.org... who else?
180     browse/*) repo_name=${repo_name#browse/};;
181 mgorny 1.1 # 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 mgorny 1.17 mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die
206 mgorny 1.1 ) || die "Unable to create ${EGIT3_STORE_DIR}"
207     fi
208    
209     addwrite "${EGIT3_STORE_DIR}"
210 mgorny 1.24 if [[ -e ${GIT_DIR}/shallow ]]; then
211     einfo "${GIT_DIR} was a shallow clone, recreating..."
212     rm -r "${GIT_DIR}" || die
213     fi
214 mgorny 1.1 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 mgorny 1.15 # skip modules that have 'update = none', bug #487262.
245     local upd=$(echo "${data}" | git config -f /dev/fd/0 \
246 mgorny 1.18 submodule."${subname}".update)
247 mgorny 1.15 [[ ${upd} == none ]] && continue
248    
249 mgorny 1.1 submodules+=(
250     "${subname}"
251     "$(echo "${data}" | git config -f /dev/fd/0 \
252 mgorny 1.17 submodule."${subname}".url || die)"
253 mgorny 1.1 "$(echo "${data}" | git config -f /dev/fd/0 \
254 mgorny 1.17 submodule."${subname}".path || die)"
255 mgorny 1.1 )
256 mgorny 1.17 done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
257 mgorny 1.1 }
258    
259 mgorny 1.23 # @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 mgorny 1.1 # @FUNCTION: git-r3_fetch
274     # @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]]
275     # @DESCRIPTION:
276     # Fetch new commits to the local clone of repository.
277     #
278     # <repo-uri> specifies the repository URIs to fetch from, as a space-
279     # -separated list. The first URI will be used as repository group
280     # identifier and therefore must be used consistently. When not
281     # specified, defaults to ${EGIT_REPO_URI}.
282     #
283     # <remote-ref> specifies the remote ref or commit id to fetch.
284     # It is preferred to use 'refs/heads/<branch-name>' for branches
285     # and 'refs/tags/<tag-name>' for tags. Other options are 'HEAD'
286     # for upstream default branch and hexadecimal commit SHA1. Defaults
287     # to the first of EGIT_COMMIT, EGIT_BRANCH or literal 'HEAD' that
288     # is set to a non-null value.
289     #
290     # <local-id> specifies the local branch identifier that will be used to
291     # locally store the fetch result. It should be unique to multiple
292     # fetches within the repository that can be performed at the same time
293 mgorny 1.20 # (including parallel merges). It defaults to ${CATEGORY}/${PN}/${SLOT%/*}.
294 mgorny 1.1 # This default should be fine unless you are fetching multiple trees
295     # from the same repository in the same ebuild.
296     #
297     # The fetch operation will affect the EGIT_STORE only. It will not touch
298     # the working copy, nor export any environment variables.
299     # If the repository contains submodules, they will be fetched
300     # recursively.
301     git-r3_fetch() {
302     debug-print-function ${FUNCNAME} "$@"
303    
304 mgorny 1.16 [[ ${EVCS_OFFLINE} ]] && return
305    
306 mgorny 1.11 local repos
307     if [[ ${1} ]]; then
308     repos=( ${1} )
309     elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
310     repos=( "${EGIT_REPO_URI[@]}" )
311     else
312     repos=( ${EGIT_REPO_URI} )
313 mgorny 1.9 fi
314    
315 mgorny 1.1 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
316     local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
317 mgorny 1.20 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
318 mgorny 1.24 local local_ref=refs/git-r3/${local_id}/__main__
319 mgorny 1.1
320     [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
321    
322     local -x GIT_DIR
323 mgorny 1.9 _git-r3_set_gitdir "${repos[0]}"
324 mgorny 1.1
325     # try to fetch from the remote
326     local r success
327 mgorny 1.9 for r in "${repos[@]}"; do
328 mgorny 1.24 einfo "Fetching ${r} ..."
329 mgorny 1.1
330 mgorny 1.24 local fetch_command=(
331     git fetch --prune "${r}"
332     # mirror the remote branches as local branches
333     "refs/heads/*:refs/heads/*"
334     # pull tags explicitly in order to prune them properly
335     "refs/tags/*:refs/tags/*"
336 mgorny 1.25 # notes in case something needs them
337     "refs/notes/*:refs/notes/*"
338 mgorny 1.1 )
339    
340 mgorny 1.24 set -- "${fetch_command[@]}"
341     echo "${@}" >&2
342     if "${@}"; then
343     # now let's see what the user wants from us
344     local full_remote_ref=$(
345     git rev-parse --verify --symbolic-full-name "${remote_ref}"
346     )
347    
348     if [[ ${full_remote_ref} ]]; then
349     # when we are given a ref, create a symbolic ref
350     # so that we preserve the actual argument
351     set -- git symbolic-ref "${local_ref}" "${full_remote_ref}"
352 mgorny 1.3 else
353 mgorny 1.24 # otherwise, we were likely given a commit id
354     set -- git update-ref --no-deref "${local_ref}" "${remote_ref}"
355 mgorny 1.2 fi
356    
357 mgorny 1.24 echo "${@}" >&2
358     if ! "${@}"; then
359     die "Referencing ${remote_ref} failed (wrong ref?)."
360 mgorny 1.1 fi
361    
362     success=1
363     break
364     fi
365     done
366     [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"
367    
368     # recursively fetch submodules
369     if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
370     local submodules
371     _git-r3_set_submodules \
372     "$(git cat-file -p "${local_ref}":.gitmodules || die)"
373    
374     while [[ ${submodules[@]} ]]; do
375     local subname=${submodules[0]}
376     local url=${submodules[1]}
377     local path=${submodules[2]}
378     local commit=$(git rev-parse "${local_ref}:${path}")
379    
380     if [[ ! ${commit} ]]; then
381     die "Unable to get commit id for submodule ${subname}"
382     fi
383 mgorny 1.19 if [[ ${url} == ./* || ${url} == ../* ]]; then
384     local subrepos=( "${repos[@]/%//${url}}" )
385     else
386     local subrepos=( "${url}" )
387     fi
388 mgorny 1.1
389 mgorny 1.19 git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"
390 mgorny 1.1
391     submodules=( "${submodules[@]:3}" ) # shift
392     done
393     fi
394     }
395    
396     # @FUNCTION: git-r3_checkout
397     # @USAGE: [<repo-uri> [<checkout-path> [<local-id>]]]
398     # @DESCRIPTION:
399     # Check the previously fetched tree to the working copy.
400     #
401     # <repo-uri> specifies the repository URIs, as a space-separated list.
402     # The first URI will be used as repository group identifier
403     # and therefore must be used consistently with git-r3_fetch.
404     # The remaining URIs are not used and therefore may be omitted.
405     # When not specified, defaults to ${EGIT_REPO_URI}.
406     #
407     # <checkout-path> specifies the path to place the checkout. It defaults
408     # to ${EGIT_CHECKOUT_DIR} if set, otherwise to ${WORKDIR}/${P}.
409     #
410     # <local-id> needs to specify the local identifier that was used
411     # for respective git-r3_fetch.
412     #
413     # The checkout operation will write to the working copy, and export
414     # the repository state into the environment. If the repository contains
415     # submodules, they will be checked out recursively.
416     git-r3_checkout() {
417     debug-print-function ${FUNCNAME} "$@"
418    
419 mgorny 1.11 local repos
420     if [[ ${1} ]]; then
421     repos=( ${1} )
422     elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
423     repos=( "${EGIT_REPO_URI[@]}" )
424     else
425     repos=( ${EGIT_REPO_URI} )
426 mgorny 1.9 fi
427    
428 mgorny 1.1 local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
429 mgorny 1.20 local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
430 mgorny 1.1
431 mgorny 1.24 local -x GIT_DIR
432 mgorny 1.9 _git-r3_set_gitdir "${repos[0]}"
433 mgorny 1.1
434     einfo "Checking out ${repos[0]} to ${out_dir} ..."
435    
436 mgorny 1.24 if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
437 mgorny 1.1 if [[ ${EVCS_OFFLINE} ]]; then
438     die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE."
439     else
440     die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?"
441     fi
442     fi
443 mgorny 1.24 local remote_ref=$(
444     git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__
445     )
446     local new_commit_id=$(
447     git rev-parse --verify refs/git-r3/"${local_id}"/__main__
448     )
449 mgorny 1.1
450 mgorny 1.24 git-r3_sub_checkout() {
451 mgorny 1.25 local orig_repo=${GIT_DIR}
452 mgorny 1.24 local -x GIT_DIR=${out_dir}/.git
453     local -x GIT_WORK_TREE=${out_dir}
454    
455 mgorny 1.26 mkdir -p "${out_dir}" || die
456    
457     # use git init+fetch instead of clone since the latter doesn't like
458     # non-empty directories.
459    
460     git init --quiet || die
461     set -- git fetch --update-head-ok "${orig_repo}" \
462     "refs/heads/*:refs/heads/*" \
463     "refs/tags/*:refs/tags/*" \
464     "refs/notes/*:refs/notes/*"
465    
466     echo "${@}" >&2
467     "${@}" || die "git fetch into checkout dir failed"
468 mgorny 1.25
469 mgorny 1.24 set -- git checkout --quiet
470     if [[ ${remote_ref} ]]; then
471     set -- "${@}" "${remote_ref#refs/heads/}"
472     else
473     set -- "${@}" "${new_commit_id}"
474     fi
475     echo "${@}" >&2
476     "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed"
477     }
478     git-r3_sub_checkout
479 mgorny 1.22
480 mgorny 1.1 local old_commit_id=$(
481 mgorny 1.24 git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__
482 mgorny 1.1 )
483     if [[ ! ${old_commit_id} ]]; then
484     echo "GIT NEW branch -->"
485     echo " repository: ${repos[0]}"
486     echo " at the commit: ${new_commit_id}"
487     else
488 mgorny 1.24 # diff against previous revision
489 mgorny 1.1 echo "GIT update -->"
490     echo " repository: ${repos[0]}"
491     # write out message based on the revisions
492     if [[ "${old_commit_id}" != "${new_commit_id}" ]]; then
493     echo " updating from commit: ${old_commit_id}"
494     echo " to commit: ${new_commit_id}"
495    
496     git --no-pager diff --stat \
497     ${old_commit_id}..${new_commit_id}
498     else
499     echo " at the commit: ${new_commit_id}"
500     fi
501     fi
502 mgorny 1.24 git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die
503 mgorny 1.1
504     # recursively checkout submodules
505 mgorny 1.24 if [[ -f ${out_dir}/.gitmodules ]]; then
506 mgorny 1.1 local submodules
507     _git-r3_set_submodules \
508 mgorny 1.24 "$(<"${out_dir}"/.gitmodules)"
509 mgorny 1.1
510     while [[ ${submodules[@]} ]]; do
511     local subname=${submodules[0]}
512     local url=${submodules[1]}
513     local path=${submodules[2]}
514    
515 mgorny 1.19 if [[ ${url} == ./* || ${url} == ../* ]]; then
516     url=${repos[0]%%/}/${url}
517     fi
518    
519 mgorny 1.24 git-r3_checkout "${url}" "${out_dir}/${path}" \
520 mgorny 1.1 "${local_id}/${subname}"
521    
522     submodules=( "${submodules[@]:3}" ) # shift
523     done
524     fi
525    
526     # keep this *after* submodules
527     export EGIT_DIR=${GIT_DIR}
528     export EGIT_VERSION=${new_commit_id}
529     }
530    
531     # @FUNCTION: git-r3_peek_remote_ref
532     # @USAGE: [<repo-uri> [<remote-ref>]]
533     # @DESCRIPTION:
534     # Peek the reference in the remote repository and print the matching
535     # (newest) commit SHA1.
536     #
537     # <repo-uri> specifies the repository URIs to fetch from, as a space-
538     # -separated list. When not specified, defaults to ${EGIT_REPO_URI}.
539     #
540     # <remote-ref> specifies the remote ref to peek. It is preferred to use
541     # 'refs/heads/<branch-name>' for branches and 'refs/tags/<tag-name>'
542     # for tags. Alternatively, 'HEAD' may be used for upstream default
543     # branch. Defaults to the first of EGIT_COMMIT, EGIT_BRANCH or literal
544     # 'HEAD' that is set to a non-null value.
545     #
546     # The operation will be done purely on the remote, without using local
547     # storage. If commit SHA1 is provided as <remote-ref>, the function will
548     # fail due to limitations of git protocol.
549     #
550     # On success, the function returns 0 and writes hexadecimal commit SHA1
551     # to stdout. On failure, the function returns 1.
552     git-r3_peek_remote_ref() {
553     debug-print-function ${FUNCNAME} "$@"
554    
555 mgorny 1.11 local repos
556     if [[ ${1} ]]; then
557     repos=( ${1} )
558     elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
559     repos=( "${EGIT_REPO_URI[@]}" )
560     else
561     repos=( ${EGIT_REPO_URI} )
562 mgorny 1.9 fi
563    
564 mgorny 1.1 local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
565     local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
566    
567     [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
568    
569     local r success
570 mgorny 1.9 for r in "${repos[@]}"; do
571 mgorny 1.1 einfo "Peeking ${remote_ref} on ${r} ..." >&2
572    
573     local is_branch lookup_ref
574     if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
575     then
576     is_branch=1
577     lookup_ref=${remote_ref}
578     else
579     # ls-remote by commit is going to fail anyway,
580     # so we may as well pass refs/tags/ABCDEF...
581     lookup_ref=refs/tags/${remote_ref}
582     fi
583    
584     # split on whitespace
585     local ref=(
586     $(git ls-remote "${r}" "${lookup_ref}")
587     )
588    
589     if [[ ${ref[0]} ]]; then
590     echo "${ref[0]}"
591     return 0
592     fi
593     done
594    
595     return 1
596     }
597    
598     git-r3_src_fetch() {
599     debug-print-function ${FUNCNAME} "$@"
600    
601     if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then
602     ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider"
603     ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use"
604     ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones"
605     ewarn "when git-2 eclass becomes deprecated."
606     fi
607    
608     _git-r3_env_setup
609     git-r3_fetch
610     }
611    
612     git-r3_src_unpack() {
613     debug-print-function ${FUNCNAME} "$@"
614    
615     _git-r3_env_setup
616     git-r3_src_fetch
617     git-r3_checkout
618     }
619    
620     # https://bugs.gentoo.org/show_bug.cgi?id=482666
621     git-r3_pkg_outofdate() {
622     debug-print-function ${FUNCNAME} "$@"
623    
624     local new_commit_id=$(git-r3_peek_remote_ref)
625     ewarn "old: ${EGIT_VERSION}"
626     ewarn "new: ${new_commit_id}"
627     [[ ${new_commit_id} && ${old_commit_id} ]] || return 2
628    
629     [[ ${EGIT_VERSION} != ${new_commit_id} ]]
630     }
631    
632     _GIT_R3=1
633     fi

  ViewVC Help
Powered by ViewVC 1.1.20