1 |
commit: b6f85379dcb5e962ccd6136ab03e2637542eb5e0 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 26 10:09:38 2016 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 26 10:17:57 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b6f85379 |
7 |
|
8 |
git-r3.eclass: Support switching refs with EVCS_OFFLINE, #575898 |
9 |
|
10 |
eclass/git-r3.eclass | 223 ++++++++++++++++++++++++++------------------------- |
11 |
1 file changed, 114 insertions(+), 109 deletions(-) |
12 |
|
13 |
diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass |
14 |
index 99e2ed9..d202e33 100644 |
15 |
--- a/eclass/git-r3.eclass |
16 |
+++ b/eclass/git-r3.eclass |
17 |
@@ -525,8 +525,6 @@ _git-r3_is_local_repo() { |
18 |
git-r3_fetch() { |
19 |
debug-print-function ${FUNCNAME} "$@" |
20 |
|
21 |
- [[ ${EVCS_OFFLINE} ]] && return |
22 |
- |
23 |
local repos |
24 |
if [[ ${1} ]]; then |
25 |
repos=( ${1} ) |
26 |
@@ -561,132 +559,143 @@ git-r3_fetch() { |
27 |
umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}" |
28 |
fi |
29 |
for r in "${repos[@]}"; do |
30 |
- einfo "Fetching \e[1m${r}\e[22m ..." |
31 |
- |
32 |
- local fetch_command=( git fetch "${r}" ) |
33 |
- local clone_type=${EGIT_CLONE_TYPE} |
34 |
- |
35 |
- if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then |
36 |
- eerror "git-r3: fetching from https:// requested. In order to support https," |
37 |
- eerror "dev-vcs/git needs to be built with USE=curl. Example solution:" |
38 |
- eerror |
39 |
- eerror " echo dev-vcs/git curl >> /etc/portage/package.use" |
40 |
- eerror " emerge -1v dev-vcs/git" |
41 |
- die "dev-vcs/git built with USE=curl required." |
42 |
- fi |
43 |
+ if [[ ! ${EVCS_OFFLINE} ]]; then |
44 |
+ einfo "Fetching \e[1m${r}\e[22m ..." |
45 |
+ |
46 |
+ local fetch_command=( git fetch "${r}" ) |
47 |
+ local clone_type=${EGIT_CLONE_TYPE} |
48 |
+ |
49 |
+ if [[ ${r} == https://* ]] && ! ROOT=/ has_version 'dev-vcs/git[curl]'; then |
50 |
+ eerror "git-r3: fetching from https:// requested. In order to support https," |
51 |
+ eerror "dev-vcs/git needs to be built with USE=curl. Example solution:" |
52 |
+ eerror |
53 |
+ eerror " echo dev-vcs/git curl >> /etc/portage/package.use" |
54 |
+ eerror " emerge -1v dev-vcs/git" |
55 |
+ die "dev-vcs/git built with USE=curl required." |
56 |
+ fi |
57 |
|
58 |
- if [[ ${clone_type} == mirror ]]; then |
59 |
- fetch_command+=( |
60 |
- --prune |
61 |
- # mirror the remote branches as local branches |
62 |
- "+refs/heads/*:refs/heads/*" |
63 |
- # pull tags explicitly in order to prune them properly |
64 |
- "+refs/tags/*:refs/tags/*" |
65 |
- # notes in case something needs them |
66 |
- "+refs/notes/*:refs/notes/*" |
67 |
- # and HEAD in case we need the default branch |
68 |
- # (we keep it in refs/git-r3 since otherwise --prune interferes) |
69 |
- "+HEAD:refs/git-r3/HEAD" |
70 |
- ) |
71 |
- else # single or shallow |
72 |
- local fetch_l fetch_r |
73 |
- |
74 |
- if [[ ${remote_ref} == HEAD ]]; then |
75 |
- # HEAD |
76 |
- fetch_l=HEAD |
77 |
- elif [[ ${remote_ref} == refs/* ]]; then |
78 |
- # regular branch, tag or some other explicit ref |
79 |
- fetch_l=${remote_ref} |
80 |
- else |
81 |
- # tag or commit id... |
82 |
- # let ls-remote figure it out |
83 |
- local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}") |
84 |
- |
85 |
- # if it was a tag, ls-remote obtained a hash |
86 |
- if [[ ${tagref} ]]; then |
87 |
- # tag |
88 |
- fetch_l=refs/tags/${remote_ref} |
89 |
+ if [[ ${clone_type} == mirror ]]; then |
90 |
+ fetch_command+=( |
91 |
+ --prune |
92 |
+ # mirror the remote branches as local branches |
93 |
+ "+refs/heads/*:refs/heads/*" |
94 |
+ # pull tags explicitly in order to prune them properly |
95 |
+ "+refs/tags/*:refs/tags/*" |
96 |
+ # notes in case something needs them |
97 |
+ "+refs/notes/*:refs/notes/*" |
98 |
+ # and HEAD in case we need the default branch |
99 |
+ # (we keep it in refs/git-r3 since otherwise --prune interferes) |
100 |
+ "+HEAD:refs/git-r3/HEAD" |
101 |
+ ) |
102 |
+ else # single or shallow |
103 |
+ local fetch_l fetch_r |
104 |
+ |
105 |
+ if [[ ${remote_ref} == HEAD ]]; then |
106 |
+ # HEAD |
107 |
+ fetch_l=HEAD |
108 |
+ elif [[ ${remote_ref} == refs/* ]]; then |
109 |
+ # regular branch, tag or some other explicit ref |
110 |
+ fetch_l=${remote_ref} |
111 |
else |
112 |
- # commit id |
113 |
- # so we need to fetch the whole branch |
114 |
- if [[ ${branch} ]]; then |
115 |
- fetch_l=${branch} |
116 |
+ # tag or commit id... |
117 |
+ # let ls-remote figure it out |
118 |
+ local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}") |
119 |
+ |
120 |
+ # if it was a tag, ls-remote obtained a hash |
121 |
+ if [[ ${tagref} ]]; then |
122 |
+ # tag |
123 |
+ fetch_l=refs/tags/${remote_ref} |
124 |
else |
125 |
- fetch_l=HEAD |
126 |
- fi |
127 |
- |
128 |
- # fetching by commit in shallow mode? can't do. |
129 |
- if [[ ${clone_type} == shallow ]]; then |
130 |
- clone_type=single |
131 |
+ # commit id |
132 |
+ # so we need to fetch the whole branch |
133 |
+ if [[ ${branch} ]]; then |
134 |
+ fetch_l=${branch} |
135 |
+ else |
136 |
+ fetch_l=HEAD |
137 |
+ fi |
138 |
+ |
139 |
+ # fetching by commit in shallow mode? can't do. |
140 |
+ if [[ ${clone_type} == shallow ]]; then |
141 |
+ clone_type=single |
142 |
+ fi |
143 |
fi |
144 |
fi |
145 |
- fi |
146 |
|
147 |
- if [[ ${fetch_l} == HEAD ]]; then |
148 |
- fetch_r=refs/git-r3/HEAD |
149 |
- else |
150 |
- fetch_r=${fetch_l} |
151 |
- fi |
152 |
- |
153 |
- fetch_command+=( |
154 |
- "+${fetch_l}:${fetch_r}" |
155 |
- ) |
156 |
+ if [[ ${fetch_l} == HEAD ]]; then |
157 |
+ fetch_r=refs/git-r3/HEAD |
158 |
+ else |
159 |
+ fetch_r=${fetch_l} |
160 |
+ fi |
161 |
|
162 |
- if [[ ${clone_type} == single+tags ]]; then |
163 |
fetch_command+=( |
164 |
- # pull tags explicitly as requested |
165 |
- "+refs/tags/*:refs/tags/*" |
166 |
+ "+${fetch_l}:${fetch_r}" |
167 |
) |
168 |
- fi |
169 |
- fi |
170 |
|
171 |
- if [[ ${clone_type} == shallow ]]; then |
172 |
- if _git-r3_is_local_repo; then |
173 |
- # '--depth 1' causes sandbox violations with local repos |
174 |
- # bug #491260 |
175 |
- clone_type=single |
176 |
- elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] |
177 |
- then |
178 |
- # use '--depth 1' when fetching a new branch |
179 |
- fetch_command+=( --depth 1 ) |
180 |
+ if [[ ${clone_type} == single+tags ]]; then |
181 |
+ fetch_command+=( |
182 |
+ # pull tags explicitly as requested |
183 |
+ "+refs/tags/*:refs/tags/*" |
184 |
+ ) |
185 |
+ fi |
186 |
fi |
187 |
- else # non-shallow mode |
188 |
- if [[ -f ${GIT_DIR}/shallow ]]; then |
189 |
- fetch_command+=( --unshallow ) |
190 |
+ |
191 |
+ if [[ ${clone_type} == shallow ]]; then |
192 |
+ if _git-r3_is_local_repo; then |
193 |
+ # '--depth 1' causes sandbox violations with local repos |
194 |
+ # bug #491260 |
195 |
+ clone_type=single |
196 |
+ elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] |
197 |
+ then |
198 |
+ # use '--depth 1' when fetching a new branch |
199 |
+ fetch_command+=( --depth 1 ) |
200 |
+ fi |
201 |
+ else # non-shallow mode |
202 |
+ if [[ -f ${GIT_DIR}/shallow ]]; then |
203 |
+ fetch_command+=( --unshallow ) |
204 |
+ fi |
205 |
fi |
206 |
- fi |
207 |
|
208 |
- set -- "${fetch_command[@]}" |
209 |
- echo "${@}" >&2 |
210 |
- if "${@}"; then |
211 |
+ set -- "${fetch_command[@]}" |
212 |
+ echo "${@}" >&2 |
213 |
+ "${@}" || continue |
214 |
+ |
215 |
if [[ ${clone_type} == mirror || ${fetch_l} == HEAD ]]; then |
216 |
# update our HEAD to match our remote HEAD ref |
217 |
git symbolic-ref HEAD refs/git-r3/HEAD \ |
218 |
|| die "Unable to update HEAD" |
219 |
fi |
220 |
+ fi |
221 |
|
222 |
- # now let's see what the user wants from us |
223 |
- local full_remote_ref=$( |
224 |
- git rev-parse --verify --symbolic-full-name "${remote_ref}" |
225 |
- ) |
226 |
+ # now let's see what the user wants from us |
227 |
+ local full_remote_ref=$( |
228 |
+ git rev-parse --verify --symbolic-full-name "${remote_ref}" |
229 |
+ ) |
230 |
|
231 |
- if [[ ${full_remote_ref} ]]; then |
232 |
- # when we are given a ref, create a symbolic ref |
233 |
- # so that we preserve the actual argument |
234 |
- set -- git symbolic-ref "${local_ref}" "${full_remote_ref}" |
235 |
- else |
236 |
- # otherwise, we were likely given a commit id |
237 |
- set -- git update-ref --no-deref "${local_ref}" "${remote_ref}" |
238 |
- fi |
239 |
+ if [[ ${full_remote_ref} ]]; then |
240 |
+ # when we are given a ref, create a symbolic ref |
241 |
+ # so that we preserve the actual argument |
242 |
+ set -- git symbolic-ref "${local_ref}" "${full_remote_ref}" |
243 |
+ else |
244 |
+ # otherwise, we were likely given a commit id |
245 |
+ set -- git update-ref --no-deref "${local_ref}" "${remote_ref}" |
246 |
+ fi |
247 |
|
248 |
- echo "${@}" >&2 |
249 |
- if ! "${@}"; then |
250 |
+ echo "${@}" >&2 |
251 |
+ if ! "${@}"; then |
252 |
+ if [[ ${EVCS_OFFLINE} ]]; then |
253 |
+ eerror "A clone of the following repository is required to proceed:" |
254 |
+ eerror " ${r}" |
255 |
+ eerror "However, networking activity has been disabled using EVCS_OFFLINE and the local" |
256 |
+ eerror "clone does not have requested ref:" |
257 |
+ eerror " ${remote_ref}" |
258 |
+ die "Local clone of ${r} does not have requested ref: ${remote_ref}. Unable to proceed with EVCS_OFFLINE." |
259 |
+ else |
260 |
die "Referencing ${remote_ref} failed (wrong ref?)." |
261 |
fi |
262 |
- |
263 |
- success=1 |
264 |
- break |
265 |
fi |
266 |
+ |
267 |
+ success=1 |
268 |
+ break |
269 |
done |
270 |
if [[ ${saved_umask} ]]; then |
271 |
umask "${saved_umask}" || die |
272 |
@@ -771,11 +780,7 @@ git-r3_checkout() { |
273 |
einfo "Checking out \e[1m${repos[0]}\e[22m to \e[1m${out_dir}\e[22m ..." |
274 |
|
275 |
if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then |
276 |
- if [[ ${EVCS_OFFLINE} ]]; then |
277 |
- die "No local clone of ${repos[0]}. Unable to work with EVCS_OFFLINE." |
278 |
- else |
279 |
- die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?" |
280 |
- fi |
281 |
+ die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?" |
282 |
fi |
283 |
local remote_ref=$( |
284 |
git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__ |