public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support
@ 2014-02-26 11:55 Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 01/10] Clarify that ebuilds are not supposed to set EGIT3_STORE_DIR Michał Górny
                   ` (12 more replies)
  0 siblings, 13 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:55 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]

Hello, all.

I will submit a long serie of patches in reply to this mail. They add
support for EGIT_CLONE_TYPE and also fix some bugs I've found during
the testing.

I've confirmed that the eclass works properly with git-1.8.3.2
(the current stable). This version is required for '--unshallow'.

Quick summary:

#1 just clarifies docs in order to get better consistency.

#2 improves the checkout mode to be faster and avoids copying the whole
repository to the checkout dir. It also makes the checkout future-proof
for shallow clones.

#3 fixes support for HEAD != master, that is repositories where
the default branch is not master ;).

#4 adds support for using local mirror for git repos. This could be
used to reduce network use on local networks with many Gentoo machines
using the same live ebuilds :).

#5-#9 actually add all the EGIT_CLONE_TYPE magic.

#10 fixes non-fast-forward updates :).

Please review, and preferably reply to each of the patches separately.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 01/10] Clarify that ebuilds are not supposed to set EGIT3_STORE_DIR.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 02/10] Replace 'git fetch' checkout with more efficient pseudo-shared fetch Michał Górny
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

---
 eclass/git-r3.eclass | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index d726cee..c00b3a0 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -36,6 +36,9 @@ fi
 # @DESCRIPTION:
 # Storage directory for git sources.
 #
+# This is intended to be set by user in make.conf. Ebuilds must not set
+# it.
+#
 # EGIT3_STORE_DIR=${DISTDIR}/git3-src
 
 # @ECLASS-VARIABLE: EGIT_REPO_URI
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 02/10] Replace 'git fetch' checkout with more efficient pseudo-shared fetch.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 01/10] Clarify that ebuilds are not supposed to set EGIT3_STORE_DIR Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch Michał Górny
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

'git fetch' uses git transport to compress and transfer all the commits
even though they're on a local machine -- both very slow and space
consuming.

Setting 'alternates' before fetching solves the issue partially since
the commits no longer need to be transferred. The checkout is still slow
since git needs to recheck all of them.

Instead, just set 'alternates' and copy the refs manually. This is
pretty much what 'git clone --shared' does. And we can't use 'git clone'
because it refuses non-empty destinations.

This also makes it possible to use the same checkout method for shallow
clones with <git-1.9 (git-1.9 finally allows clones and fetches using
shallow repos).
---
 eclass/git-r3.eclass | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index c00b3a0..892ed07 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -458,13 +458,14 @@ git-r3_checkout() {
 		# non-empty directories.
 
 		git init --quiet || die
-		set -- git fetch --update-head-ok "${orig_repo}" \
-			"refs/heads/*:refs/heads/*" \
-			"refs/tags/*:refs/tags/*" \
-			"refs/notes/*:refs/notes/*"
-
-		echo "${@}" >&2
-		"${@}" || die "git fetch into checkout dir failed"
+		# setup 'alternates' to avoid copying objects
+		echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die
+		# now copy the refs
+		# [htn]* safely catches heads, tags, notes without complaining
+		# on non-existing ones, and omits internal 'git-r3' ref
+		cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
+
+		# (no need to copy HEAD, we will set it via checkout)
 
 		set -- git checkout --quiet
 		if [[ ${remote_ref} ]]; then
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 01/10] Clarify that ebuilds are not supposed to set EGIT3_STORE_DIR Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 02/10] Replace 'git fetch' checkout with more efficient pseudo-shared fetch Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 15:22   ` Ulrich Mueller
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 04/10] Support EGIT_MIRROR_URI to specify local git mirror Michał Górny
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Long story short, our HEAD was set by 'git init' and left at the default
'master'. So whenever we hit a repository that used a different default
branch, we either fetched the wrong branch or failed completely.

Using 'git clone' would fix the issue only temporarily since it does not
provide a way to follow changes of the 'HEAD' branch. git has some code
to obtain symbolic 'HEAD' using some of the transports but it seems not
to be part of the command-line API.

So instead, we do pretty much the same as 'git clone' does when it is
unable to get the symbolic HEAD from remote. We find the branch that is
on the same commit as HEAD, preferably 'master'.

As a note: we need to fetch into a custom ref since git does not allow
fetching to 'HEAD' directly. In fact, 'git fetch HEAD:HEAD' only creates
a branch named 'HEAD', and 'git fetch --prune HEAD:HEAD' creates and
removes it ;).
---
 eclass/git-r3.eclass | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 892ed07..7c78b66 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -270,6 +270,42 @@ _git-r3_is_local_repo() {
 	[[ ${uri} == file://* || ${uri} == /* ]]
 }
 
+# @FUNCTION: _git-r3_update_head
+# @USAGE: <remote-head-ref>
+# @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()
+{
+	debug-print-function ${FUNCNAME} "$@"
+
+	local head_ref=${1}
+	local head_hash=$(git rev-parse --verify ${1} || die)
+	local matching_ref
+
+	# TODO: some transports support peeking at symbolic remote refs
+	# find a way to use that rather than guessing
+
+	# (based on guess_remote_head() in git-1.9.0/remote.c)
+	local h ref
+	while read h ref; do
+		# look for matching head
+		if [[ ${h} == ${head_hash} ]]; then
+			# either take the first matching ref, or master if it is there
+			if [[ ! ${matching_ref} || ${ref} == refs/heads/master ]]; then
+				matching_ref=${ref}
+			fi
+		fi
+	done < <(git show-ref --heads || die)
+
+	if [[ ! ${matching_ref} ]]; then
+		die "Unable to find a matching branch for remote HEAD (${head_hash})"
+	fi
+
+	git symbolic-ref HEAD "${matching_ref}" || die
+}
+
 # @FUNCTION: git-r3_fetch
 # @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]]
 # @DESCRIPTION:
@@ -335,11 +371,17 @@ git-r3_fetch() {
 			"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
 		)
 
 		set -- "${fetch_command[@]}"
 		echo "${@}" >&2
 		if "${@}"; then
+			# find remote HEAD and update our HEAD properly
+			_git-r3_update_head refs/git-r3/HEAD
+
 			# now let's see what the user wants from us
 			local full_remote_ref=$(
 				git rev-parse --verify --symbolic-full-name "${remote_ref}"
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 04/10] Support EGIT_MIRROR_URI to specify local git mirror.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (2 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 05/10] Introduce EGIT_CLONE_TYPE for future use Michał Górny
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

When multiple Gentoo machines are used on the local network, and they
use the same git ebuilds it may be useful to set a local mirror :).

The idea is quite simple -- you set the host to EGIT_CLONE_TYPE=mirror,
and then share the EGIT3_STORE_DIR directory. Then you set
EGIT_MIRROR_URI on the remaining hosts and they try to fetch from your
local mirror first.
---
 eclass/git-r3.eclass | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 7c78b66..8462fba 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -41,6 +41,20 @@ fi
 #
 # EGIT3_STORE_DIR=${DISTDIR}/git3-src
 
+# @ECLASS-VARIABLE: EGIT_MIRROR_URI
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# 'Top' URI to a local git mirror. If specified, the eclass will try
+# to fetch from the local mirror instead of using the remote repository.
+#
+# The mirror needs to follow EGIT3_STORE_DIR structure. The directory
+# created by eclass can be used for that purpose.
+#
+# Example:
+# @CODE
+# EGIT_MIRROR_URI="git://mirror.lan/"
+# @CODE
+
 # @ECLASS-VARIABLE: EGIT_REPO_URI
 # @REQUIRED
 # @DESCRIPTION:
@@ -358,6 +372,14 @@ git-r3_fetch() {
 	local -x GIT_DIR
 	_git-r3_set_gitdir "${repos[0]}"
 
+	# prepend the local mirror if applicable
+	if [[ ${EGIT_MIRROR_URI} ]]; then
+		repos=(
+			"${EGIT_MIRROR_URI%/}/${GIT_DIR##*/}"
+			"${repos[@]}"
+		)
+	fi
+
 	# try to fetch from the remote
 	local r success
 	for r in "${repos[@]}"; do
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 05/10] Introduce EGIT_CLONE_TYPE for future use.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (3 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 04/10] Support EGIT_MIRROR_URI to specify local git mirror Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 06/10] Support single-branch mode Michał Górny
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

