diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-11-18 10:14:31 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-11-28 10:14:47 +0100 |
commit | 17d7a4564177b1985e4b7e8f23a8efbc4d5c32ae (patch) | |
tree | 35d847d3dfea6d2a53e6db43675a402c9f12a443 /eclass/git-r3.eclass | |
parent | sys-libs/libcxxabi: Utilize partial git checkout (diff) | |
download | gentoo-17d7a4564177b1985e4b7e8f23a8efbc4d5c32ae.tar.gz gentoo-17d7a4564177b1985e4b7e8f23a8efbc4d5c32ae.tar.bz2 gentoo-17d7a4564177b1985e4b7e8f23a8efbc4d5c32ae.zip |
git-r3.eclass: Support more flexible EGIT_OVERRIDE_* APIs for user
Introduce a new, more flexible override API in git-r3, in replacement
of the LIVE_* API that was pretty much a legacy of git-2. This means to
solve the two major limitations of the old API:
1. The variables were based on package names without categories.
Therefore, they weren't suitable whenever two packages had the same
category. This is quite common when dealing with various programming
language bindings/reimplementations, and we can't really rely on every
new programming language inventing its own VCS.
2. The overrides weren't suitable for packages checking out multiple
repositories (LLVM, wine, glibc).
The new mode for overrides uses the repository name (as guessed
by git-r3) transformed into correct variable name. The specifically
defined variables are:
- EGIT_OVERRIDE_REPO_${NAME} -- to override the repository URI,
- EGIT_OVERRIDE_BRANCH_${NAME} -- to override the branch,
- EGIT_OVERRIDE_COMMIT_${NAME} -- to override the commit id or tag,
- EGIT_OVERRIDE_COMMIT_DATE_${NAME} -- to request last commit older than
the specified date.
Diffstat (limited to 'eclass/git-r3.eclass')
-rw-r--r-- | eclass/git-r3.eclass | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass index caf4e8d003e0..55a987b79545 100644 --- a/eclass/git-r3.eclass +++ b/eclass/git-r3.eclass @@ -553,6 +553,7 @@ _git-r3_is_local_repo() { git-r3_fetch() { debug-print-function ${FUNCNAME} "$@" + # process repos first since we create repo_name from it local repos if [[ ${1} ]]; then repos=( ${1} ) @@ -562,12 +563,6 @@ git-r3_fetch() { 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__ - local commit_date=${4:-${EGIT_COMMIT_DATE}} - [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" local r @@ -591,6 +586,54 @@ git-r3_fetch() { ) fi + # get the default values for the common variables and override them + local branch_name=${EGIT_BRANCH} + local commit_id=${2:-${EGIT_COMMIT}} + local commit_date=${4:-${EGIT_COMMIT_DATE}} + + # support new override API for EAPI 6+ + if ! has "${EAPI:-0}" 0 1 2 3 4 5; then + # get the name and do some more processing: + # 1) kill .git suffix, + # 2) underscore (remaining) non-variable characters, + # 3) add preceding underscore if it starts with a digit, + # 4) uppercase. + local override_name=${GIT_DIR##*/} + override_name=${override_name%.git} + override_name=${override_name//[^a-zA-Z0-9_]/_} + override_name=${override_name^^} + + local varmap=( + REPO:repos + BRANCH:branch_name + COMMIT:commit_id + COMMIT_DATE:commit_date + ) + + local localvar livevar live_warn= + for localvar in "${varmap[@]}"; do + livevar=EGIT_OVERRIDE_${localvar%:*}_${override_name} + localvar=${localvar#*:} + + if [[ -n ${!livevar} ]]; then + [[ ${localvar} == repos ]] && repos=() + live_warn=1 + ewarn "Using ${livevar}=${!livevar}" + declare "${localvar}=${!livevar}" + fi + done + + if [[ ${live_warn} ]]; then + ewarn "No support will be provided." + fi + fi + + # set final variables after applying overrides + local branch=${branch_name:+refs/heads/${branch_name}} + local remote_ref=${commit_id:-${branch:-HEAD}} + local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} + local local_ref=refs/git-r3/${local_id}/__main__ + # try to fetch from the remote local success saved_umask if [[ ${EVCS_UMASK} ]]; then |