1 |
mgorny 14/03/02 11:47:42 |
2 |
|
3 |
Modified: ChangeLog git-r3.eclass |
4 |
Log: |
5 |
Support EGIT_CLONE_TYPE=single. |
6 |
|
7 |
Revision Changes Path |
8 |
1.1157 eclass/ChangeLog |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1157&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?rev=1.1157&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/ChangeLog?r1=1.1156&r2=1.1157 |
13 |
|
14 |
Index: ChangeLog |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v |
17 |
retrieving revision 1.1156 |
18 |
retrieving revision 1.1157 |
19 |
diff -u -r1.1156 -r1.1157 |
20 |
--- ChangeLog 2 Mar 2014 11:47:10 -0000 1.1156 |
21 |
+++ ChangeLog 2 Mar 2014 11:47:41 -0000 1.1157 |
22 |
@@ -1,6 +1,9 @@ |
23 |
# ChangeLog for eclass directory |
24 |
# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 |
25 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1156 2014/03/02 11:47:10 mgorny Exp $ |
26 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1157 2014/03/02 11:47:41 mgorny Exp $ |
27 |
+ |
28 |
+ 02 Mar 2014; Michał Górny <mgorny@g.o> git-r3.eclass: |
29 |
+ Support EGIT_CLONE_TYPE=single. |
30 |
|
31 |
02 Mar 2014; Michał Górny <mgorny@g.o> git-r3.eclass: |
32 |
Introduce EGIT_CLONE_TYPE for future use. |
33 |
|
34 |
|
35 |
|
36 |
1.32 eclass/git-r3.eclass |
37 |
|
38 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.32&view=markup |
39 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?rev=1.32&content-type=text/plain |
40 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/git-r3.eclass?r1=1.31&r2=1.32 |
41 |
|
42 |
Index: git-r3.eclass |
43 |
=================================================================== |
44 |
RCS file: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v |
45 |
retrieving revision 1.31 |
46 |
retrieving revision 1.32 |
47 |
diff -u -r1.31 -r1.32 |
48 |
--- git-r3.eclass 2 Mar 2014 11:47:10 -0000 1.31 |
49 |
+++ git-r3.eclass 2 Mar 2014 11:47:41 -0000 1.32 |
50 |
@@ -1,6 +1,6 @@ |
51 |
# Copyright 1999-2014 Gentoo Foundation |
52 |
# Distributed under the terms of the GNU General Public License v2 |
53 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.31 2014/03/02 11:47:10 mgorny Exp $ |
54 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/git-r3.eclass,v 1.32 2014/03/02 11:47:41 mgorny Exp $ |
55 |
|
56 |
# @ECLASS: git-r3.eclass |
57 |
# @MAINTAINER: |
58 |
@@ -35,7 +35,7 @@ |
59 |
# @ECLASS-VARIABLE: EGIT_CLONE_TYPE |
60 |
# @DESCRIPTION: |
61 |
# Type of clone that should be used against the remote repository. |
62 |
-# This can be either of: 'mirror'. |
63 |
+# This can be either of: 'mirror', 'single'. |
64 |
# |
65 |
# The 'mirror' type clones all remote branches and tags with complete |
66 |
# history and all notes. EGIT_COMMIT can specify any commit hash. |
67 |
@@ -43,7 +43,14 @@ |
68 |
# while fetching. This mode is suitable for cloning the local copy |
69 |
# for development or hosting a local git mirror. However, clones |
70 |
# of repositories with large diverged branches may quickly grow large. |
71 |
-: ${EGIT_CLONE_TYPE:=mirror} |
72 |
+# |
73 |
+# The 'single' type clones only the requested branch or tag. Tags |
74 |
+# referencing commits throughout the branch history are fetched as well, |
75 |
+# and all notes. EGIT_COMMIT can safely specify only hashes |
76 |
+# in the current branch. No purging of old references is done (if you |
77 |
+# often switch branches, you may need to remove stale branches |
78 |
+# yourself). This mode is suitable for general use. |
79 |
+: ${EGIT_CLONE_TYPE:=single} |
80 |
|
81 |
# @ECLASS-VARIABLE: EGIT3_STORE_DIR |
82 |
# @DESCRIPTION: |
83 |
@@ -122,7 +129,7 @@ |
84 |
|
85 |
# check the clone type |
86 |
case "${EGIT_CLONE_TYPE}" in |
87 |
- mirror) |
88 |
+ mirror|single) |
89 |
;; |
90 |
*) |
91 |
die "Invalid EGIT_CLONE_TYPE=${EGIT_CLONE_TYPE}" |
92 |
@@ -305,14 +312,14 @@ |
93 |
[[ ${uri} == file://* || ${uri} == /* ]] |
94 |
} |
95 |
|
96 |
-# @FUNCTION: _git-r3_update_head |
97 |
-# @USAGE: <remote-head-ref> |
98 |
+# @FUNCTION: _git-r3_find_head |
99 |
+# @USAGE: <head-ref> |
100 |
# @INTERNAL |
101 |
# @DESCRIPTION: |
102 |
-# Given a ref to which remote HEAD was fetched, try to match |
103 |
-# a local branch and update symbolic HEAD appropriately. |
104 |
-_git-r3_update_head() |
105 |
-{ |
106 |
+# Given a ref to which remote HEAD was fetched, try to find |
107 |
+# a branch matching the commit. Expects 'git show-ref' |
108 |
+# or 'git ls-remote' output on stdin. |
109 |
+_git-r3_find_head() { |
110 |
debug-print-function ${FUNCNAME} "$@" |
111 |
|
112 |
local head_ref=${1} |
113 |
@@ -332,13 +339,13 @@ |
114 |
matching_ref=${ref} |
115 |
fi |
116 |
fi |
117 |
- done < <(git show-ref --heads || die) |
118 |
+ done |
119 |
|
120 |
if [[ ! ${matching_ref} ]]; then |
121 |
die "Unable to find a matching branch for remote HEAD (${head_hash})" |
122 |
fi |
123 |
|
124 |
- git symbolic-ref HEAD "${matching_ref}" || die |
125 |
+ echo "${matching_ref}" |
126 |
} |
127 |
|
128 |
# @FUNCTION: git-r3_fetch |
129 |
@@ -406,24 +413,85 @@ |
130 |
for r in "${repos[@]}"; do |
131 |
einfo "Fetching ${r} ..." |
132 |
|
133 |
- local fetch_command=( |
134 |
- git fetch --prune "${r}" |
135 |
- # mirror the remote branches as local branches |
136 |
- "refs/heads/*:refs/heads/*" |
137 |
- # pull tags explicitly in order to prune them properly |
138 |
- "refs/tags/*:refs/tags/*" |
139 |
- # notes in case something needs them |
140 |
- "refs/notes/*:refs/notes/*" |
141 |
- # and HEAD in case we need the default branch |
142 |
- # (we keep it in refs/git-r3 since otherwise --prune interferes) |
143 |
- HEAD:refs/git-r3/HEAD |
144 |
- ) |
145 |
+ local fetch_command=( git fetch "${r}" ) |
146 |
+ |
147 |
+ if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then |
148 |
+ fetch_command+=( |
149 |
+ --prune |
150 |
+ # mirror the remote branches as local branches |
151 |
+ "refs/heads/*:refs/heads/*" |
152 |
+ # pull tags explicitly in order to prune them properly |
153 |
+ "refs/tags/*:refs/tags/*" |
154 |
+ # notes in case something needs them |
155 |
+ "refs/notes/*:refs/notes/*" |
156 |
+ # and HEAD in case we need the default branch |
157 |
+ # (we keep it in refs/git-r3 since otherwise --prune interferes) |
158 |
+ HEAD:refs/git-r3/HEAD |
159 |
+ ) |
160 |
+ else # single |
161 |
+ local fetch_l fetch_r |
162 |
+ |
163 |
+ if [[ ${remote_ref} == HEAD ]]; then |
164 |
+ # HEAD |
165 |
+ fetch_l=HEAD |
166 |
+ elif [[ ${remote_ref} == refs/heads/* ]]; then |
167 |
+ # regular branch |
168 |
+ fetch_l=${remote_ref} |
169 |
+ else |
170 |
+ # tag or commit... |
171 |
+ # let ls-remote figure it out |
172 |
+ local tagref=$(git ls-remote "${r}" "refs/tags/${remote_ref}") |
173 |
+ |
174 |
+ # if it was a tag, ls-remote obtained a hash |
175 |
+ if [[ ${tagref} ]]; then |
176 |
+ # tag |
177 |
+ fetch_l=refs/tags/${remote_ref} |
178 |
+ else |
179 |
+ # commit, so we need to fetch the branch |
180 |
+ # and guess where it takes us... |
181 |
+ if [[ ${branch} ]]; then |
182 |
+ fetch_l=${branch} |
183 |
+ else |
184 |
+ fetch_l=HEAD |
185 |
+ fi |
186 |
+ fi |
187 |
+ fi |
188 |
+ |
189 |
+ if [[ ${fetch_l} == HEAD ]]; then |
190 |
+ fetch_r=refs/git-r3/HEAD |
191 |
+ else |
192 |
+ fetch_r=${fetch_l} |
193 |
+ fi |
194 |
+ |
195 |
+ fetch_command+=( |
196 |
+ "${fetch_l}:${fetch_r}" |
197 |
+ ) |
198 |
+ fi |
199 |
|
200 |
set -- "${fetch_command[@]}" |
201 |
echo "${@}" >&2 |
202 |
if "${@}"; then |
203 |
- # find remote HEAD and update our HEAD properly |
204 |
- _git-r3_update_head refs/git-r3/HEAD |
205 |
+ if [[ ${EGIT_CLONE_TYPE} == mirror ]]; then |
206 |
+ # find remote HEAD and update our HEAD properly |
207 |
+ git symbolic-ref HEAD \ |
208 |
+ "$(_git-r3_find_head refs/git-r3/HEAD \ |
209 |
+ < <(git show-ref --heads || die))" \ |
210 |
+ || die "Unable to update HEAD" |
211 |
+ else # single |
212 |
+ if [[ ${fetch_l} == HEAD ]]; then |
213 |
+ # find out what branch we fetched as HEAD |
214 |
+ local head_branch=$(_git-r3_find_head \ |
215 |
+ refs/git-r3/HEAD \ |
216 |
+ < <(git ls-remote --heads "${r}" || die)) |
217 |
+ |
218 |
+ # and move it to its regular place |
219 |
+ git update-ref --no-deref "${head_branch}" \ |
220 |
+ refs/git-r3/HEAD \ |
221 |
+ || die "Unable to sync HEAD branch ${head_branch}" |
222 |
+ git symbolic-ref HEAD "${head_branch}" \ |
223 |
+ || die "Unable to update HEAD" |
224 |
+ fi |
225 |
+ fi |
226 |
|
227 |
# now let's see what the user wants from us |
228 |
local full_remote_ref=$( |