1 |
This one's pretty similar to what we had before though a bit simpler. |
2 |
For one, we don't have the 'smart fetching' anymore since it was complex |
3 |
and unsafe. |
4 |
|
5 |
Implementation-wise 'shallow' mode differs only when starting a new |
6 |
branch. In that case, '--depth 1' is used to avoid fetching earlier |
7 |
commits. Further updates are done through plain 'git fetch'. |
8 |
|
9 |
So, if you enable shallow mode after cloning a repository in 'single' |
10 |
mode, nothing will actually change :). However, if you switch branch |
11 |
the repository will become partially 'shallow'. |
12 |
|
13 |
This also comes with --unshallow support that requires >=git-1.8.2.1. |
14 |
When 'single' or 'mirror' mode is requested, and the repository is |
15 |
shallow, it guarantees that at least the requested branch is |
16 |
unshallowed and fully useful. |
17 |
--- |
18 |
eclass/git-r3.eclass | 36 +++++++++++++++++++++++++++--------- |
19 |
1 file changed, 27 insertions(+), 9 deletions(-) |
20 |
|
21 |
diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass |
22 |
index 8b7d75d..c9c2da5 100644 |
23 |
--- a/eclass/git-r3.eclass |
24 |
+++ b/eclass/git-r3.eclass |
25 |
@@ -29,13 +29,13 @@ EXPORT_FUNCTIONS src_unpack |
26 |
if [[ ! ${_GIT_R3} ]]; then |
27 |
|
28 |
if [[ ! ${_INHERITED_BY_GIT_2} ]]; then |
29 |
- DEPEND="dev-vcs/git" |
30 |
+ DEPEND=">=dev-vcs/git-1.8.2.1" |
31 |
fi |
32 |
|
33 |
# @ECLASS-VARIABLE: EGIT_CLONE_TYPE |
34 |
# @DESCRIPTION: |
35 |
# Type of clone that should be used against the remote repository. |
36 |
-# This can be either of: 'mirror', 'single'. |
37 |
+# This can be either of: 'mirror', 'single', 'shallow'. |
38 |
# |
39 |
# The 'mirror' type clones all remote branches and tags with complete |
40 |
# history and all notes. EGIT_COMMIT can specify any commit hash. |
41 |
@@ -50,6 +50,12 @@ fi |
42 |
# in the current branch. No purging of old references is done (if you |
43 |
# often switch branches, you may need to remove stale branches |
44 |
# yourself). This mode is suitable for general use. |
45 |
+# |
46 |
+# The 'shallow' type clones only the newest commit on requested branch |
47 |
+# or tag. EGIT_COMMIT can only specify tags, and since the history is |
48 |
+# unavailable calls like 'git describe' will not reference prior tags. |
49 |
+# No purging of old references is done. This mode is intended mostly for |
50 |
+# embedded systems with limited disk space. |
51 |
: ${EGIT_CLONE_TYPE:=single} |
52 |
|
53 |
# @ECLASS-VARIABLE: EGIT3_STORE_DIR |
54 |
@@ -129,7 +135,7 @@ _git-r3_env_setup() { |
55 |
|
56 |
# check the clone type |
57 |
case "${EGIT_CLONE_TYPE}" in |
58 |
- mirror|single) |
59 |
+ mirror|single|shallow) |
60 |
;; |
61 |
*) |
62 |
die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" |
63 |
@@ -249,10 +255,6 @@ _git-r3_set_gitdir() { |
64 |
fi |
65 |
|
66 |
addwrite "${EGIT3_STORE_DIR}" |
67 |
- if [[ -e ${GIT_DIR}/shallow ]]; then |
68 |
- einfo "${GIT_DIR} was a shallow clone, recreating..." |
69 |
- rm -r "${GIT_DIR}" || die |
70 |
- fi |
71 |
if [[ ! -d ${GIT_DIR} ]]; then |
72 |
mkdir "${GIT_DIR}" || die |
73 |
git init --bare || die |
74 |
@@ -428,7 +430,7 @@ git-r3_fetch() { |
75 |
# (we keep it in refs/git-r3 since otherwise --prune interferes) |
76 |
HEAD:refs/git-r3/HEAD |
77 |
) |
78 |
- else # single |
79 |
+ else # single or shallow |
80 |
local fetch_l fetch_r |
81 |
|
82 |
if [[ ${remote_ref} == HEAD ]]; then |
83 |
@@ -468,6 +470,18 @@ git-r3_fetch() { |
84 |
) |
85 |
fi |
86 |
|
87 |
+ if [[ ${EGIT_CLONE_TYPE} == shallow ]]; then |
88 |
+ # use '--depth 1' when fetching a new branch |
89 |
+ if [[ ! $(git rev-parse --quiet --verify "${fetch_r}") ]] |
90 |
+ then |
91 |
+ fetch_command+=( --depth 1 ) |
92 |
+ fi |
93 |
+ else # non-shallow mode |
94 |
+ if [[ -f ${GIT_DIR}/shallow ]]; then |
95 |
+ fetch_command+=( --unshallow ) |
96 |
+ fi |
97 |
+ fi |
98 |
+ |
99 |
set -- "${fetch_command[@]}" |
100 |
echo "${@}" >&2 |
101 |
if "${@}"; then |
102 |
@@ -477,7 +491,7 @@ git-r3_fetch() { |
103 |
"$(_git-r3_find_head refs/git-r3/HEAD \ |
104 |
< <(git show-ref --heads || die))" \ |
105 |
|| die "Unable to update HEAD" |
106 |
- else # single |
107 |
+ else # single or shallow |
108 |
if [[ ${fetch_l} == HEAD ]]; then |
109 |
# find out what branch we fetched as HEAD |
110 |
local head_branch=$(_git-r3_find_head \ |
111 |
@@ -620,6 +634,10 @@ git-r3_checkout() { |
112 |
|
113 |
# (no need to copy HEAD, we will set it via checkout) |
114 |
|
115 |
+ if [[ -f ${orig_repo}/shallow ]]; then |
116 |
+ cp "${orig_repo}"/shallow "${GIT_DIR}"/ || die |
117 |
+ fi |
118 |
+ |
119 |
set -- git checkout --quiet |
120 |
if [[ ${remote_ref} ]]; then |
121 |
set -- "${@}" "${remote_ref#refs/heads/}" |
122 |
-- |
123 |
1.8.3.2 |