1 |
commit: 539d635ed929d982cc1ab32ec685403c2d2694e3 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 17 23:19:33 2017 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 28 09:14:16 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=539d635e |
7 |
|
8 |
git-r3.eclass: Support checking out specific subdirectories |
9 |
|
10 |
Support limiting the git checkout to specific subdirectories of the git |
11 |
tree, using 'git checkout ... -- <paths>...' The main use case for this |
12 |
is doing partial checkouts of very large repositories where only a small |
13 |
subset of files is necessary. Doing partial checkouts can save both |
14 |
time and disk space which can be important in large intertwined |
15 |
projects such as LLVM+Clang. |
16 |
|
17 |
eclass/git-r3.eclass | 20 +++++++++++++++++--- |
18 |
1 file changed, 17 insertions(+), 3 deletions(-) |
19 |
|
20 |
diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass |
21 |
index c9d2731a64f..caf4e8d003e 100644 |
22 |
--- a/eclass/git-r3.eclass |
23 |
+++ b/eclass/git-r3.eclass |
24 |
@@ -803,7 +803,7 @@ git-r3_fetch() { |
25 |
} |
26 |
|
27 |
# @FUNCTION: git-r3_checkout |
28 |
-# @USAGE: [<repo-uri> [<checkout-path> [<local-id>]]] |
29 |
+# @USAGE: [<repo-uri> [<checkout-path> [<local-id> [<checkout-paths>...]]]] |
30 |
# @DESCRIPTION: |
31 |
# Check the previously fetched tree to the working copy. |
32 |
# |
33 |
@@ -819,6 +819,12 @@ git-r3_fetch() { |
34 |
# <local-id> needs to specify the local identifier that was used |
35 |
# for respective git-r3_fetch. |
36 |
# |
37 |
+# If <checkout-paths> are specified, then the specified paths are passed |
38 |
+# to 'git checkout' to effect a partial checkout. Please note that such |
39 |
+# checkout will not cause the repository to switch branches, |
40 |
+# and submodules will be skipped at the moment. The submodules matching |
41 |
+# those paths might be checked out in a future version of the eclass. |
42 |
+# |
43 |
# The checkout operation will write to the working copy, and export |
44 |
# the repository state into the environment. If the repository contains |
45 |
# submodules, they will be checked out recursively. |
46 |
@@ -836,6 +842,7 @@ git-r3_checkout() { |
47 |
|
48 |
local out_dir=${2:-${EGIT_CHECKOUT_DIR:-${WORKDIR}/${P}}} |
49 |
local local_id=${3:-${CATEGORY}/${PN}/${SLOT%/*}} |
50 |
+ local checkout_paths=( "${@:4}" ) |
51 |
|
52 |
local -x GIT_DIR |
53 |
_git-r3_set_gitdir "${repos[0]}" |
54 |
@@ -883,6 +890,9 @@ git-r3_checkout() { |
55 |
else |
56 |
set -- "${@}" "${new_commit_id}" |
57 |
fi |
58 |
+ if [[ ${checkout_paths[@]} ]]; then |
59 |
+ set -- "${@}" -- "${checkout_paths[@]}" |
60 |
+ fi |
61 |
echo "${@}" >&2 |
62 |
"${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed" |
63 |
} |
64 |
@@ -905,8 +915,12 @@ git-r3_checkout() { |
65 |
echo " updating from commit: ${old_commit_id}" |
66 |
echo " to commit: ${new_commit_id}" |
67 |
|
68 |
- git --no-pager diff --stat \ |
69 |
+ set -- git --no-pager diff --stat \ |
70 |
${old_commit_id}..${new_commit_id} |
71 |
+ if [[ ${checkout_paths[@]} ]]; then |
72 |
+ set -- "${@}" -- "${checkout_paths[@]}" |
73 |
+ fi |
74 |
+ "${@}" |
75 |
else |
76 |
echo " at the commit: ${new_commit_id}" |
77 |
fi |
78 |
@@ -914,7 +928,7 @@ git-r3_checkout() { |
79 |
git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die |
80 |
|
81 |
# recursively checkout submodules |
82 |
- if [[ -f ${out_dir}/.gitmodules ]]; then |
83 |
+ if [[ -f ${out_dir}/.gitmodules && ! ${checkout_paths} ]]; then |
84 |
local submodules |
85 |
_git-r3_set_submodules \ |
86 |
"$(<"${out_dir}"/.gitmodules)" |