In this commit, it's just 'mirror' explained :).
---
 eclass/git-r3.eclass | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 8462fba..9c8508a 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -32,6 +32,19 @@ if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
 	DEPEND="dev-vcs/git"
 fi
 
+# @ECLASS-VARIABLE: EGIT_CLONE_TYPE
+# @DESCRIPTION:
+# Type of clone that should be used against the remote repository.
+# This can be either of: 'mirror'.
+#
+# The 'mirror' type clones all remote branches and tags with complete
+# history and all notes. EGIT_COMMIT can specify any commit hash.
+# Upstream-removed branches and tags are purged from the local clone
+# 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}
+
 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
 # @DESCRIPTION:
 # Storage directory for git sources.
@@ -107,6 +120,14 @@ fi
 _git-r3_env_setup() {
 	debug-print-function ${FUNCNAME} "$@"
 
+	# check the clone type
+	case "${EGIT_CLONE_TYPE}" in
+		mirror)
+			;;
+		*)
+			die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
+	esac
+
 	local esc_pn livevar
 	esc_pn=${PN//[-+]/_}
 
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 06/10] Support single-branch mode.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (4 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 05/10] Introduce EGIT_CLONE_TYPE for future use Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones Michał Górny
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

This is pretty similar to what git-2.eclass did by default. Instead of
fetching all the branches, we only fetch what user told us to. Good news
is that it's sometimes a space-saver. Bad news is that it's harder to
deal with.

One of the problems is that EGIT_COMMIT can either specify a tag
or a hash (possibly an abbreviated one). And while we can fetch tags
(since they are refs), git can't fetch an arbitrary commit by hash. Plus
there's the special HEAD case to care about.

So first, we need to figure out what we're going to fetch actually. If
it's a commit hash, we need to fetch the (supposedly) requested branch
instead and hope the commit is in it. And if we're fetching HEAD, we
need to use the special ref as explained before.

Then, we need to update 'HEAD' properly. We could supposedly try to
figure out what HEAD is before fetching but since we support fetch
failures and repository fallback, it's easier to do so after checking
that the repo is up.

It's pretty much the opposite we do in 'mirror' mode. We fetch HEAD into
dedicated ref, then use 'git ls-remote' to figure out what branch we
actually fetched. Then we move the commits into proper branch and update
HEAD.
---
 eclass/git-r3.eclass | 118 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 93 insertions(+), 25 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 9c8508a..8b7d75d 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -35,7 +35,7 @@ fi
 # @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 @@ fi
 # 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 @@ _git-r3_env_setup() {
 
 	# check the clone type
 	case "${EGIT_CLONE_TYPE}" in
-		mirror)
+		mirror|single)
 			;;
 		*)
 			die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
