1 |
commit: 37620f874574313cb781ce2815d4de68f2c8917e |
2 |
Author: Chema Alonso Josa <nimiux <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Dec 10 19:56:47 2017 +0000 |
4 |
Commit: José María Alonso <nimiux <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Dec 10 19:56:47 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/lisp.git/commit/?id=37620f87 |
7 |
|
8 |
git-r3.eclass: Drops redundant eclass |
9 |
|
10 |
eclass/git-r3.eclass | 1054 -------------------------------------------------- |
11 |
1 file changed, 1054 deletions(-) |
12 |
|
13 |
diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass |
14 |
deleted file mode 100644 |
15 |
index c9d2731a..00000000 |
16 |
--- a/eclass/git-r3.eclass |
17 |
+++ /dev/null |
18 |
@@ -1,1054 +0,0 @@ |
19 |
-# Copyright 1999-2017 Gentoo Foundation |
20 |
-# Distributed under the terms of the GNU General Public License v2 |
21 |
- |
22 |
-# @ECLASS: git-r3.eclass |
23 |
-# @MAINTAINER: |
24 |
-# Michał Górny <mgorny@g.o> |
25 |
-# @BLURB: Eclass for fetching and unpacking git repositories. |
26 |
-# @DESCRIPTION: |
27 |
-# Third generation eclass for easing maintenance of live ebuilds using |
28 |
-# git as remote repository. |
29 |
- |
30 |
-case "${EAPI:-0}" in |
31 |
- 0|1|2|3|4|5|6) |
32 |
- ;; |
33 |
- *) |
34 |
- die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
35 |
- ;; |
36 |
-esac |
37 |
- |
38 |
-EXPORT_FUNCTIONS src_unpack |
39 |
- |
40 |
-if [[ ! ${_GIT_R3} ]]; then |
41 |
- |
42 |
-if [[ ! ${_INHERITED_BY_GIT_2} ]]; then |
43 |
- DEPEND=">=dev-vcs/git-1.8.2.1" |
44 |
-fi |
45 |
- |
46 |
-# @ECLASS-VARIABLE: EGIT_CLONE_TYPE |
47 |
-# @DESCRIPTION: |
48 |
-# Type of clone that should be used against the remote repository. |
49 |
-# This can be either of: 'mirror', 'single', 'shallow'. |
50 |
-# |
51 |
-# This is intended to be set by user in make.conf. Ebuilds are supposed |
52 |
-# to set EGIT_MIN_CLONE_TYPE if necessary instead. |
53 |
-# |
54 |
-# The 'mirror' type clones all remote branches and tags with complete |
55 |
-# history and all notes. EGIT_COMMIT can specify any commit hash. |
56 |
-# Upstream-removed branches and tags are purged from the local clone |
57 |
-# while fetching. This mode is suitable for cloning the local copy |
58 |
-# for development or hosting a local git mirror. However, clones |
59 |
-# of repositories with large diverged branches may quickly grow large. |
60 |
-# |
61 |
-# The 'single+tags' type clones the requested branch and all tags |
62 |
-# in the repository. All notes are fetched as well. EGIT_COMMIT |
63 |
-# can safely specify hashes throughout the current branch and all tags. |
64 |
-# No purging of old references is done (if you often switch branches, |
65 |
-# you may need to remove stale branches yourself). This mode is intended |
66 |
-# mostly for use with broken git servers such as Google Code that fail |
67 |
-# to fetch tags along with the branch in 'single' mode. |
68 |
-# |
69 |
-# The 'single' type clones only the requested branch or tag. Tags |
70 |
-# referencing commits throughout the branch history are fetched as well, |
71 |
-# and all notes. EGIT_COMMIT can safely specify only hashes |
72 |
-# in the current branch. No purging of old references is done (if you |
73 |
-# often switch branches, you may need to remove stale branches |
74 |
-# yourself). This mode is suitable for general use. |
75 |
-# |
76 |
-# The 'shallow' type clones only the newest commit on requested branch |
77 |
-# or tag. EGIT_COMMIT can only specify tags, and since the history is |
78 |
-# unavailable calls like 'git describe' will not reference prior tags. |
79 |
-# No purging of old references is done. This mode is intended mostly for |
80 |
-# embedded systems with limited disk space. |
81 |
-: ${EGIT_CLONE_TYPE:=single} |
82 |
- |
83 |
-# @ECLASS-VARIABLE: EGIT_MIN_CLONE_TYPE |
84 |
-# @DESCRIPTION: |
85 |
-# 'Minimum' clone type supported by the ebuild. Takes same values |
86 |
-# as EGIT_CLONE_TYPE. When user sets a type that's 'lower' (that is, |
87 |
-# later on the list) than EGIT_MIN_CLONE_TYPE, the eclass uses |
88 |
-# EGIT_MIN_CLONE_TYPE instead. |
89 |
-# |
90 |
-# This variable is intended to be used by ebuilds only. Users are |
91 |
-# supposed to set EGIT_CLONE_TYPE instead. |
92 |
-# |
93 |
-# A common case is to use 'single' whenever the build system requires |
94 |
-# access to full branch history, or 'single+tags' when Google Code |
95 |
-# or a similar remote is used that does not support shallow clones |
96 |
-# and fetching tags along with commits. Please use sparingly, and to fix |
97 |
-# fatal errors rather than 'non-pretty versions'. |
98 |
-: ${EGIT_MIN_CLONE_TYPE:=shallow} |
99 |
- |
100 |
-# @ECLASS-VARIABLE: EGIT3_STORE_DIR |
101 |
-# @DESCRIPTION: |
102 |
-# Storage directory for git sources. |
103 |
-# |
104 |
-# This is intended to be set by user in make.conf. Ebuilds must not set |
105 |
-# it. |
106 |
-# |
107 |
-# EGIT3_STORE_DIR=${DISTDIR}/git3-src |
108 |
- |
109 |
-# @ECLASS-VARIABLE: EGIT_MIRROR_URI |
110 |
-# @DEFAULT_UNSET |
111 |
-# @DESCRIPTION: |
112 |
-# 'Top' URI to a local git mirror. If specified, the eclass will try |
113 |
-# to fetch from the local mirror instead of using the remote repository. |
114 |
-# |
115 |
-# The mirror needs to follow EGIT3_STORE_DIR structure. The directory |
116 |
-# created by eclass can be used for that purpose. |
117 |
-# |
118 |
-# Example: |
119 |
-# @CODE |
120 |
-# EGIT_MIRROR_URI="git://mirror.lan/" |
121 |
-# @CODE |
122 |
- |
123 |
-# @ECLASS-VARIABLE: EGIT_REPO_URI |
124 |
-# @REQUIRED |
125 |
-# @DESCRIPTION: |
126 |
-# URIs to the repository, e.g. https://foo. If multiple URIs are |
127 |
-# provided, the eclass will consider the remaining URIs as fallbacks |
128 |
-# to try if the first URI does not work. For supported URI syntaxes, |
129 |
-# read the manpage for git-clone(1). |
130 |
-# |
131 |
-# URIs should be using https:// whenever possible. http:// and git:// |
132 |
-# URIs are completely unsecured and their use (even if only as |
133 |
-# a fallback) renders the ebuild completely vulnerable to MITM attacks. |
134 |
-# |
135 |
-# It can be overridden via env using ${PN}_LIVE_REPO variable. |
136 |
-# |
137 |
-# Can be a whitespace-separated list or an array. |
138 |
-# |
139 |
-# Example: |
140 |
-# @CODE |
141 |
-# EGIT_REPO_URI="https://a/b.git https://c/d.git" |
142 |
-# @CODE |
143 |
- |
144 |
-# @ECLASS-VARIABLE: EVCS_OFFLINE |
145 |
-# @DEFAULT_UNSET |
146 |
-# @DESCRIPTION: |
147 |
-# If non-empty, this variable prevents any online operations. |
148 |
- |
149 |
-# @ECLASS-VARIABLE: EVCS_UMASK |
150 |
-# @DEFAULT_UNSET |
151 |
-# @DESCRIPTION: |
152 |
-# Set this variable to a custom umask. This is intended to be set by |
153 |
-# users. By setting this to something like 002, it can make life easier |
154 |
-# for people who do development as non-root (but are in the portage |
155 |
-# group), and then switch over to building with FEATURES=userpriv. |
156 |
-# Or vice-versa. Shouldn't be a security issue here as anyone who has |
157 |
-# portage group write access already can screw the system over in more |
158 |
-# creative ways. |
159 |
- |
160 |
-# @ECLASS-VARIABLE: EGIT_BRANCH |
161 |
-# @DEFAULT_UNSET |
162 |
-# @DESCRIPTION: |
163 |
-# The branch name to check out. If unset, the upstream default (HEAD) |
164 |
-# will be used. |
165 |
-# |
166 |
-# It can be overriden via env using ${PN}_LIVE_BRANCH variable. |
167 |
- |
168 |
-# @ECLASS-VARIABLE: EGIT_COMMIT |
169 |
-# @DEFAULT_UNSET |
170 |
-# @DESCRIPTION: |
171 |
-# The tag name or commit identifier to check out. If unset, newest |
172 |
-# commit from the branch will be used. Note that if set to a commit |
173 |
-# not on HEAD branch, EGIT_BRANCH needs to be set to a branch on which |
174 |
-# the commit is available. |
175 |
-# |
176 |
-# It can be overriden via env using ${PN}_LIVE_COMMIT variable. |
177 |
- |
178 |
-# @ECLASS-VARIABLE: EGIT_COMMIT_DATE |
179 |
-# @DEFAULT_UNSET |
180 |
-# @DESCRIPTION: |
181 |
-# Attempt to check out the repository state for the specified timestamp. |
182 |
-# The date should be in format understood by 'git rev-list'. The commits |
183 |
-# on EGIT_BRANCH will be considered. |
184 |
-# |
185 |
-# The eclass will select the last commit with commit date preceding |
186 |
-# the specified date. When merge commits are found, only first parents |
187 |
-# will be considered in order to avoid switching into external branches |
188 |
-# (assuming that merges are done correctly). In other words, each merge |
189 |
-# will be considered alike a single commit with date corresponding |
190 |
-# to the merge commit date. |
191 |
-# |
192 |
-# It can be overriden via env using ${PN}_LIVE_COMMIT_DATE variable. |
193 |
- |
194 |
-# @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR |
195 |
-# @DESCRIPTION: |
196 |
-# The directory to check the git sources out to. |
197 |
-# |
198 |
-# EGIT_CHECKOUT_DIR=${WORKDIR}/${P} |
199 |
- |
200 |
-# @ECLASS-VARIABLE: EGIT_SUBMODULES |
201 |
-# @DEFAULT_UNSET |
202 |
-# @DESCRIPTION: |
203 |
-# An array of inclusive and exclusive wildcards on submodule names, |
204 |
-# stating which submodules are fetched and checked out. Exclusions |
205 |
-# start with '-', and exclude previously matched submodules. |
206 |
-# |
207 |
-# If unset, all submodules are enabled. Empty list disables all |
208 |
-# submodules. In order to use an exclude-only list, start the array |
209 |
-# with '*'. |
210 |
-# |
211 |
-# Remember that wildcards need to be quoted in order to prevent filename |
212 |
-# expansion. |
213 |
-# |
214 |
-# Examples: |
215 |
-# @CODE |
216 |
-# # Disable all submodules |
217 |
-# EGIT_SUBMODULES=() |
218 |
-# |
219 |
-# # Include only foo and bar |
220 |
-# EGIT_SUBMODULES=( foo bar ) |
221 |
-# |
222 |
-# # Use all submodules except for test-* but include test-lib |
223 |
-# EGIT_SUBMODULES=( '*' '-test-*' test-lib ) |
224 |
-# @CODE |
225 |
- |
226 |
-# @FUNCTION: _git-r3_env_setup |
227 |
-# @INTERNAL |
228 |
-# @DESCRIPTION: |
229 |
-# Set the eclass variables as necessary for operation. This can involve |
230 |
-# setting EGIT_* to defaults or ${PN}_LIVE_* variables. |
231 |
-_git-r3_env_setup() { |
232 |
- debug-print-function ${FUNCNAME} "$@" |
233 |
- |
234 |
- # check the clone type |
235 |
- case "${EGIT_CLONE_TYPE}" in |
236 |
- mirror|single+tags|single|shallow) |
237 |
- ;; |
238 |
- *) |
239 |
- die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" |
240 |
- esac |
241 |
- case "${EGIT_MIN_CLONE_TYPE}" in |
242 |
- shallow) |
243 |
- ;; |
244 |
- single) |
245 |
- if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then |
246 |
- einfo "git-r3: ebuild needs to be cloned in '\e[1msingle\e[22m' mode, adjusting" |
247 |
- EGIT_CLONE_TYPE=single |
248 |
- fi |
249 |
- ;; |
250 |
- single+tags) |
251 |
- if [[ ${EGIT_CLONE_TYPE} == shallow || ${EGIT_CLONE_TYPE} == single ]]; then |
252 |
- einfo "git-r3: ebuild needs to be cloned in '\e[1msingle+tags\e[22m' mode, adjusting" |
253 |
- EGIT_CLONE_TYPE=single+tags |
254 |
- fi |
255 |
- ;; |
256 |
- mirror) |
257 |
- if [[ ${EGIT_CLONE_TYPE} != mirror ]]; then |
258 |
- einfo "git-r3: ebuild needs to be cloned in '\e[1mmirror\e[22m' mode, adjusting" |
259 |
- EGIT_CLONE_TYPE=mirror |
260 |
- fi |
261 |
- ;; |
262 |
- *) |
263 |
- die "Invalid EGIT_MIN_CLONE_TYPE=${EGIT_MIN_CLONE_TYPE}" |
264 |
- esac |
265 |
- |
266 |
- if [[ ${EGIT_SUBMODULES[@]+1} && $(declare -p EGIT_SUBMODULES) != "declare -a"* ]] |
267 |
- then |
268 |
- die 'EGIT_SUBMODULES must be an array.' |
269 |
- fi |
270 |
- |
271 |
- local esc_pn livevar |
272 |
- esc_pn=${PN//[-+]/_} |
273 |
- [[ ${esc_pn} == [0-9]* ]] && esc_pn=_${esc_pn} |
274 |
- |
275 |
- livevar=${esc_pn}_LIVE_REPO |
276 |
- EGIT_REPO_URI=${!livevar-${EGIT_REPO_URI}} |
277 |
- [[ ${!livevar} ]] \ |
278 |
- && ewarn "Using ${livevar}, no support will be provided" |
279 |
- |
280 |
- livevar=${esc_pn}_LIVE_BRANCH |
281 |
- EGIT_BRANCH=${!livevar-${EGIT_BRANCH}} |
282 |
- [[ ${!livevar} ]] \ |
283 |
- && ewarn "Using ${livevar}, no support will be provided" |
284 |
- |
285 |
- livevar=${esc_pn}_LIVE_COMMIT |
286 |
- EGIT_COMMIT=${!livevar-${EGIT_COMMIT}} |
287 |
- [[ ${!livevar} ]] \ |
288 |
- && ewarn "Using ${livevar}, no support will be provided" |
289 |
- |
290 |
- livevar=${esc_pn}_LIVE_COMMIT_DATE |
291 |
- EGIT_COMMIT_DATE=${!livevar-${EGIT_COMMIT_DATE}} |
292 |
- [[ ${!livevar} ]] \ |
293 |
- && ewarn "Using ${livevar}, no support will be provided" |
294 |
- |
295 |
- if [[ ${EGIT_COMMIT} && ${EGIT_COMMIT_DATE} ]]; then |
296 |
- die "EGIT_COMMIT and EGIT_COMMIT_DATE can not be specified simultaneously" |
297 |
- fi |
298 |
- |
299 |
- # Migration helpers. Remove them when git-2 is removed. |
300 |
- |
301 |
- if [[ ${EGIT_SOURCEDIR} ]]; then |
302 |
- eerror "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR. While updating" |
303 |
- eerror "your ebuild, please check whether the variable is necessary at all" |
304 |
- eerror "since the default has been changed from \${S} to \${WORKDIR}/\${P}." |
305 |
- eerror "Therefore, proper setting of S may be sufficient." |
306 |
- die "EGIT_SOURCEDIR has been replaced by EGIT_CHECKOUT_DIR." |
307 |
- fi |
308 |
- |
309 |
- if [[ ${EGIT_MASTER} ]]; then |
310 |
- eerror "EGIT_MASTER has been removed. Instead, the upstream default (HEAD)" |
311 |
- eerror "is used by the eclass. Please remove the assignment or use EGIT_BRANCH" |
312 |
- eerror "as necessary." |
313 |
- die "EGIT_MASTER has been removed." |
314 |
- fi |
315 |
- |
316 |
- if [[ ${EGIT_HAS_SUBMODULES} ]]; then |
317 |
- eerror "EGIT_HAS_SUBMODULES has been removed. The eclass no longer needs" |
318 |
- eerror "to switch the clone type in order to support submodules and therefore" |
319 |
- eerror "submodules are detected and fetched automatically. If you need to" |
320 |
- eerror "disable or filter submodules, see EGIT_SUBMODULES." |
321 |
- die "EGIT_HAS_SUBMODULES is no longer necessary." |
322 |
- fi |
323 |
- |
324 |
- if [[ ${EGIT_PROJECT} ]]; then |
325 |
- eerror "EGIT_PROJECT has been removed. Instead, the eclass determines" |
326 |
- eerror "the local clone path using path in canonical EGIT_REPO_URI." |
327 |
- eerror "If the current algorithm causes issues for you, please report a bug." |
328 |
- die "EGIT_PROJECT is no longer necessary." |
329 |
- fi |
330 |
- |
331 |
- if [[ ${EGIT_BOOTSTRAP} ]]; then |
332 |
- eerror "EGIT_BOOTSTRAP has been removed. Please create proper src_prepare()" |
333 |
- eerror "instead." |
334 |
- die "EGIT_BOOTSTRAP has been removed." |
335 |
- fi |
336 |
- |
337 |
- if [[ ${EGIT_NOUNPACK} ]]; then |
338 |
- eerror "EGIT_NOUNPACK has been removed. The eclass no longer calls default" |
339 |
- eerror "unpack function. If necessary, please declare proper src_unpack()." |
340 |
- die "EGIT_NOUNPACK has been removed." |
341 |
- fi |
342 |
-} |
343 |
- |
344 |
-# @FUNCTION: _git-r3_set_gitdir |
345 |
-# @USAGE: <repo-uri> |
346 |
-# @INTERNAL |
347 |
-# @DESCRIPTION: |
348 |
-# Obtain the local repository path and set it as GIT_DIR. Creates |
349 |
-# a new repository if necessary. |
350 |
-# |
351 |
-# <repo-uri> may be used to compose the path. It should therefore be |
352 |
-# a canonical URI to the repository. |
353 |
-_git-r3_set_gitdir() { |
354 |
- debug-print-function ${FUNCNAME} "$@" |
355 |
- |
356 |
- local repo_name=${1#*://*/} |
357 |
- |
358 |
- # strip the trailing slash |
359 |
- repo_name=${repo_name%/} |
360 |
- |
361 |
- # strip common prefixes to make paths more likely to match |
362 |
- # e.g. git://X/Y.git vs https://X/git/Y.git |
363 |
- # (but just one of the prefixes) |
364 |
- case "${repo_name}" in |
365 |
- # gnome.org... who else? |
366 |
- browse/*) repo_name=${repo_name#browse/};; |
367 |
- # cgit can proxy requests to git |
368 |
- cgit/*) repo_name=${repo_name#cgit/};; |
369 |
- # pretty common |
370 |
- git/*) repo_name=${repo_name#git/};; |
371 |
- # gentoo.org |
372 |
- gitroot/*) repo_name=${repo_name#gitroot/};; |
373 |
- # sourceforge |
374 |
- p/*) repo_name=${repo_name#p/};; |
375 |
- # kernel.org |
376 |
- pub/scm/*) repo_name=${repo_name#pub/scm/};; |
377 |
- esac |
378 |
- # ensure a .git suffix, same reason |
379 |
- repo_name=${repo_name%.git}.git |
380 |
- # now replace all the slashes |
381 |
- repo_name=${repo_name//\//_} |
382 |
- |
383 |
- local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}} |
384 |
- : ${EGIT3_STORE_DIR:=${distdir}/git3-src} |
385 |
- |
386 |
- GIT_DIR=${EGIT3_STORE_DIR}/${repo_name} |
387 |
- |
388 |
- if [[ ! -d ${EGIT3_STORE_DIR} && ! ${EVCS_OFFLINE} ]]; then |
389 |
- ( |
390 |
- addwrite / |
391 |
- mkdir -p "${EGIT3_STORE_DIR}" |
392 |
- ) || die "Unable to create ${EGIT3_STORE_DIR}" |
393 |
- fi |
394 |
- |
395 |
- addwrite "${EGIT3_STORE_DIR}" |
396 |
- if [[ ! -d ${GIT_DIR} ]]; then |
397 |
- if [[ ${EVCS_OFFLINE} ]]; then |
398 |
- eerror "A clone of the following repository is required to proceed:" |
399 |
- eerror " ${1}" |
400 |
- eerror "However, networking activity has been disabled using EVCS_OFFLINE and there" |
401 |
- eerror "is no local clone available." |
402 |
- die "No local clone of ${1}. Unable to proceed with EVCS_OFFLINE." |
403 |
- fi |
404 |
- |
405 |
- local saved_umask |
406 |
- if [[ ${EVCS_UMASK} ]]; then |
407 |
- saved_umask=$(umask) |
408 |
- umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}" |
409 |
- fi |
410 |
- mkdir "${GIT_DIR}" || die |
411 |
- git init --bare || die |
412 |
- if [[ ${saved_umask} ]]; then |
413 |
- umask "${saved_umask}" || die |
414 |
- fi |
415 |
- fi |
416 |
-} |
417 |
- |
418 |
-# @FUNCTION: _git-r3_set_submodules |
419 |
-# @USAGE: <file-contents> |
420 |
-# @INTERNAL |
421 |
-# @DESCRIPTION: |
422 |
-# Parse .gitmodules contents passed as <file-contents> |
423 |
-# as in "$(cat .gitmodules)"). Composes a 'submodules' array that |
424 |
-# contains in order (name, URL, path) for each submodule. |
425 |
-_git-r3_set_submodules() { |
426 |
- debug-print-function ${FUNCNAME} "$@" |
427 |
- |
428 |
- local data=${1} |
429 |
- |
430 |
- # ( name url path ... ) |
431 |
- submodules=() |
432 |
- |
433 |
- local l |
434 |
- while read l; do |
435 |
- # submodule.<path>.path=<path> |
436 |
- # submodule.<path>.url=<url> |
437 |
- [[ ${l} == submodule.*.url=* ]] || continue |
438 |
- |
439 |
- l=${l#submodule.} |
440 |
- local subname=${l%%.url=*} |
441 |
- |
442 |
- # filter out on EGIT_SUBMODULES |
443 |
- if declare -p EGIT_SUBMODULES &>/dev/null; then |
444 |
- local p l_res res= |
445 |
- for p in "${EGIT_SUBMODULES[@]}"; do |
446 |
- if [[ ${p} == -* ]]; then |
447 |
- p=${p#-} |
448 |
- l_res= |
449 |
- else |
450 |
- l_res=1 |
451 |
- fi |
452 |
- |
453 |
- [[ ${subname} == ${p} ]] && res=${l_res} |
454 |
- done |
455 |
- |
456 |
- if [[ ! ${res} ]]; then |
457 |
- einfo "Skipping submodule \e[1m${subname}\e[22m" |
458 |
- continue |
459 |
- fi |
460 |
- fi |
461 |
- |
462 |
- # skip modules that have 'update = none', bug #487262. |
463 |
- local upd=$(echo "${data}" | git config -f /dev/fd/0 \ |
464 |
- submodule."${subname}".update) |
465 |
- [[ ${upd} == none ]] && continue |
466 |
- |
467 |
- # https://github.com/git/git/blob/master/refs.c#L31 |
468 |
- # we are more restrictive than git itself but that should not |
469 |
- # cause any issues, #572312, #606950 |
470 |
- # TODO: check escaped names for collisions |
471 |
- local enc_subname=${subname//[^a-zA-Z0-9-]/_} |
472 |
- |
473 |
- submodules+=( |
474 |
- "${enc_subname}" |
475 |
- "$(echo "${data}" | git config -f /dev/fd/0 \ |
476 |
- submodule."${subname}".url || die)" |
477 |
- "$(echo "${data}" | git config -f /dev/fd/0 \ |
478 |
- submodule."${subname}".path || die)" |
479 |
- ) |
480 |
- done < <(echo "${data}" | git config -f /dev/fd/0 -l || die) |
481 |
-} |
482 |
- |
483 |
-# @FUNCTION: _git-r3_set_subrepos |
484 |
-# @USAGE: <submodule-uri> <parent-repo-uri>... |
485 |
-# @INTERNAL |
486 |
-# @DESCRIPTION: |
487 |
-# Create 'subrepos' array containing absolute (canonical) submodule URIs |
488 |
-# for the given <submodule-uri>. If the URI is relative, URIs will be |
489 |
-# constructed using all <parent-repo-uri>s. Otherwise, this single URI |
490 |
-# will be placed in the array. |
491 |
-_git-r3_set_subrepos() { |
492 |
- debug-print-function ${FUNCNAME} "$@" |
493 |
- |
494 |
- local suburl=${1} |
495 |
- subrepos=( "${@:2}" ) |
496 |
- |
497 |
- if [[ ${suburl} == ./* || ${suburl} == ../* ]]; then |
498 |
- # drop all possible trailing slashes for consistency |
499 |
- subrepos=( "${subrepos[@]%%/}" ) |
500 |
- |
501 |
- while true; do |
502 |
- if [[ ${suburl} == ./* ]]; then |
503 |
- suburl=${suburl:2} |
504 |
- elif [[ ${suburl} == ../* ]]; then |
505 |
- suburl=${suburl:3} |
506 |
- |
507 |
- # XXX: correctness checking |
508 |
- |
509 |
- # drop the last path component |
510 |
- subrepos=( "${subrepos[@]%/*}" ) |
511 |
- # and then the trailing slashes, again |
512 |
- subrepos=( "${subrepos[@]%%/}" ) |
513 |
- else |
514 |
- break |
515 |
- fi |
516 |
- done |
517 |
- |
518 |
- # append the preprocessed path to the preprocessed URIs |
519 |
- subrepos=( "${subrepos[@]/%//${suburl}}") |
520 |
- else |
521 |
- subrepos=( "${suburl}" ) |
522 |
- fi |
523 |
-} |
524 |
- |
525 |
- |
526 |
-# @FUNCTION: _git-r3_is_local_repo |
527 |
-# @USAGE: <repo-uri> |
528 |
-# @INTERNAL |
529 |
-# @DESCRIPTION: |
530 |
-# Determine whether the given URI specifies a local (on-disk) |
531 |
-# repository. |
532 |
-_git-r3_is_local_repo() { |
533 |
- debug-print-function ${FUNCNAME} "$@" |
534 |
- |
535 |
- local uri=${1} |
536 |
- |
537 |
- [[ ${uri} == file://* || ${uri} == /* ]] |
538 |
-} |
539 |
- |
540 |
-# @FUNCTION: git-r3_fetch |
541 |
-# @USAGE: [<repo-uri> [<remote-ref> [<local-id> [<commit-date>]]]] |
542 |
-# @DESCRIPTION: |
543 |
-# Fetch new commits to the local clone of repository. |
544 |
-# |
545 |
-# <repo-uri> specifies the repository URIs to fetch from, as a space- |
546 |
-# -separated list. The first URI will be used as repository group |
547 |
-# identifier and therefore must be used consistently. When not |
548 |
-# specified, defaults to ${EGIT_REPO_URI}. |
549 |
-# |
550 |
-# <remote-ref> specifies the remote ref or commit id to fetch. |
551 |
-# It is preferred to use 'refs/heads/<branch-name>' for branches |
552 |
-# and 'refs/tags/<tag-name>' for tags. Other options are 'HEAD' |
553 |
-# for upstream default branch and hexadecimal commit SHA1. Defaults |
554 |
-# to the first of EGIT_COMMIT, EGIT_BRANCH or literal 'HEAD' that |
555 |
-# is set to a non-null value. |
556 |
-# |
557 |
-# <local-id> specifies the local branch identifier that will be used to |
558 |
-# locally store the fetch result. It should be unique to multiple |
559 |
-# fetches within the repository that can be performed at the same time |
560 |
-# (including parallel merges). It defaults to ${CATEGORY}/${PN}/${SLOT%/*}. |
561 |
-# This default should be fine unless you are fetching multiple trees |
562 |
-# from the same repository in the same ebuild. |
563 |
-# |
564 |
-# <commit-id> requests attempting to use repository state as of specific |
565 |
-# date. For more details, see EGIT_COMMIT_DATE. |
566 |
-# |
567 |
-# The fetch operation will affect the EGIT_STORE only. It will not touch |
568 |
-# the working copy, nor export any environment variables. |
569 |
-# If the repository contains submodules, they will be fetched |
570 |
-# recursively. |
571 |
-git-r3_fetch() { |
572 |
- debug-print-function ${FUNCNAME} "$@" |
573 |
- |
574 |
- local repos |
575 |
- if [[ ${1} ]]; then |
576 |
- repos=( ${1} ) |
577 |
- elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then |
578 |
- repos=( "${EGIT_REPO_URI[@]}" ) |
579 |
- else |
580 |
- repos=( ${EGIT_REPO_URI} ) |
581 |
- fi |
582 |
- |
583 |
- local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} |
584 |
- local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} |
585 |
- local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} |
586 |
- local local_ref=refs/git-r3/${local_id}/__main__ |
587 |
- local commit_date=${4:-${EGIT_COMMIT_DATE}} |
588 |
- |
589 |
- [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" |
590 |
- |
591 |
- local r |
592 |
- for r in "${repos[@]}"; do |
593 |
- if [[ ${r} == git:* || ${r} == http:* ]]; then |
594 |
- ewarn "git-r3: ${r%%:*} protocol is completely unsecure and may render the ebuild" |
595 |
- ewarn "easily susceptible to MITM attacks (even if used only as fallback). Please" |
596 |
- ewarn "use https instead." |
597 |
- ewarn "[URI: ${r}]" |
598 |
- fi |
599 |
- done |
600 |
- |
601 |
- local -x GIT_DIR |
602 |
- _git-r3_set_gitdir "${repos[0]}" |
603 |
- |
604 |
- # prepend the local mirror if applicable |
605 |
- if [[ ${EGIT_MIRROR_URI} ]]; then |
606 |
- repos=( |
607 |
- "${EGIT_MIRROR_URI%/}/${GIT_DIR##*/}" |
608 |
- "${repos[@]}" |
609 |
- ) |
610 |
- fi |
611 |
- |
612 |
- # try to fetch from the remote |
613 |
- local success saved_umask |
614 |
- if [[ ${EVCS_UMASK} ]]; then |
615 |
- saved_umask=$(umask) |
616 |
- umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}" |
617 |
- fi |
618 |
- for r in "${repos[@]}"; do |
619 |
- if [[ ! ${EVCS_OFFLINE} ]]; then |
620 |
- einfo "Fetching \e[1m${r}\e[22m ..." |
621 |
- |
622 |
- local fetch_command=( git fetch "${r}" ) |
623 |
- local clone_type=${EGIT_CLONE_TYPE} |
624 |
- |
625 |
- if [[ ${r} == http://* || ${r} == https://* ]] && |
626 |
- [[ ! ${EGIT_CURL_WARNED} ]] && |
627 |
- ! ROOT=/ has_version 'dev-vcs/git[curl]' |
628 |
- then |
629 |
- ewarn "git-r3: fetching from HTTP(S) requested. In order to support HTTP(S)," |
630 |
- ewarn "dev-vcs/git needs to be built with USE=curl. Example solution:" |
631 |
- ewarn |
632 |
- ewarn " echo dev-vcs/git curl >> /etc/portage/package.use" |
633 |
- ewarn " emerge -1v dev-vcs/git" |
634 |
- ewarn |
635 |
- ewarn "HTTP(S) URIs will be skipped." |
636 |
- EGIT_CURL_WARNED=1 |
637 |
- fi |
638 |
- |
639 |
- if [[ ${clone_type} == mirror ]]; then |
640 |
- fetch_command+=( |
641 |
- --prune |
642 |
- # mirror the remote branches as local branches |
643 |
- "+refs/heads/*:refs/heads/*" |
644 |
- # pull tags explicitly in order to prune them properly |
645 |
- "+refs/tags/*:refs/tags/*" |
646 |
- # notes in case something needs them |
647 |
- "+refs/notes/*:refs/notes/*" |
648 |
- # and HEAD in case we need the default branch |
649 |
- # (we keep it in refs/git-r3 since otherwise --prune interferes) |
650 |
- "+HEAD:refs/git-r3/HEAD" |
651 |
- ) |
652 |
- else # single or shallow |
653 |
- local fetch_l fetch_r |
654 |
- |
655 |
- if [[ ${remote_ref} == HEAD ]]; then |
656 |
- # HEAD |
657 |
- fetch_l=HEAD |
658 |
- elif [[ ${remote_ref} == refs/* ]]; then |
659 |
- # regular branch, tag or some other explicit ref |
660 |
- fetch_l=${remote_ref} |
661 |
- else |
662 |
- # tag or commit id... |
663 |
- # let ls-remote figure it out |
664 |
- local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}") |
665 |
- |
666 |
- # if it was a tag, ls-remote obtained a hash |
667 |
- if [[ ${tagref} ]]; then |
668 |
- # tag |
669 |
- fetch_l=refs/tags/${remote_ref} |
670 |
- else |
671 |
- # commit id |
672 |
- # so we need to fetch the whole branch |
673 |
- if [[ ${branch} ]]; then |
674 |
- fetch_l=${branch} |
675 |
- else |
676 |
- fetch_l=HEAD |
677 |
- fi |
678 |
- |
679 |
- # fetching by commit in shallow mode? can't do. |
680 |
- if [[ ${clone_type} == shallow ]]; then |
681 |
- clone_type=single |
682 |
- fi |
683 |
- fi |
684 |
- fi |
685 |
- |
686 |
- # checkout by date does not make sense in shallow mode |
687 |
- if [[ ${commit_date} && ${clone_type} == shallow ]]; then |
688 |
- clone_type=single |
689 |
- fi |
690 |
- |
691 |
- if [[ ${fetch_l} == HEAD ]]; then |
692 |
- fetch_r=refs/git-r3/HEAD |
693 |
- else |
694 |
- fetch_r=${fetch_l} |
695 |
- fi |
696 |
- |
697 |
- fetch_command+=( |
698 |
- "+${fetch_l}:${fetch_r}" |
699 |
- ) |
700 |
- |
701 |
- if [[ ${clone_type} == single+tags ]]; then |
702 |
- fetch_command+=( |
703 |
- # pull tags explicitly as requested |
704 |
- "+refs/tags/*:refs/tags/*" |
705 |
- ) |
706 |
- fi |
707 |
- fi |
708 |
- |
709 |
- if [[ ${clone_type} == shallow ]]; then |
710 |
- if _git-r3_is_local_repo; then |
711 |
- # '--depth 1' causes sandbox violations with local repos |
712 |
- # bug #491260 |
713 |
- clone_type=single |
714 |
- elif [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] |
715 |
- then |
716 |
- # use '--depth 1' when fetching a new branch |
717 |
- fetch_command+=( --depth 1 ) |
718 |
- fi |
719 |
- else # non-shallow mode |
720 |
- if [[ -f ${GIT_DIR}/shallow ]]; then |
721 |
- fetch_command+=( --unshallow ) |
722 |
- fi |
723 |
- fi |
724 |
- |
725 |
- set -- "${fetch_command[@]}" |
726 |
- echo "${@}" >&2 |
727 |
- "${@}" || continue |
728 |
- |
729 |
- if [[ ${clone_type} == mirror || ${fetch_l} == HEAD ]]; then |
730 |
- # update our HEAD to match our remote HEAD ref |
731 |
- git symbolic-ref HEAD refs/git-r3/HEAD \ |
732 |
- || die "Unable to update HEAD" |
733 |
- fi |
734 |
- fi |
735 |
- |
736 |
- # now let's see what the user wants from us |
737 |
- if [[ ${commit_date} ]]; then |
738 |
- local dated_commit_id=$( |
739 |
- git rev-list --first-parent --before="${commit_date}" \ |
740 |
- -n 1 "${remote_ref}" |
741 |
- ) |
742 |
- if [[ ${?} -ne 0 ]]; then |
743 |
- die "Listing ${remote_ref} failed (wrong ref?)." |
744 |
- elif [[ ! ${dated_commit_id} ]]; then |
745 |
- die "Unable to find commit for date ${commit_date}." |
746 |
- else |
747 |
- set -- git update-ref --no-deref "${local_ref}" "${dated_commit_id}" |
748 |
- fi |
749 |
- else |
750 |
- local full_remote_ref=$( |
751 |
- git rev-parse --verify --symbolic-full-name "${remote_ref}" |
752 |
- ) |
753 |
- |
754 |
- if [[ ${full_remote_ref} ]]; then |
755 |
- # when we are given a ref, create a symbolic ref |
756 |
- # so that we preserve the actual argument |
757 |
- set -- git symbolic-ref "${local_ref}" "${full_remote_ref}" |
758 |
- else |
759 |
- # otherwise, we were likely given a commit id |
760 |
- set -- git update-ref --no-deref "${local_ref}" "${remote_ref}" |
761 |
- fi |
762 |
- fi |
763 |
- |
764 |
- echo "${@}" >&2 |
765 |
- if ! "${@}"; then |
766 |
- if [[ ${EVCS_OFFLINE} ]]; then |
767 |
- eerror "A clone of the following repository is required to proceed:" |
768 |
- eerror " ${r}" |
769 |
- eerror "However, networking activity has been disabled using EVCS_OFFLINE and the local" |
770 |
- eerror "clone does not have requested ref:" |
771 |
- eerror " ${remote_ref}" |
772 |
- die "Local clone of ${r} does not have requested ref: ${remote_ref}. Unable to proceed with EVCS_OFFLINE." |
773 |
- else |
774 |
- die "Referencing ${remote_ref} failed (wrong ref?)." |
775 |
- fi |
776 |
- fi |
777 |
- |
778 |
- success=1 |
779 |
- break |
780 |
- done |
781 |
- if [[ ${saved_umask} ]]; then |
782 |
- umask "${saved_umask}" || die |
783 |
- fi |
784 |
- [[ ${success} ]] || die "Unable to fetch from any of EGIT_REPO_URI" |
785 |
- |
786 |
- # submodules can reference commits in any branch |
787 |
- # always use the 'mirror' mode to accomodate that, bug #503332 |
788 |
- local EGIT_CLONE_TYPE=mirror |
789 |
- |
790 |
- # recursively fetch submodules |
791 |
- if git cat-file -e "${local_ref}":.gitmodules &>/dev/null; then |
792 |
- local submodules |
793 |
- _git-r3_set_submodules \ |
794 |
- "$(git cat-file -p "${local_ref}":.gitmodules || die)" |
795 |
- |
796 |
- while [[ ${submodules[@]} ]]; do |
797 |
- local subname=${submodules[0]} |
798 |
- local url=${submodules[1]} |
799 |
- local path=${submodules[2]} |
800 |
- |
801 |
- # use only submodules for which path does exist |
802 |
- # (this is in par with 'git submodule'), bug #551100 |
803 |
- # note: git cat-file does not work for submodules |
804 |
- if [[ $(git ls-tree -d "${local_ref}" "${path}") ]] |
805 |
- then |
806 |
- local commit=$(git rev-parse "${local_ref}:${path}" || die) |
807 |
- |
808 |
- if [[ ! ${commit} ]]; then |
809 |
- die "Unable to get commit id for submodule ${subname}" |
810 |
- fi |
811 |
- |
812 |
- local subrepos |
813 |
- _git-r3_set_subrepos "${url}" "${repos[@]}" |
814 |
- |
815 |
- git-r3_fetch "${subrepos[*]}" "${commit}" "${local_id}/${subname}" |
816 |
- fi |
817 |
- |
818 |
- submodules=( "${submodules[@]:3}" ) # shift |
819 |
- done |
820 |
- fi |
821 |
-} |
822 |
- |
823 |
-# @FUNCTION: git-r3_checkout |
824 |
-# @USAGE: [<repo-uri> [<checkout-path> [<local-id>]]] |
825 |
-# @DESCRIPTION: |
826 |
-# Check the previously fetched tree to the working copy. |
827 |
-# |
828 |
-# <repo-uri> specifies the repository URIs, as a space-separated list. |
829 |
-# The first URI will be used as repository group identifier |
830 |
-# and therefore must be used consistently with git-r3_fetch. |
831 |
-# The remaining URIs are not used and therefore may be omitted. |
832 |
-# When not specified, defaults to ${EGIT_REPO_URI}. |
833 |
-# |
834 |
-# <checkout-path> specifies the path to place the checkout. It defaults |
835 |
-# to ${EGIT_CHECKOUT_DIR} if set, otherwise to ${WORKDIR}/${P}. |
836 |
-# |
837 |
-# <local-id> needs to specify the local identifier that was used |
838 |
-# for respective git-r3_fetch. |
839 |
-# |
840 |
-# The checkout operation will write to the working copy, and export |
841 |
-# the repository state into the environment. If the repository contains |
842 |
-# submodules, they will be checked out recursively. |
843 |
-git-r3_checkout() { |
844 |
- debug-print-function ${FUNCNAME} "$@" |
845 |
- |
846 |
- local repos |
847 |
- if [[ ${1} ]]; then |
848 |
- repos=( ${1} ) |
849 |
- elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then |
850 |
- repos=( "${EGIT_REPO_URI[@]}" ) |
851 |
- else |
852 |
- repos=( ${EGIT_REPO_URI} ) |
853 |
- fi |
854 |
- |
855 |
- local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} |
856 |
- local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} |
857 |
- |
858 |
- local -x GIT_DIR |
859 |
- _git-r3_set_gitdir "${repos[0]}" |
860 |
- |
861 |
- einfo "Checking out \e[1m${repos[0]}\e[22m to \e[1m${out_dir}\e[22m ..." |
862 |
- |
863 |
- if ! git cat-file -e refs/git-r3/"${local_id}"/__main__; then |
864 |
- die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?" |
865 |
- fi |
866 |
- local remote_ref=$( |
867 |
- git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__ |
868 |
- ) |
869 |
- local new_commit_id=$( |
870 |
- git rev-parse --verify refs/git-r3/"${local_id}"/__main__ |
871 |
- ) |
872 |
- |
873 |
- git-r3_sub_checkout() { |
874 |
- local orig_repo=${GIT_DIR} |
875 |
- local -x GIT_DIR=${out_dir}/.git |
876 |
- local -x GIT_WORK_TREE=${out_dir} |
877 |
- |
878 |
- mkdir -p "${out_dir}" || die |
879 |
- |
880 |
- # use git init+fetch instead of clone since the latter doesn't like |
881 |
- # non-empty directories. |
882 |
- |
883 |
- git init --quiet || die |
884 |
- # setup 'alternates' to avoid copying objects |
885 |
- echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die |
886 |
- # now copy the refs |
887 |
- cp -R "${orig_repo}"/refs/* "${GIT_DIR}"/refs/ || die |
888 |
- if [[ -f ${orig_repo}/packed-refs ]]; then |
889 |
- cp "${orig_repo}"/packed-refs "${GIT_DIR}"/packed-refs || die |
890 |
- fi |
891 |
- |
892 |
- # (no need to copy HEAD, we will set it via checkout) |
893 |
- |
894 |
- if [[ -f ${orig_repo}/shallow ]]; then |
895 |
- cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die |
896 |
- fi |
897 |
- |
898 |
- set -- git checkout --quiet |
899 |
- if [[ ${remote_ref} ]]; then |
900 |
- set -- "${@}" "${remote_ref#refs/heads/}" |
901 |
- else |
902 |
- set -- "${@}" "${new_commit_id}" |
903 |
- fi |
904 |
- echo "${@}" >&2 |
905 |
- "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed" |
906 |
- } |
907 |
- git-r3_sub_checkout |
908 |
- unset -f git-r3_sub_checkout |
909 |
- |
910 |
- local old_commit_id=$( |
911 |
- git rev-parse --quiet --verify refs/git-r3/"${local_id}"/__old__ |
912 |
- ) |
913 |
- if [[ ! ${old_commit_id} ]]; then |
914 |
- echo "GIT NEW branch -->" |
915 |
- echo " repository: ${repos[0]}" |
916 |
- echo " at the commit: ${new_commit_id}" |
917 |
- else |
918 |
- # diff against previous revision |
919 |
- echo "GIT update -->" |
920 |
- echo " repository: ${repos[0]}" |
921 |
- # write out message based on the revisions |
922 |
- if [[ "${old_commit_id}" != "${new_commit_id}" ]]; then |
923 |
- echo " updating from commit: ${old_commit_id}" |
924 |
- echo " to commit: ${new_commit_id}" |
925 |
- |
926 |
- git --no-pager diff --stat \ |
927 |
- ${old_commit_id}..${new_commit_id} |
928 |
- else |
929 |
- echo " at the commit: ${new_commit_id}" |
930 |
- fi |
931 |
- fi |
932 |
- git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die |
933 |
- |
934 |
- # recursively checkout submodules |
935 |
- if [[ -f ${out_dir}/.gitmodules ]]; then |
936 |
- local submodules |
937 |
- _git-r3_set_submodules \ |
938 |
- "$(<"${out_dir}"/.gitmodules)" |
939 |
- |
940 |
- while [[ ${submodules[@]} ]]; do |
941 |
- local subname=${submodules[0]} |
942 |
- local url=${submodules[1]} |
943 |
- local path=${submodules[2]} |
944 |
- |
945 |
- # use only submodules for which path does exist |
946 |
- # (this is in par with 'git submodule'), bug #551100 |
947 |
- if [[ -d ${out_dir}/${path} ]]; then |
948 |
- local subrepos |
949 |
- _git-r3_set_subrepos "${url}" "${repos[@]}" |
950 |
- |
951 |
- git-r3_checkout "${subrepos[*]}" "${out_dir}/${path}" \ |
952 |
- "${local_id}/${subname}" |
953 |
- fi |
954 |
- |
955 |
- submodules=( "${submodules[@]:3}" ) # shift |
956 |
- done |
957 |
- fi |
958 |
- |
959 |
- # keep this *after* submodules |
960 |
- export EGIT_DIR=${GIT_DIR} |
961 |
- export EGIT_VERSION=${new_commit_id} |
962 |
-} |
963 |
- |
964 |
-# @FUNCTION: git-r3_peek_remote_ref |
965 |
-# @USAGE: [<repo-uri> [<remote-ref>]] |
966 |
-# @DESCRIPTION: |
967 |
-# Peek the reference in the remote repository and print the matching |
968 |
-# (newest) commit SHA1. |
969 |
-# |
970 |
-# <repo-uri> specifies the repository URIs to fetch from, as a space- |
971 |
-# -separated list. When not specified, defaults to ${EGIT_REPO_URI}. |
972 |
-# |
973 |
-# <remote-ref> specifies the remote ref to peek. It is preferred to use |
974 |
-# 'refs/heads/<branch-name>' for branches and 'refs/tags/<tag-name>' |
975 |
-# for tags. Alternatively, 'HEAD' may be used for upstream default |
976 |
-# branch. Defaults to the first of EGIT_COMMIT, EGIT_BRANCH or literal |
977 |
-# 'HEAD' that is set to a non-null value. |
978 |
-# |
979 |
-# The operation will be done purely on the remote, without using local |
980 |
-# storage. If commit SHA1 is provided as <remote-ref>, the function will |
981 |
-# fail due to limitations of git protocol. |
982 |
-# |
983 |
-# On success, the function returns 0 and writes hexadecimal commit SHA1 |
984 |
-# to stdout. On failure, the function returns 1. |
985 |
-git-r3_peek_remote_ref() { |
986 |
- debug-print-function ${FUNCNAME} "$@" |
987 |
- |
988 |
- local repos |
989 |
- if [[ ${1} ]]; then |
990 |
- repos=( ${1} ) |
991 |
- elif [[ $(declare -p EGIT_REPO_URI) == "declare -a"* ]]; then |
992 |
- repos=( "${EGIT_REPO_URI[@]}" ) |
993 |
- else |
994 |
- repos=( ${EGIT_REPO_URI} ) |
995 |
- fi |
996 |
- |
997 |
- local branch=${EGIT_BRANCH:+refs/heads/${EGIT_BRANCH}} |
998 |
- local remote_ref=${2:-${EGIT_COMMIT:-${branch:-HEAD}}} |
999 |
- |
1000 |
- [[ ${repos[@]} ]] || die "No URI provided and EGIT_REPO_URI unset" |
1001 |
- |
1002 |
- local r success |
1003 |
- for r in "${repos[@]}"; do |
1004 |
- einfo "Peeking \e[1m${remote_ref}\e[22m on \e[1m${r}\e[22m ..." >&2 |
1005 |
- |
1006 |
- local lookup_ref |
1007 |
- if [[ ${remote_ref} == refs/* || ${remote_ref} == HEAD ]] |
1008 |
- then |
1009 |
- lookup_ref=${remote_ref} |
1010 |
- else |
1011 |
- # ls-remote by commit is going to fail anyway, |
1012 |
- # so we may as well pass refs/tags/ABCDEF... |
1013 |
- lookup_ref=refs/tags/${remote_ref} |
1014 |
- fi |
1015 |
- |
1016 |
- # split on whitespace |
1017 |
- local ref=( |
1018 |
- $(git ls-remote "${r}" "${lookup_ref}") |
1019 |
- ) |
1020 |
- |
1021 |
- if [[ ${ref[0]} ]]; then |
1022 |
- echo "${ref[0]}" |
1023 |
- return 0 |
1024 |
- fi |
1025 |
- done |
1026 |
- |
1027 |
- return 1 |
1028 |
-} |
1029 |
- |
1030 |
-git-r3_src_fetch() { |
1031 |
- debug-print-function ${FUNCNAME} "$@" |
1032 |
- |
1033 |
- if [[ ! ${EGIT3_STORE_DIR} && ${EGIT_STORE_DIR} ]]; then |
1034 |
- ewarn "You have set EGIT_STORE_DIR but not EGIT3_STORE_DIR. Please consider" |
1035 |
- ewarn "setting EGIT3_STORE_DIR for git-r3.eclass. It is recommended to use" |
1036 |
- ewarn "a different directory than EGIT_STORE_DIR to ease removing old clones" |
1037 |
- ewarn "when git-2 eclass becomes deprecated." |
1038 |
- fi |
1039 |
- |
1040 |
- _git-r3_env_setup |
1041 |
- git-r3_fetch |
1042 |
-} |
1043 |
- |
1044 |
-git-r3_src_unpack() { |
1045 |
- debug-print-function ${FUNCNAME} "$@" |
1046 |
- |
1047 |
- _git-r3_env_setup |
1048 |
- git-r3_src_fetch |
1049 |
- git-r3_checkout |
1050 |
-} |
1051 |
- |
1052 |
-# https://bugs.gentoo.org/show_bug.cgi?id=482666 |
1053 |
-git-r3_pkg_needrebuild() { |
1054 |
- debug-print-function ${FUNCNAME} "$@" |
1055 |
- |
1056 |
- local new_commit_id=$(git-r3_peek_remote_ref) |
1057 |
- [[ ${new_commit_id} && ${EGIT_VERSION} ]] || die "Lookup failed" |
1058 |
- |
1059 |
- if [[ ${EGIT_VERSION} != ${new_commit_id} ]]; then |
1060 |
- einfo "Update from \e[1m${EGIT_VERSION}\e[22m to \e[1m${new_commit_id}\e[22m" |
1061 |
- else |
1062 |
- einfo "Local and remote at \e[1m${EGIT_VERSION}\e[22m" |
1063 |
- fi |
1064 |
- |
1065 |
- [[ ${EGIT_VERSION} != ${new_commit_id} ]] |
1066 |
-} |
1067 |
- |
1068 |
-# 'export' locally until this gets into EAPI |
1069 |
-pkg_needrebuild() { git-r3_pkg_needrebuild; } |
1070 |
- |
1071 |
-_GIT_R3=1 |
1072 |
-fi |