Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] git-r3.eclass: Support more flexible EGIT_OVERRIDE_* APIs for user
Date: Sat, 18 Nov 2017 09:22:47
Message-Id: 20171118092234.18926-1-mgorny@gentoo.org
1 Introduce a new, more flexible override API in git-r3, in replacement
2 of the LIVE_* API that was pretty much a legacy of git-2. This means to
3 solve the two major limitations of the old API:
4
5 1. The variables were based on package names without categories.
6 Therefore, they weren't suitable whenever two packages had the same
7 category. This is quite common when dealing with various programming
8 language bindings/reimplementations, and we can't really rely on every
9 new programming language inventing its own VCS.
10
11 2. The overrides weren't suitable for packages checking out multiple
12 repositories (LLVM, wine, glibc).
13
14 The new mode for overrides uses the repository name (as guessed
15 by git-r3) transformed into correct variable name. The specifically
16 defined variables are:
17
18 - EGIT_OVERRIDE_REPO_${NAME} -- to override the repository URI,
19
20 - EGIT_OVERRIDE_BRANCH_${NAME} -- to override the branch,
21
22 - EGIT_OVERRIDE_COMMIT_${NAME} -- to override the commit id or tag,
23
24 - EGIT_OVERRIDE_COMMIT_DATE_${NAME} -- to request last commit older than
25 the specified date.
26 ---
27 eclass/git-r3.eclass | 55 ++++++++++++++++++++++++++++++++++++++++++++++------
28 1 file changed, 49 insertions(+), 6 deletions(-)
29
30 diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
31 index caf4e8d003e0..55a987b79545 100644
32 --- a/eclass/git-r3.eclass
33 +++ b/eclass/git-r3.eclass
34 @@ -553,6 +553,7 @@ _git-r3_is_local_repo() {
35 git-r3_fetch() {
36 debug-print-function ${FUNCNAME} "$@"
37
38 + # process repos first since we create repo_name from it
39 local repos
40 if [[ ${1} ]]; then
41 repos=( ${1} )
42 @@ -562,12 +563,6 @@ git-r3_fetch() {
43 repos=( ${EGIT_REPO_URI} )
44 fi
45
46 - local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}}
47 - local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}}
48 - local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
49 - local local_ref=refs/git-r3/${local_id}/__main__
50 - local commit_date=${4:-${EGIT_COMMIT_DATE}}
51 -
52 [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset"
53
54 local r
55 @@ -591,6 +586,54 @@ git-r3_fetch() {
56 )
57 fi
58
59 + # get the default values for the common variables and override them
60 + local branch_name=${EGIT_BRANCH}
61 + local commit_id=${2:-${EGIT_COMMIT}}
62 + local commit_date=${4:-${EGIT_COMMIT_DATE}}
63 +
64 + # support new override API for EAPI 6+
65 + if ! has "${EAPI:-0}" 0 1 2 3 4 5; then
66 + # get the name and do some more processing:
67 + # 1) kill .git suffix,
68 + # 2) underscore (remaining) non-variable characters,
69 + # 3) add preceding underscore if it starts with a digit,
70 + # 4) uppercase.
71 + local override_name=${GIT_DIR##*/}
72 + override_name=${override_name%.git}
73 + override_name=${override_name//[^a-zA-Z0-9_]/_}
74 + override_name=${override_name^^}
75 +
76 + local varmap=(
77 + REPO:repos
78 + BRANCH:branch_name
79 + COMMIT:commit_id
80 + COMMIT_DATE:commit_date
81 + )
82 +
83 + local localvar livevar live_warn=
84 + for localvar in "${varmap[@]}"; do
85 + livevar=EGIT_OVERRIDE_${localvar%:*}_${override_name}
86 + localvar=${localvar#*:}
87 +
88 + if [[ -n ${!livevar} ]]; then
89 + [[ ${localvar} == repos ]] && repos=()
90 + live_warn=1
91 + ewarn "Using ${livevar}=${!livevar}"
92 + declare "${localvar}=${!livevar}"
93 + fi
94 + done
95 +
96 + if [[ ${live_warn} ]]; then
97 + ewarn "No support will be provided."
98 + fi
99 + fi
100 +
101 + # set final variables after applying overrides
102 + local branch=${branch_name:+refs/heads/${branch_name}}
103 + local remote_ref=${commit_id:-${branch:-HEAD}}
104 + local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}}
105 + local local_ref=refs/git-r3/${local_id}/__main__
106 +
107 # try to fetch from the remote
108 local success saved_umask
109 if [[ ${EVCS_UMASK} ]]; then
110 --
111 2.15.0

Replies