@@ -305,14 +312,14 @@ _git-r3_is_local_repo() {
 	[[ ${uri} == file://* || ${uri} == /* ]]
 }
 
-# @FUNCTION: _git-r3_update_head
-# @USAGE: <remote-head-ref>
+# @FUNCTION: _git-r3_find_head
+# @USAGE: <head-ref>
 # @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 @@ _git-r3_update_head()
 				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 @@ git-r3_fetch() {
 	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=$(
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (5 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 06/10] Support single-branch mode Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 12:39   ` Alex Xu
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 08/10] Auto-unshallow when fetch-by-commit is requested Michał Górny
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

This one's pretty similar to what we had before though a bit simpler.
For one, we don't have the 'smart fetching' anymore since it was complex
and unsafe.

Implementation-wise 'shallow' mode differs only when starting a new
branch. In that case, '--depth 1' is used to avoid fetching earlier
commits. Further updates are done through plain 'git fetch'.

So, if you enable shallow mode after cloning a repository in 'single'
mode, nothing will actually change :). However, if you switch branch
the repository will become partially 'shallow'.

This also comes with --unshallow support that requires >=git-1.8.2.1.
When 'single' or 'mirror' mode is requested, and the repository is
shallow, it guarantees that at least the requested branch is
unshallowed and fully useful.
---
 eclass/git-r3.eclass | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 8b7d75d..c9c2da5 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -29,13 +29,13 @@ EXPORT_FUNCTIONS src_unpack
 if [[ ! ${_GIT_R3} ]]; then
 
 if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
-	DEPEND="dev-vcs/git"
+	DEPEND=">=dev-vcs/git-1.8.2.1"
 fi
 
 # @ECLASS-VARIABLE: EGIT_CLONE_TYPE
 # @DESCRIPTION:
 # Type of clone that should be used against the remote repository.
-# This can be either of: 'mirror', 'single'.
+# This can be either of: 'mirror', 'single', 'shallow'.
 #
 # The 'mirror' type clones all remote branches and tags with complete
 # history and all notes. EGIT_COMMIT can specify any commit hash.
@@ -50,6 +50,12 @@ fi
 # 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.
+#
+# The 'shallow' type clones only the newest commit on requested branch
+# or tag. EGIT_COMMIT can only specify tags, and since the history is
+# unavailable calls like 'git describe' will not reference prior tags.
+# No purging of old references is done. This mode is intended mostly for
+# embedded systems with limited disk space.
 : ${EGIT_CLONE_TYPE:=single}
 
 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
@@ -129,7 +135,7 @@ _git-r3_env_setup() {
 
 	# check the clone type
 	case "${EGIT_CLONE_TYPE}" in
-		mirror|single)
+		mirror|single|shallow)
 			;;
 		*)
 			die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
@@ -249,10 +255,6 @@ _git-r3_set_gitdir() {
 	fi
 
 	addwrite "${EGIT3_STORE_DIR}"
-	if [[ -e ${GIT_DIR}/shallow ]]; then
-		einfo "${GIT_DIR} was a shallow clone, recreating..."
-		rm -r "${GIT_DIR}" || die
-	fi
 	if [[ ! -d ${GIT_DIR} ]]; then
 		mkdir "${GIT_DIR}" || die
 		git init --bare || die
@@ -428,7 +430,7 @@ git-r3_fetch() {
 				# (we keep it in refs/git-r3 since otherwise --prune interferes)
 				HEAD:refs/git-r3/HEAD
 			)
-		else # single
+		else # single or shallow
 			local fetch_l fetch_r
 
 			if [[ ${remote_ref} == HEAD ]]; then
@@ -468,6 +470,18 @@ git-r3_fetch() {
 			)
 		fi
 
+		if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
+			# use '--depth 1' when fetching a new branch
+			if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
+			then
+				fetch_command+=( --depth 1 )
+			fi
+		else # non-shallow mode
+			if [[ -f ${GIT_DIR}/shallow ]]; then
+				fetch_command+=( --unshallow )
+			fi
+		fi
+
 		set -- "${fetch_command[@]}"
 		echo "${@}" >&2
 		if "${@}"; then
@@ -477,7 +491,7 @@ git-r3_fetch() {
 					"$(_git-r3_find_head refs/git-r3/HEAD \
 						< <(git show-ref --heads || die))" \
 						|| die "Unable to update HEAD"
-			else # single
+			else # single or shallow
 				if [[ ${fetch_l} == HEAD ]]; then
 					# find out what branch we fetched as HEAD
 					local head_branch=$(_git-r3_find_head \
@@ -620,6 +634,10 @@ git-r3_checkout() {
 
 		# (no need to copy HEAD, we will set it via checkout)
 
+		if [[ -f ${orig_repo}/shallow ]]; then
+			cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die
+		fi
+
 		set -- git checkout --quiet
 		if [[ ${remote_ref} ]]; then
 			set -- "${@}" "${remote_ref#refs/heads/}"
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 08/10] Auto-unshallow when fetch-by-commit is requested.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (6 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type Michał Górny
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

This is required to support submodules transparently since they always
fetch by commit hash.
---
 eclass/git-r3.eclass | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index c9c2da5..08b8ebb 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -449,13 +449,18 @@ git-r3_fetch() {
 					# tag
 					fetch_l=refs/tags/${remote_ref}
 				else
-					# commit, so we need to fetch the branch
-					# and guess where it takes us...
+					# commit
+					# so we need to fetch the branch
 					if [[ ${branch} ]]; then
 						fetch_l=${branch}
 					else
 						fetch_l=HEAD
 					fi
+
+					# fetching by commit in shallow mode? can't do.
+					if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
+						local EGIT_CLONE_TYPE=single
+					fi
 				fi
 			fi
 
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (7 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 08/10] Auto-unshallow when fetch-by-commit is requested Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 15:29   ` Ulrich Mueller
  2014-02-26 23:53   ` hasufell
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 10/10] Use '+'-refs to force updates on fetch Michał Górny
                   ` (3 subsequent siblings)
  12 siblings, 2 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Use-cases include Google Code (that doesn't support shallow clones) and
random build systems that play with history and 'git describe'.

However, please use this sparingly. When the build can't go on without
non-shallow clone, sure. But if it only results in non-pretty versions,
I think users choosing EGIT_CLONE_TYPE=shallow explicitly are ready to
deal with the fallout.
---
 eclass/git-r3.eclass | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 08b8ebb..33e66a6 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -58,6 +58,19 @@ fi
 # embedded systems with limited disk space.
 : ${EGIT_CLONE_TYPE:=single}
 
+# @ECLASS-VARIABLE: EGIT_MIN_CLONE_TYPE
+# @DESCRIPTION:
+# 'Minimum' clone type supported by the ebuild. Takes same values
+# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is,
+# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
+# EGIT_MIN_CLONE_TYPE instead.
+#
+# A common case is to use 'single' whenever the build system requires
+# access to full branch history or the remote (Google Code) does not
+# support shallow clones. Please use sparingly, and to fix fatal errors
+# rather than 'non-pretty versions'.
+: ${EGIT_MIN_CLONE_TYPE:=shallow}
+
 # @ECLASS-VARIABLE: EGIT3_STORE_DIR
 # @DESCRIPTION:
 # Storage directory for git sources.
@@ -140,6 +153,24 @@ _git-r3_env_setup() {
 		*)
 			die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
 	esac
+	case "${EGIT_MIN_CLONE_TYPE}" in
+		shallow)
+			;;
+		single)
+			if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
+				ewarn "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
+				EGIT_CLONE_TYPE=single
+			fi
+			;;
+		mirror)
+			if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
+				ewarn "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
+				EGIT_CLONE_TYPE=mirror
+			fi
+			;;
+		*)
+			die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
+	esac
 
 	local esc_pn livevar
 	esc_pn=${PN//[-+]/_}
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 10/10] Use '+'-refs to force updates on fetch.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (8 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type Michał Górny
@ 2014-02-26 11:59 ` Michał Górny
  2014-02-26 15:19 ` [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 11:59 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

This is required to allow non-forward updates with upstreams that don't
like linear or predictable history.
---
 eclass/git-r3.eclass | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 33e66a6..af84ca6 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -452,14 +452,14 @@ git-r3_fetch() {
 			fetch_command+=(
 				--prune
 				# mirror the remote branches as local branches
-				"refs/heads/*:refs/heads/*"
+				"+refs/heads/*:refs/heads/*"
 				# pull tags explicitly in order to prune them properly
-				"refs/tags/*:refs/tags/*"
+				"+refs/tags/*:refs/tags/*"
 				# notes in case something needs them
-				"refs/notes/*:refs/notes/*"
+				"+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
+				"+HEAD:refs/git-r3/HEAD"
 			)
 		else # single or shallow
 			local fetch_l fetch_r
@@ -502,7 +502,7 @@ git-r3_fetch() {
 			fi
 
 			fetch_command+=(
-				"${fetch_l}:${fetch_r}"
+				"+${fetch_l}:${fetch_r}"
 			)
 		fi
 
-- 
1.8.3.2



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones.
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones Michał Górny
@ 2014-02-26 12:39   ` Alex Xu
  2014-02-26 12:47     ` Michał Górny
  0 siblings, 1 reply; 24+ messages in thread
From: Alex Xu @ 2014-02-26 12:39 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

On 26/02/14 06:59 AM, Michał Górny wrote:
> Implementation-wise 'shallow' mode differs only when starting a new
> branch. In that case, '--depth 1' is used to avoid fetching earlier
> commits. Further updates are done through plain 'git fetch'.

So this fetches all a..b commits. If the package hasn't been updated in
a while, wouldn't this be less efficient than a new clone?


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones.
  2014-02-26 12:39   ` Alex Xu
@ 2014-02-26 12:47     ` Michał Górny
  0 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 12:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: alex_y_xu

[-- Attachment #1: Type: text/plain, Size: 752 bytes --]

Dnia 2014-02-26, o godz. 07:39:51
Alex Xu <alex_y_xu@yahoo.ca> napisał(a):

> On 26/02/14 06:59 AM, Michał Górny wrote:
> > Implementation-wise 'shallow' mode differs only when starting a new
> > branch. In that case, '--depth 1' is used to avoid fetching earlier
> > commits. Further updates are done through plain 'git fetch'.
> 
> So this fetches all a..b commits. If the package hasn't been updated in
> a while, wouldn't this be less efficient than a new clone?

In a few rare cases, yes, that could happen. Though we can't really
estimate or guess that :).

If user suspects that, he can always remove the local repository
and let the eclass re-fetch it. I doubt we can do more than that.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (9 preceding siblings ...)
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 10/10] Use '+'-refs to force updates on fetch Michał Górny
@ 2014-02-26 15:19 ` Michał Górny
  2014-02-26 23:42 ` [gentoo-dev] [PATCH git-r3 11/11] Disable shallow clones of local repositories Michał Górny
  2014-02-27  0:09 ` [gentoo-dev] [PATCH git-r3 12/12] Clarify which EGIT_CLONE_TYPE variables are set by who Michał Górny
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 15:19 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 336 bytes --]

Dnia 2014-02-26, o godz. 12:55:20
Michał Górny <mgorny@gentoo.org> napisał(a):

> I will submit a long serie of patches in reply to this mail. They add
> support for EGIT_CLONE_TYPE and also fix some bugs I've found during
> the testing.

oh, and the complete eclass for easier testing.

-- 
Best regards,
Michał Górny

[-- Attachment #1.2: git-r3.eclass --]
[-- Type: text/plain, Size: 25702 bytes --]

# 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.26 2014/02/25 13:01:49 mgorny Exp $

# @ECLASS: git-r3.eclass
# @MAINTAINER:
# Michał Górny <mgorny@gentoo.org>
# @BLURB: Eclass for fetching and unpacking git repositories.
# @DESCRIPTION:
# Third generation eclass for easing maitenance of live ebuilds using
# git as remote repository.

case "${EAPI:-0}" in
	0|1|2|3|4|5)
		;;
	*)
		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
		;;
esac

if [[ ! ${_GIT_R3} ]]; then

inherit eutils

fi

EXPORT_FUNCTIONS src_unpack

if [[ ! ${_GIT_R3} ]]; then

if [[ ! ${_INHERITED_BY_GIT_2} ]]; then
	DEPEND=">=dev-vcs/git-1.8.2.1"
fi

# @ECLASS-VARIABLE: EGIT_CLONE_TYPE
# @DESCRIPTION:
# Type of clone that should be used against the remote repository.
# This can be either of: 'mirror', 'single', 'shallow'.
#
# The 'mirror' type clones all remote branches and tags with complete
# history and all notes. EGIT_COMMIT can specify any commit hash.
# Upstream-removed branches and tags are purged from the local clone
# 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.
#
# 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.
#
# The 'shallow' type clones only the newest commit on requested branch
# or tag. EGIT_COMMIT can only specify tags, and since the history is
# unavailable calls like 'git describe' will not reference prior tags.
# No purging of old references is done. This mode is intended mostly for
# embedded systems with limited disk space.
: ${EGIT_CLONE_TYPE:=single}

# @ECLASS-VARIABLE: EGIT_MIN_CLONE_TYPE
# @DESCRIPTION:
# 'Minimum' clone type supported by the ebuild. Takes same values
# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is,
# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
# EGIT_MIN_CLONE_TYPE instead.
#
# A common case is to use 'single' whenever the build system requires
# access to full branch history or the remote (Google Code) does not
# support shallow clones. Please use sparingly, and to fix fatal errors
# rather than 'non-pretty versions'.
: ${EGIT_MIN_CLONE_TYPE:=shallow}

# @ECLASS-VARIABLE: EGIT3_STORE_DIR
# @DESCRIPTION:
# Storage directory for git sources.
#
# This is intended to be set by user in make.conf. Ebuilds must not set
# it.
#
# EGIT3_STORE_DIR=${DISTDIR}/git3-src

# @ECLASS-VARIABLE: EGIT_MIRROR_URI
# @DEFAULT_UNSET
# @DESCRIPTION:
# 'Top' URI to a local git mirror. If specified, the eclass will try
# to fetch from the local mirror instead of using the remote repository.
#
# The mirror needs to follow EGIT3_STORE_DIR structure. The directory
# created by eclass can be used for that purpose.
#
# Example:
# @CODE
# EGIT_MIRROR_URI="git://mirror.lan/"
# @CODE

# @ECLASS-VARIABLE: EGIT_REPO_URI
# @REQUIRED
# @DESCRIPTION:
# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
# are provided, the eclass will consider them as fallback URIs to try
# if the first URI does not work.
#
# It can be overriden via env using ${PN}_LIVE_REPO variable.
#
# Can be a whitespace-separated list or an array.
#
# Example:
# @CODE
# EGIT_REPO_URI="git://a/b.git https://c/d.git"
# @CODE

# @ECLASS-VARIABLE: EVCS_OFFLINE
# @DEFAULT_UNSET
# @DESCRIPTION:
# If non-empty, this variable prevents any online operations.

# @ECLASS-VARIABLE: EGIT_BRANCH
# @DEFAULT_UNSET
# @DESCRIPTION:
# The branch name to check out. If unset, the upstream default (HEAD)
# will be used.
#
# It can be overriden via env using ${PN}_LIVE_BRANCH variable.

# @ECLASS-VARIABLE: EGIT_COMMIT
# @DEFAULT_UNSET
# @DESCRIPTION:
# The tag name or commit identifier to check out. If unset, newest
# commit from the branch will be used. If set, EGIT_BRANCH will
# be ignored.
#
# It can be overriden via env using ${PN}_LIVE_COMMIT variable.

# @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR
# @DESCRIPTION:
# The directory to check the git sources out to.
#
# EGIT_CHECKOUT_DIR=${WORKDIR}/${P}

# @FUNCTION: _git-r3_env_setup
# @INTERNAL
# @DESCRIPTION:
# Set the eclass variables as necessary for operation. This can involve
# setting EGIT_* to defaults or ${PN}_LIVE_* variables.
_git-r3_env_setup() {
	debug-print-function ${FUNCNAME} "$@"

	# check the clone type
	case "${EGIT_CLONE_TYPE}" in
		mirror|single|shallow)
			;;
		*)
			die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}"
	esac
	case "${EGIT_MIN_CLONE_TYPE}" in
		shallow)
			;;
		single)
			if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
				ewarn "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
				EGIT_CLONE_TYPE=single
			fi
			;;
		mirror)
			if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
				ewarn "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
				EGIT_CLONE_TYPE=mirror
			fi
			;;
		*)
			die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}"
	esac

	local esc_pn livevar
	esc_pn=${PN//[-+]/_}

	livevar=${esc_pn}_LIVE_REPO
	EGIT_REPO_URI=${!livevar:-${EGIT_REPO_URI}}
	[[ ${!livevar} ]] \
		&& ewarn "Using ${livevar}, no support will be provided"

	livevar=${esc_pn}_LIVE_BRANCH
	EGIT_BRANCH=${!livevar:-${EGIT_BRANCH}}
	[[ ${!livevar} ]] \
		&& ewarn "Using ${livevar}, no support will be provided"

	livevar=${esc_pn}_LIVE_COMMIT
	EGIT_COMMIT=${!livevar:-${EGIT_COMMIT}}
	[[ ${!livevar} ]] \
		&& ewarn "Using ${livevar}, no support will be provided"

	# Migration helpers. Remove them when git-2 is removed.

	if [[ ${EGIT_SOURCEDIR} ]]; then
		eerror "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR. While updating"
		eerror "your ebuild, please check whether the variable is necessary at all"
		eerror "since the default has been changed from \${S} to \${WORKDIR}/\${P}."
		eerror "Therefore, proper setting of S may be sufficient."
		die "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR."
	fi

	if [[ ${EGIT_MASTER} ]]; then
		eerror "EGIT_MASTER has been removed. Instead, the upstream default (HEAD)"
		eerror "is used by the eclass. Please remove the assignment or use EGIT_BRANCH"
		eerror "as necessary."
		die "EGIT_MASTER has been removed."
	fi

	if [[ ${EGIT_HAS_SUBMODULES} ]]; then
		eerror "EGIT_HAS_SUBMODULES has been removed. The eclass no longer needs"
		eerror "to switch the clone type in order to support submodules and therefore"
		eerror "submodules are detected and fetched automatically."
		die "EGIT_HAS_SUBMODULES is no longer necessary."
	fi

	if [[ ${EGIT_PROJECT} ]]; then
		eerror "EGIT_PROJECT has been removed. Instead, the eclass determines"
		eerror "the local clone path using path in canonical EGIT_REPO_URI."
		eerror "If the current algorithm causes issues for you, please report a bug."
		die "EGIT_PROJECT is no longer necessary."
	fi

	if [[ ${EGIT_BOOTSTRAP} ]]; then
		eerror "EGIT_BOOTSTRAP has been removed. Please create proper src_prepare()"
		eerror "instead."
		die "EGIT_BOOTSTRAP has been removed."
	fi

	if [[ ${EGIT_NOUNPACK} ]]; then
		eerror "EGIT_NOUNPACK has been removed. The eclass no longer calls default"
		eerror "unpack function. If necessary, please declare proper src_unpack()."
		die "EGIT_NOUNPACK has been removed."
	fi
}

# @FUNCTION: _git-r3_set_gitdir
# @USAGE: <repo-uri>
# @INTERNAL
# @DESCRIPTION:
# Obtain the local repository path and set it as GIT_DIR. Creates
# a new repository if necessary.
#
# <repo-uri> may be used to compose the path. It should therefore be
# a canonical URI to the repository.
_git-r3_set_gitdir() {
	debug-print-function ${FUNCNAME} "$@"

	local repo_name=${1#*://*/}

	# strip the trailing slash
	repo_name=${repo_name%/}

	# strip common prefixes to make paths more likely to match
	# e.g. git://X/Y.git vs https://X/git/Y.git
	# (but just one of the prefixes)
	case "${repo_name}" in
		# gnome.org... who else?
		browse/*) repo_name=${repo_name#browse/};;
		# cgit can proxy requests to git
		cgit/*) repo_name=${repo_name#cgit/};;
		# pretty common
		git/*) repo_name=${repo_name#git/};;
		# gentoo.org
		gitroot/*) repo_name=${repo_name#gitroot/};;
		# google code, sourceforge
		p/*) repo_name=${repo_name#p/};;
		# kernel.org
		pub/scm/*) repo_name=${repo_name#pub/scm/};;
	esac
	# ensure a .git suffix, same reason
	repo_name=${repo_name%.git}.git
	# now replace all the slashes
	repo_name=${repo_name//\//_}

	local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
	: ${EGIT3_STORE_DIR:=${distdir}/git3-src}

	GIT_DIR=${EGIT3_STORE_DIR}/${repo_name}

	if [[ ! -d ${EGIT3_STORE_DIR} ]]; then
		(
			addwrite /
			mkdir -m0755 -p "${EGIT3_STORE_DIR}" || die
		) || die "Unable to create ${EGIT3_STORE_DIR}"
	fi

	addwrite "${EGIT3_STORE_DIR}"
	if [[ ! -d ${GIT_DIR} ]]; then
		mkdir "${GIT_DIR}" || die
		git init --bare || die
	fi
}

# @FUNCTION: _git-r3_set_submodules
# @USAGE: <file-contents>
# @INTERNAL
# @DESCRIPTION:
# Parse .gitmodules contents passed as <file-contents>
# as in "$(cat .gitmodules)"). Composes a 'submodules' array that
# contains in order (name, URL, path) for each submodule.
_git-r3_set_submodules() {
	debug-print-function ${FUNCNAME} "$@"

	local data=${1}

	# ( name url path ... )
	submodules=()

	local l
	while read l; do
		# submodule.<path>.path=<path>
		# submodule.<path>.url=<url>
		[[ ${l} == submodule.*.url=* ]] || continue

		l=${l#submodule.}
		local subname=${l%%.url=*}

		# skip modules that have 'update = none', bug #487262.
		local upd=$(echo "${data}" | git config -f /dev/fd/0 \
			submodule."${subname}".update)
		[[ ${upd} == none ]] && continue

		submodules+=(
			"${subname}"
			"$(echo "${data}" | git config -f /dev/fd/0 \
				submodule."${subname}".url || die)"
			"$(echo "${data}" | git config -f /dev/fd/0 \
				submodule."${subname}".path || die)"
		)
	done < <(echo "${data}" | git config -f /dev/fd/0 -l || die)
}

# @FUNCTION: _git-r3_is_local_repo
# @USAGE: <repo-uri>
# @INTERNAL
# @DESCRIPTION:
# Determine whether the given URI specifies a local (on-disk)
# repository.
_git-r3_is_local_repo() {
	debug-print-function ${FUNCNAME} "$@"

	local uri=${1}

	[[ ${uri} == file://* || ${uri} == /* ]]
}

# @FUNCTION: _git-r3_find_head
# @USAGE: <head-ref>
# @INTERNAL
# @DESCRIPTION:
# 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}
	local head_hash=$(git rev-parse --verify ${1} || die)
	local matching_ref

	# TODO: some transports support peeking at symbolic remote refs
	# find a way to use that rather than guessing

	# (based on guess_remote_head() in git-1.9.0/remote.c)
	local h ref
	while read h ref; do
		# look for matching head
		if [[ ${h} == ${head_hash} ]]; then
			# either take the first matching ref, or master if it is there
			if [[ ! ${matching_ref} || ${ref} == refs/heads/master ]]; then
				matching_ref=${ref}
			fi
		fi
	done

	if [[ ! ${matching_ref} ]]; then
		die "Unable to find a matching branch for remote HEAD (${head_hash})"
	fi

	echo "${matching_ref}"
}

# @FUNCTION: git-r3_fetch
# @USAGE: [<repo-uri> [<remote-ref> [<local-id>]]]
# @DESCRIPTION:
# Fetch new commits to the local clone of repository.
#
# <repo-uri> specifies the repository URIs to fetch from, as a space-
# -separated list. The first URI will be used as repository group
# identifier and therefore must be used consistently. When not
# specified, defaults to ${EGIT_REPO_URI}.
#
# <remote-ref> specifies the remote ref or commit id to fetch.
# It is preferred to use 'refs/heads/<branch-name>' for branches
# and 'refs/tags/<tag-name>' for tags. Other options are 'HEAD'
# for upstream default branch and hexadecimal commit SHA1. Defaults
# to the first of EGIT_COMMIT, EGIT_BRANCH or literal 'HEAD' that
# is set to a non-null value.
#
# <local-id> specifies the local branch identifier that will be used to
# locally store the fetch result. It should be unique to multiple
# fetches within the repository that can be performed at the same time
# (including parallel merges). It defaults to ${CATEGORY}/${PN}/${SLOT%/*}.
# This default should be fine unless you are fetching multiple trees
# from the same repository in the same ebuild.
#
# The fetch operation will affect the EGIT_STORE only. It will not touch
# the working copy, nor export any environment variables.
# If the repository contains submodules, they will be fetched
# recursively.
git-r3_fetch() {
	debug-print-function ${FUNCNAME} "$@"

	[[ ${EVCS_OFFLINE} ]] && return

	local repos
	if [[ ${1} ]]; then
		repos=( ${1} )
	elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
		repos=( "${EGIT_REPO_URI[@]}" )
	else
		repos=( ${EGIT_REPO_URI} )
	fi

	local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
	local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
	local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
	local local_ref=refs/git-r3/${local_id}/__main__

	[[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"

	local -x GIT_DIR
	_git-r3_set_gitdir "${repos[0]}"

	# prepend the local mirror if applicable
	if [[ ${EGIT_MIRROR_URI} ]]; then
		repos=(
			"${EGIT_MIRROR_URI%/}/${GIT_DIR##*/}"
			"${repos[@]}"
		)
	fi

	# try to fetch from the remote
	local r success
	for r in "${repos[@]}"; do
		einfo "Fetching ${r} ..."

		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 or shallow
			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
					if [[ ${branch} ]]; then
						fetch_l=${branch}
					else
						fetch_l=HEAD
					fi

					# fetching by commit in shallow mode? can't do.
					if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
						local EGIT_CLONE_TYPE=single
					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

		if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
			# use '--depth 1' when fetching a new branch
			if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
			then
				fetch_command+=( --depth 1 )
			fi
		else # non-shallow mode
			if [[ -f ${GIT_DIR}/shallow ]]; then
				fetch_command+=( --unshallow )
			fi
		fi

		set -- "${fetch_command[@]}"
		echo "${@}" >&2
		if "${@}"; then
			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 or shallow
				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=$(
				git rev-parse --verify --symbolic-full-name "${remote_ref}"
			)

			if [[ ${full_remote_ref} ]]; then
				# when we are given a ref, create a symbolic ref
				# so that we preserve the actual argument
				set -- git symbolic-ref "${local_ref}" "${full_remote_ref}"
			else
				# otherwise, we were likely given a commit id
				set -- git update-ref --no-deref "${local_ref}" "${remote_ref}"
			fi

			echo "${@}" >&2
			if ! "${@}"; then
				die "Referencing ${remote_ref} failed (wrong ref?)."
			fi

			success=1
			break
		fi
	done
	[[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI"

	# recursively fetch submodules
	if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then
		local submodules
		_git-r3_set_submodules \
			"$(git cat-file -p "${local_ref}":.gitmodules || die)"

		while [[ ${submodules[@]} ]]; do
			local subname=${submodules[0]}
			local url=${submodules[1]}
			local path=${submodules[2]}
			local commit=$(git rev-parse "${local_ref}:${path}")

			if [[ ! ${commit} ]]; then
				die "Unable to get commit id for submodule ${subname}"
			fi
			if [[ ${url} == ./* || ${url} == ../* ]]; then
				local subrepos=( "${repos[@]/%//${url}}" )
			else
				local subrepos=( "${url}" )
			fi

			git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}"

			submodules=( "${submodules[@]:3}" ) # shift
		done
	fi
}

# @FUNCTION: git-r3_checkout
# @USAGE: [<repo-uri> [<checkout-path> [<local-id>]]]
# @DESCRIPTION:
# Check the previously fetched tree to the working copy.
#
# <repo-uri> specifies the repository URIs, as a space-separated list.
# The first URI will be used as repository group identifier
# and therefore must be used consistently with git-r3_fetch.
# The remaining URIs are not used and therefore may be omitted.
# When not specified, defaults to ${EGIT_REPO_URI}.
#
# <checkout-path> specifies the path to place the checkout. It defaults
# to ${EGIT_CHECKOUT_DIR} if set, otherwise to ${WORKDIR}/${P}.
#
# <local-id> needs to specify the local identifier that was used
# for respective git-r3_fetch.
#
# The checkout operation will write to the working copy, and export
# the repository state into the environment. If the repository contains
# submodules, they will be checked out recursively.
git-r3_checkout() {
	debug-print-function ${FUNCNAME} "$@"

	local repos
	if [[ ${1} ]]; then
		repos=( ${1} )
	elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
		repos=( "${EGIT_REPO_URI[@]}" )
	else
		repos=( ${EGIT_REPO_URI} )
	fi

	local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}}
	local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}

	local -x GIT_DIR
	_git-r3_set_gitdir "${repos[0]}"

	einfo "Checking out ${repos[0]} to ${out_dir} ..."

	if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then
		if [[ ${EVCS_OFFLINE} ]]; then
			die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE."
		else
			die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?"
		fi
	fi
	local remote_ref=$(
		git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__
	)
	local new_commit_id=$(
		git rev-parse --verify refs/git-r3/"${local_id}"/__main__
	)

	git-r3_sub_checkout() {
		local orig_repo=${GIT_DIR}
		local -x GIT_DIR=${out_dir}/.git
		local -x GIT_WORK_TREE=${out_dir}

		mkdir -p "${out_dir}" || die

		# use git init+fetch instead of clone since the latter doesn't like
		# non-empty directories.

		git init --quiet || die
		# setup 'alternates' to avoid copying objects
		echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die
		# now copy the refs
		# [htn]* safely catches heads, tags, notes without complaining
		# on non-existing ones, and omits internal 'git-r3' ref
		cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die

		# (no need to copy HEAD, we will set it via checkout)

		if [[ -f ${orig_repo}/shallow ]]; then
			cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die
		fi

		set -- git checkout --quiet
		if [[ ${remote_ref} ]]; then
			set -- "${@}" "${remote_ref#refs/heads/}"
		else
			set -- "${@}" "${new_commit_id}"
		fi
		echo "${@}" >&2
		"${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed"
	}
	git-r3_sub_checkout

	local old_commit_id=$(
		git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__
	)
	if [[ ! ${old_commit_id} ]]; then
		echo "GIT NEW branch -->"
		echo "   repository:               ${repos[0]}"
		echo "   at the commit:            ${new_commit_id}"
	else
		# diff against previous revision
		echo "GIT update -->"
		echo "   repository:               ${repos[0]}"
		# write out message based on the revisions
		if [[ "${old_commit_id}" != "${new_commit_id}" ]]; then
			echo "   updating from commit:     ${old_commit_id}"
			echo "   to commit:                ${new_commit_id}"

			git --no-pager diff --stat \
				${old_commit_id}..${new_commit_id}
		else
			echo "   at the commit:            ${new_commit_id}"
		fi
	fi
	git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die

	# recursively checkout submodules
	if [[ -f ${out_dir}/.gitmodules ]]; then
		local submodules
		_git-r3_set_submodules \
			"$(<"${out_dir}"/.gitmodules)"

		while [[ ${submodules[@]} ]]; do
			local subname=${submodules[0]}
			local url=${submodules[1]}
			local path=${submodules[2]}

			if [[ ${url} == ./* || ${url} == ../* ]]; then
				url=${repos[0]%%/}/${url}
			fi

			git-r3_checkout "${url}" "${out_dir}/${path}" \
				"${local_id}/${subname}"

			submodules=( "${submodules[@]:3}" ) # shift
		done
	fi

	# keep this *after* submodules
	export EGIT_DIR=${GIT_DIR}
	export EGIT_VERSION=${new_commit_id}
}

# @FUNCTION: git-r3_peek_remote_ref
# @USAGE: [<repo-uri> [<remote-ref>]]
# @DESCRIPTION:
# Peek the reference in the remote repository and print the matching
# (newest) commit SHA1.
#
# <repo-uri> specifies the repository URIs to fetch from, as a space-
# -separated list. When not specified, defaults to ${EGIT_REPO_URI}.
#
# <remote-ref> specifies the remote ref to peek.  It is preferred to use
# 'refs/heads/<branch-name>' for branches and 'refs/tags/<tag-name>'
# for tags. Alternatively, 'HEAD' may be used for upstream default
# branch. Defaults to the first of EGIT_COMMIT, EGIT_BRANCH or literal
# 'HEAD' that is set to a non-null value.
#
# The operation will be done purely on the remote, without using local
# storage. If commit SHA1 is provided as <remote-ref>, the function will
# fail due to limitations of git protocol.
#
# On success, the function returns 0 and writes hexadecimal commit SHA1
# to stdout. On failure, the function returns 1.
git-r3_peek_remote_ref() {
	debug-print-function ${FUNCNAME} "$@"

	local repos
	if [[ ${1} ]]; then
		repos=( ${1} )
	elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then
		repos=( "${EGIT_REPO_URI[@]}" )
	else
		repos=( ${EGIT_REPO_URI} )
	fi

	local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
	local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}

	[[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"

	local r success
	for r in "${repos[@]}"; do
		einfo "Peeking ${remote_ref} on ${r} ..." >&2

		local is_branch lookup_ref
		if [[ ${remote_ref} == refs/heads/* || ${remote_ref} == HEAD ]]
		then
			is_branch=1
			lookup_ref=${remote_ref}
		else
			# ls-remote by commit is going to fail anyway,
			# so we may as well pass refs/tags/ABCDEF...
			lookup_ref=refs/tags/${remote_ref}
		fi

		# split on whitespace
		local ref=(
			$(git ls-remote "${r}" "${lookup_ref}")
		)

		if [[ ${ref[0]} ]]; then
			echo "${ref[0]}"
			return 0
		fi
	done

	return 1
}

git-r3_src_fetch() {
	debug-print-function ${FUNCNAME} "$@"

	if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then
		ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider"
		ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use"
		ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones"
		ewarn "when git-2 eclass becomes deprecated."
	fi

	_git-r3_env_setup
	git-r3_fetch
}

git-r3_src_unpack() {
	debug-print-function ${FUNCNAME} "$@"

	_git-r3_env_setup
	git-r3_src_fetch
	git-r3_checkout
}

# https://bugs.gentoo.org/show_bug.cgi?id=482666
git-r3_pkg_outofdate() {
	debug-print-function ${FUNCNAME} "$@"

	local new_commit_id=$(git-r3_peek_remote_ref)
	ewarn "old: ${EGIT_VERSION}"
	ewarn "new: ${new_commit_id}"
	[[ ${new_commit_id} && ${old_commit_id} ]] || return 2

	[[ ${EGIT_VERSION} != ${new_commit_id} ]]
}

_GIT_R3=1
fi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch.
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch Michał Górny
@ 2014-02-26 15:22   ` Ulrich Mueller
  2014-02-26 15:26     ` Michał Górny
  0 siblings, 1 reply; 24+ messages in thread
From: Ulrich Mueller @ 2014-02-26 15:22 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

In _git-r3_update_head():

> +	local head_hash=$(git rev-parse --verify ${1} || die)

Maybe it's overkill, but I'd put double quotes around the ${1} here.

Ulrich


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch.
  2014-02-26 15:22   ` Ulrich Mueller
@ 2014-02-26 15:26     ` Michał Górny
  0 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 15:26 UTC (permalink / raw
  To: gentoo-dev; +Cc: ulm

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

Dnia 2014-02-26, o godz. 16:22:25
Ulrich Mueller <ulm@gentoo.org> napisał(a):

> In _git-r3_update_head():
> 
> > +	local head_hash=$(git rev-parse --verify ${1} || die)
> 
> Maybe it's overkill, but I'd put double quotes around the ${1} here.

Good catch. Fixed now.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type Michał Górny
@ 2014-02-26 15:29   ` Ulrich Mueller
  2014-02-26 15:33     ` Alex Xu
  2014-02-26 15:34     ` Michał Górny
  2014-02-26 23:53   ` hasufell
  1 sibling, 2 replies; 24+ messages in thread
From: Ulrich Mueller @ 2014-02-26 15:29 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

In _git-r3_env_setup():

> +		single)
> +			if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
> +				ewarn "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
> +				EGIT_CLONE_TYPE=single
> +			fi
> +			;;
> +		mirror)
> +			if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
> +				ewarn "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"

This is part of normal operation, so maybe downgrade these ewarns to
elog? There's nothing the user can do to suppress these warnings,
apart from changing his global setting for the clone type, which we
won't want him to do.

Ulrich


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 15:29   ` Ulrich Mueller
@ 2014-02-26 15:33     ` Alex Xu
  2014-02-26 15:34     ` Michał Górny
  1 sibling, 0 replies; 24+ messages in thread
From: Alex Xu @ 2014-02-26 15:33 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

On 26/02/14 10:29 AM, Ulrich Mueller wrote:
> This is part of normal operation, so maybe downgrade these ewarns to
> elog? There's nothing the user can do to suppress these warnings,
> apart from changing his global setting for the clone type, which we
> won't want him to do.

You can put EGIT_CLONE_TYPE in package.env.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 15:29   ` Ulrich Mueller
  2014-02-26 15:33     ` Alex Xu
@ 2014-02-26 15:34     ` Michał Górny
  1 sibling, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 15:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: ulm

[-- Attachment #1: Type: text/plain, Size: 784 bytes --]

Dnia 2014-02-26, o godz. 16:29:54
Ulrich Mueller <ulm@gentoo.org> napisał(a):

> In _git-r3_env_setup():
> 
> > +		single)
> > +			if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
> > +				ewarn "git-r3: ebuild needs to be cloned in 'single' mode, adjusting"
> > +				EGIT_CLONE_TYPE=single
> > +			fi
> > +			;;
> > +		mirror)
> > +			if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then
> > +				ewarn "git-r3: ebuild needs to be cloned in 'mirror' mode, adjusting"
> 
> This is part of normal operation, so maybe downgrade these ewarns to
> elog? There's nothing the user can do to suppress these warnings,
> apart from changing his global setting for the clone type, which we
> won't want him to do.

Seems fine. Maybe even 'einfo'?

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 11/11] Disable shallow clones of local repositories.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (10 preceding siblings ...)
  2014-02-26 15:19 ` [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
@ 2014-02-26 23:42 ` Michał Górny
  2014-02-27  0:09 ` [gentoo-dev] [PATCH git-r3 12/12] Clarify which EGIT_CLONE_TYPE variables are set by who Michał Górny
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-26 23:42 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

It was already proven before that trying to fetch those with '--depth'
result in sandbox violations due to git writing temporary files
in the repository. Instead, fetch them as 'single'.
---
 eclass/git-r3.eclass | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 37138a9..7ab94d2 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -507,9 +507,13 @@ git-r3_fetch() {
 		fi
 
 		if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then
-			# use '--depth 1' when fetching a new branch
-			if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
+			if _git-r3_is_local_repo; then
+				# '--depth 1' causes sandbox violations with local repos
+				# bug #491260
+				local EGIT_CLONE_TYPE=single
+			elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]]
 			then
+				# use '--depth 1' when fetching a new branch
 				fetch_command+=( --depth 1 )
 			fi
 		else # non-shallow mode
-- 
1.9.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type Michał Górny
  2014-02-26 15:29   ` Ulrich Mueller
@ 2014-02-26 23:53   ` hasufell
  2014-02-27  0:09     ` Michał Górny
  1 sibling, 1 reply; 24+ messages in thread
From: hasufell @ 2014-02-26 23:53 UTC (permalink / raw
  To: gentoo-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Micha? Górny:
> Use-cases include Google Code (that doesn't support shallow clones)
> and random build systems that play with history and 'git
> describe'.
> 
> However, please use this sparingly. When the build can't go on
> without non-shallow clone, sure. But if it only results in
> non-pretty versions, I think users choosing EGIT_CLONE_TYPE=shallow
> explicitly are ready to deal with the fallout.

Afaiu EGIT_MIN_CLONE_TYPE is not something the user should mess with.
Can we make that more clear somehow? I already see related bug reports
by people doing weird things in make.conf.

Or even developers mixing these two up.
-----BEGIN PGP SIGNATURE-----

iQEcBAEBCgAGBQJTDn5yAAoJEFpvPKfnPDWzXSAH/jeogFcURQvW8/wOpd0Ejd5X
vkX/g0nhwJj7+q4t9FHOtvhw95KvaMvqd7t5G11SRKu/RqgfvjN2RdnfPAAaYIuZ
oQ04gopmHvuTxEF/FOrWv0aJ5oF9f2bpxesnsSgSRI4SVIeII9sjHyPowEOS+NH4
i1HPaMFG3OitI0yHBOFAqGhbPoNjNPrb2n3UVMUFnrM5bPZnj6MDUyFhc1p35fjt
BVT7WWvDH6wKg0pYuHj6bPK6zyQAADYKF0VZOMfw+4UadWT7iGfjJE68JGW4Dm9s
HUDqDg/Kda4Jexb/U2DoIpwXrKU79K7aUxSxUSTKV7UqSV+BmJpsGcVsddMJgu4=
=NnXq
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [gentoo-dev] [PATCH git-r3 12/12] Clarify which EGIT_CLONE_TYPE variables are set by who.
  2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
                   ` (11 preceding siblings ...)
  2014-02-26 23:42 ` [gentoo-dev] [PATCH git-r3 11/11] Disable shallow clones of local repositories Michał Górny
@ 2014-02-27  0:09 ` Michał Górny
  12 siblings, 0 replies; 24+ messages in thread
From: Michał Górny @ 2014-02-27  0:09 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

As requested by hasufell.
---
 eclass/git-r3.eclass | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
index 7ab94d2..01a6461 100644
--- a/eclass/git-r3.eclass
+++ b/eclass/git-r3.eclass
@@ -37,6 +37,9 @@ fi
 # Type of clone that should be used against the remote repository.
 # This can be either of: 'mirror', 'single', 'shallow'.
 #
+# This is intended to be set by user in make.conf. Ebuilds are supposed
+# to set EGIT_MIN_CLONE_TYPE if necessary instead.
+#
 # The 'mirror' type clones all remote branches and tags with complete
 # history and all notes. EGIT_COMMIT can specify any commit hash.
 # Upstream-removed branches and tags are purged from the local clone
@@ -65,6 +68,9 @@ fi
 # later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses
 # EGIT_MIN_CLONE_TYPE instead.
 #
+# This variable is intended to be used by ebuilds only. Users are
+# supposed to set EGIT_CLONE_TYPE instead.
+#
 # A common case is to use 'single' whenever the build system requires
 # access to full branch history or the remote (Google Code) does not
 # support shallow clones. Please use sparingly, and to fix fatal errors
-- 
1.9.0



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-26 23:53   ` hasufell
@ 2014-02-27  0:09     ` Michał Górny
  2014-02-27  0:23       ` hasufell
  0 siblings, 1 reply; 24+ messages in thread
From: Michał Górny @ 2014-02-27  0:09 UTC (permalink / raw
  To: gentoo-dev; +Cc: hasufell

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

Dnia 2014-02-26, o godz. 23:53:22
hasufell <hasufell@gentoo.org> napisał(a):

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
> 
> Micha? Górny:
> > Use-cases include Google Code (that doesn't support shallow clones)
> > and random build systems that play with history and 'git
> > describe'.
> > 
> > However, please use this sparingly. When the build can't go on
> > without non-shallow clone, sure. But if it only results in
> > non-pretty versions, I think users choosing EGIT_CLONE_TYPE=shallow
> > explicitly are ready to deal with the fallout.
> 
> Afaiu EGIT_MIN_CLONE_TYPE is not something the user should mess with.
> Can we make that more clear somehow? I already see related bug reports
> by people doing weird things in make.conf.
> 
> Or even developers mixing these two up.

I assumed 'supported by the ebuild' implies it's for ebuild to set. But
I can make it explicit, sure.

-- 
Best regards,
Michał Górny

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 966 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type.
  2014-02-27  0:09     ` Michał Górny
@ 2014-02-27  0:23       ` hasufell
  0 siblings, 0 replies; 24+ messages in thread
From: hasufell @ 2014-02-27  0:23 UTC (permalink / raw
  To: gentoo-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Michał Górny:
> Dnia 2014-02-26, o godz. 23:53:22 hasufell <hasufell@gentoo.org>
> napisał(a):
> 
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
>> 
>> Micha? Górny:
>>> Use-cases include Google Code (that doesn't support shallow
>>> clones) and random build systems that play with history and
>>> 'git describe'.
>>> 
>>> However, please use this sparingly. When the build can't go on 
>>> without non-shallow clone, sure. But if it only results in 
>>> non-pretty versions, I think users choosing
>>> EGIT_CLONE_TYPE=shallow explicitly are ready to deal with the
>>> fallout.
>> 
>> Afaiu EGIT_MIN_CLONE_TYPE is not something the user should mess
>> with. Can we make that more clear somehow? I already see related
>> bug reports by people doing weird things in make.conf.
>> 
>> Or even developers mixing these two up.
> 
> I assumed 'supported by the ebuild' implies it's for ebuild to set.
> But I can make it explicit, sure.
> 

Thanks for your work.
-----BEGIN PGP SIGNATURE-----

iQEcBAEBCgAGBQJTDoWPAAoJEFpvPKfnPDWzNz4H/Rjm3tImvgw9dVbdeBOFh4lQ
l4lhHDtvM7vNJirChGogZIZUOm8hWSoGEZ2qfjZtFpm8Ywvbt1cbgKllOlUYMyOP
ZPciTMmhfRiFAYkiVF1B2xcvKCeJufKiXPcm8iVUEQ3Q6sZ4doNSnXEW/un3MH4E
h69H1FG21A+ZRcdc5jA0ETrT/bojODrqLuDwe6eMEuXVpAlpnQFA7KPZK3ZOq7dr
d5gOtC6gPGr5HjWNp31w1QmzKrAqUGTdrmWW8vgvK4daufWjxKuj0+K4SEjfsNQk
lB+AM+c7D58SvTy57Ey8GKv8QhVO6PSR1zty8bTzoCms6pvIf3DqNf6PJjOzd04=
=oBmI
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-02-27  0:23 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-26 11:55 [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 01/10] Clarify that ebuilds are not supposed to set EGIT3_STORE_DIR Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 02/10] Replace 'git fetch' checkout with more efficient pseudo-shared fetch Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 03/10] Properly support non-master default branch Michał Górny
2014-02-26 15:22   ` Ulrich Mueller
2014-02-26 15:26     ` Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 04/10] Support EGIT_MIRROR_URI to specify local git mirror Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 05/10] Introduce EGIT_CLONE_TYPE for future use Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 06/10] Support single-branch mode Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 07/10] Support shallow clones Michał Górny
2014-02-26 12:39   ` Alex Xu
2014-02-26 12:47     ` Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 08/10] Auto-unshallow when fetch-by-commit is requested Michał Górny
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 09/10] Add EGIT_MIN_CLONE_TYPE to support ebuilds requiring greater clone type Michał Górny
2014-02-26 15:29   ` Ulrich Mueller
2014-02-26 15:33     ` Alex Xu
2014-02-26 15:34     ` Michał Górny
2014-02-26 23:53   ` hasufell
2014-02-27  0:09     ` Michał Górny
2014-02-27  0:23       ` hasufell
2014-02-26 11:59 ` [gentoo-dev] [PATCH git-r3 10/10] Use '+'-refs to force updates on fetch Michał Górny
2014-02-26 15:19 ` [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support Michał Górny
2014-02-26 23:42 ` [gentoo-dev] [PATCH git-r3 11/11] Disable shallow clones of local repositories Michał Górny
2014-02-27  0:09 ` [gentoo-dev] [PATCH git-r3 12/12] Clarify which EGIT_CLONE_TYPE variables are set by who Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox