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

Diff of /eclass/git-r3.eclass

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

Revision 1.27 Revision 1.30
1# Copyright 1999-2014 Gentoo Foundation 1# Copyright 1999-2014 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-r3.eclass,v 1.27 2014/03/02 11:44:19 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.30 2014/03/02 11:46:42 mgorny Exp $
4 4
5# @ECLASS: git-r3.eclass 5# @ECLASS: git-r3.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Michał Górny <mgorny@gentoo.org> 7# Michał Górny <mgorny@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 8# @BLURB: Eclass for fetching and unpacking git repositories.
38# 38#
39# This is intended to be set by user in make.conf. Ebuilds must not set 39# This is intended to be set by user in make.conf. Ebuilds must not set
40# it. 40# it.
41# 41#
42# EGIT3_STORE_DIR=${DISTDIR}/git3-src 42# EGIT3_STORE_DIR=${DISTDIR}/git3-src
43
44# @ECLASS-VARIABLE: EGIT_MIRROR_URI
45# @DEFAULT_UNSET
46# @DESCRIPTION:
47# 'Top' URI to a local git mirror. If specified, the eclass will try
48# to fetch from the local mirror instead of using the remote repository.
49#
50# The mirror needs to follow EGIT3_STORE_DIR structure. The directory
51# created by eclass can be used for that purpose.
52#
53# Example:
54# @CODE
55# EGIT_MIRROR_URI="git://mirror.lan/"
56# @CODE
43 57
44# @ECLASS-VARIABLE: EGIT_REPO_URI 58# @ECLASS-VARIABLE: EGIT_REPO_URI
45# @REQUIRED 59# @REQUIRED
46# @DESCRIPTION: 60# @DESCRIPTION:
47# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs 61# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
268 local uri=${1} 282 local uri=${1}
269 283
270 [[ ${uri} == file://* || ${uri} == /* ]] 284 [[ ${uri} == file://* || ${uri} == /* ]]
271} 285}
272 286
287# @FUNCTION: _git-r3_update_head
288# @USAGE: <remote-head-ref>
289# @INTERNAL
290# @DESCRIPTION:
291# Given a ref to which remote HEAD was fetched, try to match
292# a local branch and update symbolic HEAD appropriately.
293_git-r3_update_head()
294{
295 debug-print-function ${FUNCNAME} "$@"
296
297 local head_ref=${1}
298 local head_hash=$(git rev-parse --verify "${1}" || die)
299 local matching_ref
300
301 # TODO: some transports support peeking at symbolic remote refs
302 # find a way to use that rather than guessing
303
304 # (based on guess_remote_head() in git-1.9.0/remote.c)
305 local h ref
306 while read h ref; do
307 # look for matching head
308 if [[ ${h} == ${head_hash} ]]; then
309 # either take the first matching ref, or master if it is there
310 if [[ ! ${matching_ref} || ${ref} == refs/heads/master ]]; then
311 matching_ref=${ref}
312 fi
313 fi
314 done < <(git show-ref --heads || die)
315
316 if [[ ! ${matching_ref} ]]; then
317 die "Unable to find a matching branch for remote HEAD (${head_hash})"
318 fi
319
320 git symbolic-ref HEAD "${matching_ref}" || die
321}
322
273# @FUNCTION: git-r3_fetch 323# @FUNCTION: git-r3_fetch
274# @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]] 324# @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]]
275# @DESCRIPTION: 325# @DESCRIPTION:
276# Fetch new commits to the local clone of repository. 326# Fetch new commits to the local clone of repository.
277# 327#
319 369
320 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" 370 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
321 371
322 local -x GIT_DIR 372 local -x GIT_DIR
323 _git-r3_set_gitdir "${repos[0]}" 373 _git-r3_set_gitdir "${repos[0]}"
374
375 # prepend the local mirror if applicable
376 if [[ ${EGIT_MIRROR_URI} ]]; then
377 repos=(
378 "${EGIT_MIRROR_URI%/}/${GIT_DIR##*/}"
379 "${repos[@]}"
380 )
381 fi
324 382
325 # try to fetch from the remote 383 # try to fetch from the remote
326 local r success 384 local r success
327 for r in "${repos[@]}"; do 385 for r in "${repos[@]}"; do
328 einfo "Fetching ${r} ..." 386 einfo "Fetching ${r} ..."
333 "refs/heads/*:refs/heads/*" 391 "refs/heads/*:refs/heads/*"
334 # pull tags explicitly in order to prune them properly 392 # pull tags explicitly in order to prune them properly
335 "refs/tags/*:refs/tags/*" 393 "refs/tags/*:refs/tags/*"
336 # notes in case something needs them 394 # notes in case something needs them
337 "refs/notes/*:refs/notes/*" 395 "refs/notes/*:refs/notes/*"
396 # and HEAD in case we need the default branch
397 # (we keep it in refs/git-r3 since otherwise --prune interferes)
398 HEAD:refs/git-r3/HEAD
338 ) 399 )
339 400
340 set -- "${fetch_command[@]}" 401 set -- "${fetch_command[@]}"
341 echo "${@}" >&2 402 echo "${@}" >&2
342 if "${@}"; then 403 if "${@}"; then
404 # find remote HEAD and update our HEAD properly
405 _git-r3_update_head refs/git-r3/HEAD
406
343 # now let's see what the user wants from us 407 # now let's see what the user wants from us
344 local full_remote_ref=$( 408 local full_remote_ref=$(
345 git rev-parse --verify --symbolic-full-name "${remote_ref}" 409 git rev-parse --verify --symbolic-full-name "${remote_ref}"
346 ) 410 )
347 411
456 520
457 # use git init+fetch instead of clone since the latter doesn't like 521 # use git init+fetch instead of clone since the latter doesn't like
458 # non-empty directories. 522 # non-empty directories.
459 523
460 git init --quiet || die 524 git init --quiet || die
461 set -- git fetch --update-head-ok "${orig_repo}" \ 525 # setup 'alternates' to avoid copying objects
462 "refs/heads/*:refs/heads/*" \ 526 echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die
463 "refs/tags/*:refs/tags/*" \ 527 # now copy the refs
464 "refs/notes/*:refs/notes/*" 528 # [htn]* safely catches heads, tags, notes without complaining
529 # on non-existing ones, and omits internal 'git-r3' ref
530 cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
465 531
466 echo "${@}" >&2 532 # (no need to copy HEAD, we will set it via checkout)
467 "${@}" || die "git fetch into checkout dir failed"
468 533
469 set -- git checkout --quiet 534 set -- git checkout --quiet
470 if [[ ${remote_ref} ]]; then 535 if [[ ${remote_ref} ]]; then
471 set -- "${@}" "${remote_ref#refs/heads/}" 536 set -- "${@}" "${remote_ref#refs/heads/}"
472 else 537 else

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

  ViewVC Help
Powered by ViewVC 1.1.20