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 EGIT_SUBMODULES to filter used submodules, #497164
Date: Mon, 23 May 2016 19:54:37
Message-Id: 20160523195419.11522-1-mgorny@gentoo.org
1 ---
2 eclass/git-r3.eclass | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-
3 1 file changed, 52 insertions(+), 1 deletion(-)
4
5 diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
6 index 957ff08..61218a8 100644
7 --- a/eclass/git-r3.eclass
8 +++ b/eclass/git-r3.eclass
9 @@ -165,6 +165,36 @@ fi
10 #
11 # EGIT_CHECKOUT_DIR=${WORKDIR}/${P}
12
13 +# @ECLASS-VARIABLE: EGIT_SUBMODULES
14 +# @DEFAULT_UNSET
15 +# @DESCRIPTION:
16 +# An array of inclusive and exclusive wildcards on submodule names,
17 +# stating which submodules are fetched and checked out. Exclusions
18 +# start with '-', and exclude previously matched submodules.
19 +#
20 +# If unset, all submodules are enabled. Empty list disables all
21 +# submodules. In order to use an exclude-only list, start the array
22 +# with '*'.
23 +#
24 +# Remember that wildcards need to be quoted in order to prevent filename
25 +# expansion.
26 +#
27 +# Examples:
28 +# @CODE
29 +# # Disable all submodules
30 +# EGIT_SUBMODULES=()
31 +#
32 +# # Include only foo and bar
33 +# EGIT_SUBMODULES=( foo bar )
34 +#
35 +# # Use all submodules except for test-* but include test-lib
36 +# EGIT_SUBMODULES=( '*' '-test-*' test-lib )
37 +# @CODE
38 +if [[ ${EGIT_SUBMODULES[@]+1} && $(declare -p EGIT_SUBMODULES) != "declare -a"* ]]
39 +then
40 + die 'EGIT_SUBMODULES must be an array.'
41 +fi
42 +
43 # @FUNCTION: _git-r3_env_setup
44 # @INTERNAL
45 # @DESCRIPTION:
46 @@ -243,7 +273,8 @@ _git-r3_env_setup() {
47 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
48 eerror "EGIT_HAS_SUBMODULES has been removed. The eclass no longer needs"
49 eerror "to switch the clone type in order to support submodules and therefore"
50 - eerror "submodules are detected and fetched automatically."
51 + eerror "submodules are detected and fetched automatically. If you need to"
52 + eerror "disable or filter submodules, see EGIT_SUBMODULES."
53 die "EGIT_HAS_SUBMODULES is no longer necessary."
54 fi
55
56 @@ -357,6 +388,26 @@ _git-r3_set_submodules() {
57 l=${l#submodule.}
58 local subname=${l%%.url=*}
59
60 + # filter out on EGIT_SUBMODULES
61 + if declare -p EGIT_SUBMODULES &>/dev/null; then
62 + local p res= l_res
63 + for p in "${EGIT_SUBMODULES[@]}"; do
64 + if [[ ${p} == -* ]]; then
65 + p=${p#-}
66 + l_res=
67 + else
68 + l_res=1
69 + fi
70 +
71 + [[ ${subname} == ${p} ]] && res=${l_res}
72 + done
73 +
74 + if [[ ! ${res} ]]; then
75 + einfo "Skipping submodule \e[1m${subname}\e[22m"
76 + continue
77 + fi
78 + fi
79 +
80 # skip modules that have 'update = none', bug #487262.
81 local upd=$(echo "${data}" | git config -f /dev/fd/0 \
82 submodule."${subname}".update)
83 --
84 2.8.3

Replies