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

Replies