From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 4D82913873B for ; Sun, 2 Mar 2014 11:47:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DCB09E0A52; Sun, 2 Mar 2014 11:47:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 67E90E0A52 for ; Sun, 2 Mar 2014 11:47:44 +0000 (UTC) Received: from flycatcher.gentoo.org (flycatcher.gentoo.org [81.93.255.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 698D033FB13 for ; Sun, 2 Mar 2014 11:47:43 +0000 (UTC) Received: by flycatcher.gentoo.org (Postfix, from userid 2279) id 2ADF52004C; Sun, 2 Mar 2014 11:47:42 +0000 (UTC) From: "Michal Gorny (mgorny)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, mgorny@gentoo.org Subject: [gentoo-commits] gentoo-x86 commit in eclass: ChangeLog git-r3.eclass X-VCS-Repository: gentoo-x86 X-VCS-Files: ChangeLog git-r3.eclass X-VCS-Directories: eclass X-VCS-Committer: mgorny X-VCS-Committer-Name: Michal Gorny Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Message-Id: <20140302114742.2ADF52004C@flycatcher.gentoo.org> Date: Sun, 2 Mar 2014 11:47:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 60441857-0454-4dd8-bfb9-85a0cf30d564 X-Archives-Hash: c455c761238ee6e124c4fa2ef2220742 mgorny 14/03/02 11:47:42 Modified: ChangeLog git-r3.eclass Log: Support EGIT_CLONE_TYPE=single. Revision Changes Path 1.1157 eclass/ChangeLog file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1157&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1157&content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?r1=1.1156&r2=1.1157 Index: ChangeLog =================================================================== RCS file: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v retrieving revision 1.1156 retrieving revision 1.1157 diff -u -r1.1156 -r1.1157 --- ChangeLog 2 Mar 2014 11:47:10 -0000 1.1156 +++ ChangeLog 2 Mar 2014 11:47:41 -0000 1.1157 @@ -1,6 +1,9 @@ # ChangeLog for eclass directory # Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1156 2014/03/02 11:47:10 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1157 2014/03/02 11:47:41 mgorny Exp $ + + 02 Mar 2014; Michał Górny git-r3.eclass: + Support EGIT_CLONE_TYPE=single. 02 Mar 2014; Michał Górny git-r3.eclass: Introduce EGIT_CLONE_TYPE for future use. 1.32 eclass/git-r3.eclass file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.32&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.32&content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?r1=1.31&r2=1.32 Index: git-r3.eclass =================================================================== RCS file: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- git-r3.eclass 2 Mar 2014 11:47:10 -0000 1.31 +++ git-r3.eclass 2 Mar 2014 11:47:41 -0000 1.32 @@ -1,6 +1,6 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.31 2014/03/02 11:47:10 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.32 2014/03/02 11:47:41 mgorny Exp $ # @ECLASS: git-r3.eclass # @MAINTAINER: @@ -35,7 +35,7 @@ # @ECLASS-VARIABLE: EGIT_CLONE_TYPE # @DESCRIPTION: # Type of clone that should be used against the remote repository. -# This can be either of: 'mirror'. +# This can be either of: 'mirror', 'single'. # # The 'mirror' type clones all remote branches and tags with complete # history and all notes. EGIT_COMMIT can specify any commit hash. @@ -43,7 +43,14 @@ # while fetching. This mode is suitable for cloning the local copy # for development or hosting a local git mirror. However, clones # of repositories with large diverged branches may quickly grow large. -: ${EGIT_CLONE_TYPE:=mirror} +# +# The 'single' type clones only the requested branch or tag. Tags +# referencing commits throughout the branch history are fetched as well, +# and all notes. EGIT_COMMIT can safely specify only hashes +# in the current branch. No purging of old references is done (if you +# often switch branches, you may need to remove stale branches +# yourself). This mode is suitable for general use. +: ${EGIT_CLONE_TYPE:=single} # @ECLASS-VARIABLE: EGIT3_STORE_DIR # @DESCRIPTION: @@ -122,7 +129,7 @@ # check the clone type case "${EGIT_CLONE_TYPE}" in - mirror) + mirror|single) ;; *) die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" @@ -305,14 +312,14 @@ [[ ${uri} == file://* || ${uri} == /* ]] } -# @FUNCTION: _git-r3_update_head -# @USAGE: +# @FUNCTION: _git-r3_find_head +# @USAGE: # @INTERNAL # @DESCRIPTION: -# Given a ref to which remote HEAD was fetched, try to match -# a local branch and update symbolic HEAD appropriately. -_git-r3_update_head() -{ +# Given a ref to which remote HEAD was fetched, try to find +# a branch matching the commit. Expects 'git show-ref' +# or 'git ls-remote' output on stdin. +_git-r3_find_head() { debug-print-function ${FUNCNAME} "$@" local head_ref=${1} @@ -332,13 +339,13 @@ matching_ref=${ref} fi fi - done < <(git show-ref --heads || die) + done if [[ ! ${matching_ref} ]]; then die "Unable to find a matching branch for remote HEAD (${head_hash})" fi - git symbolic-ref HEAD "${matching_ref}" || die + echo "${matching_ref}" } # @FUNCTION: git-r3_fetch @@ -406,24 +413,85 @@ for r in "${repos[@]}"; do einfo "Fetching ${r} ..." - local fetch_command=( - git fetch --prune "${r}" - # mirror the remote branches as local branches - "refs/heads/*:refs/heads/*" - # pull tags explicitly in order to prune them properly - "refs/tags/*:refs/tags/*" - # notes in case something needs them - "refs/notes/*:refs/notes/*" - # and HEAD in case we need the default branch - # (we keep it in refs/git-r3 since otherwise --prune interferes) - HEAD:refs/git-r3/HEAD - ) + local fetch_command=( git fetch "${r}" ) + + if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then + fetch_command+=( + --prune + # mirror the remote branches as local branches + "refs/heads/*:refs/heads/*" + # pull tags explicitly in order to prune them properly + "refs/tags/*:refs/tags/*" + # notes in case something needs them + "refs/notes/*:refs/notes/*" + # and HEAD in case we need the default branch + # (we keep it in refs/git-r3 since otherwise --prune interferes) + HEAD:refs/git-r3/HEAD + ) + else # single + local fetch_l fetch_r + + if [[ ${remote_ref} == HEAD ]]; then + # HEAD + fetch_l=HEAD + elif [[ ${remote_ref} == refs/heads/* ]]; then + # regular branch + fetch_l=${remote_ref} + else + # tag or commit... + # let ls-remote figure it out + local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}") + + # if it was a tag, ls-remote obtained a hash + if [[ ${tagref} ]]; then + # tag + fetch_l=refs/tags/${remote_ref} + else + # commit, so we need to fetch the branch + # and guess where it takes us... + if [[ ${branch} ]]; then + fetch_l=${branch} + else + fetch_l=HEAD + fi + fi + fi + + if [[ ${fetch_l} == HEAD ]]; then + fetch_r=refs/git-r3/HEAD + else + fetch_r=${fetch_l} + fi + + fetch_command+=( + "${fetch_l}:${fetch_r}" + ) + fi set -- "${fetch_command[@]}" echo "${@}" >&2 if "${@}"; then - # find remote HEAD and update our HEAD properly - _git-r3_update_head refs/git-r3/HEAD + if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then + # find remote HEAD and update our HEAD properly + git symbolic-ref HEAD \ + "$(_git-r3_find_head refs/git-r3/HEAD \ + < <(git show-ref --heads || die))" \ + || die "Unable to update HEAD" + else # single + if [[ ${fetch_l} == HEAD ]]; then + # find out what branch we fetched as HEAD + local head_branch=$(_git-r3_find_head \ + refs/git-r3/HEAD \ + < <(git ls-remote --heads "${r}" || die)) + + # and move it to its regular place + git update-ref --no-deref "${head_branch}" \ + refs/git-r3/HEAD \ + || die "Unable to sync HEAD branch ${head_branch}" + git symbolic-ref HEAD "${head_branch}" \ + || die "Unable to update HEAD" + fi + fi # now let's see what the user wants from us local full_remote_ref=$(