summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2017-05-13 02:46:29 +0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:57 +0100
commitbf87c5cd194b5a24c388d6445b413b5f673bc1de (patch)
treebeef4530468ec0502c43a8692b0127fb613e2a4b
parent27d56982c7ba05e86a100b0cca2411ee5ac7a85e (diff)
downloadpoky-bf87c5cd194b5a24c388d6445b413b5f673bc1de.tar.gz
bitbake: fetch/git: support per-branch/per-url depths for shallow
Allow the user to explicitly adjust the depth for named urls/branches. The un-suffixed BB_GIT_SHALLOW_DEPTH is used as the default. Example usage: BB_GIT_SHALLOW_DEPTH = "1" BB_GIT_SHALLOW_DEPTH_doc = "0" BB_GIT_SHALLOW_DEPTH_meta = "0" (Bitbake rev: 9dfc517e5bcc6dd203a0ad685cc884676d2984c4) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/fetch2/git.py61
-rw-r--r--bitbake/lib/bb/tests/fetch.py35
2 files changed, 73 insertions, 23 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 0412f9ff51..250109bf9e 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -70,6 +70,7 @@ Supported SRC_URI options are:
70# with this program; if not, write to the Free Software Foundation, Inc., 70# with this program; if not, write to the Free Software Foundation, Inc.,
71# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 71# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72 72
73import collections
73import errno 74import errno
74import os 75import os
75import re 76import re
@@ -178,12 +179,43 @@ class Git(FetchMethod):
178 if ud.bareclone: 179 if ud.bareclone:
179 ud.cloneflags += " --mirror" 180 ud.cloneflags += " --mirror"
180 181
182 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
183
184 depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH")
185 if depth_default is not None:
186 try:
187 depth_default = int(depth_default or 0)
188 except ValueError:
189 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH: %s" % depth_default)
190 else:
191 if depth_default < 0:
192 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH: %s" % depth_default)
193 else:
194 depth_default = 1
195 ud.shallow_depths = collections.defaultdict(lambda: depth_default)
196
181 ud.branches = {} 197 ud.branches = {}
182 for pos, name in enumerate(ud.names): 198 for pos, name in enumerate(ud.names):
183 branch = branches[pos] 199 branch = branches[pos]
184 ud.branches[name] = branch 200 ud.branches[name] = branch
185 ud.unresolvedrev[name] = branch 201 ud.unresolvedrev[name] = branch
186 202
203 shallow_depth = d.getVar("BB_GIT_SHALLOW_DEPTH_%s" % name)
204 if shallow_depth is not None:
205 try:
206 shallow_depth = int(shallow_depth or 0)
207 except ValueError:
208 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH_%s: %s" % (name, shallow_depth))
209 else:
210 if shallow_depth < 0:
211 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH_%s: %s" % (name, shallow_depth))
212 ud.shallow_depths[name] = shallow_depth
213
214 if (ud.shallow and
215 all(ud.shallow_depths[n] == 0 for n in ud.names)):
216 # Shallow disabled for this URL
217 ud.shallow = False
218
187 if ud.usehead: 219 if ud.usehead:
188 ud.unresolvedrev['default'] = 'HEAD' 220 ud.unresolvedrev['default'] = 'HEAD'
189 221
@@ -222,23 +254,6 @@ class Git(FetchMethod):
222 mirrortarball = 'git2_%s.tar.gz' % gitsrcname 254 mirrortarball = 'git2_%s.tar.gz' % gitsrcname
223 ud.fullmirror = os.path.join(dl_dir, mirrortarball) 255 ud.fullmirror = os.path.join(dl_dir, mirrortarball)
224 ud.mirrortarballs = [mirrortarball] 256 ud.mirrortarballs = [mirrortarball]
225
226 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
227 if ud.shallow:
228 ud.shallow_depth = d.getVar("BB_GIT_SHALLOW_DEPTH")
229 if ud.shallow_depth is not None:
230 try:
231 ud.shallow_depth = int(ud.shallow_depth or 0)
232 except ValueError:
233 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH: %s" % ud.shallow_depth)
234 else:
235 if not ud.shallow_depth:
236 ud.shallow = False
237 elif ud.shallow_depth < 0:
238 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH: %s" % ud.shallow_depth)
239 else:
240 ud.shallow_depth = 1
241
242 if ud.shallow: 257 if ud.shallow:
243 tarballname = gitsrcname 258 tarballname = gitsrcname
244 if ud.bareclone: 259 if ud.bareclone:
@@ -246,10 +261,12 @@ class Git(FetchMethod):
246 261
247 for name, revision in sorted(ud.revisions.items()): 262 for name, revision in sorted(ud.revisions.items()):
248 tarballname = "%s_%s" % (tarballname, ud.revisions[name][:7]) 263 tarballname = "%s_%s" % (tarballname, ud.revisions[name][:7])
249 if not ud.nobranch: 264 depth = ud.shallow_depths[name]
250 tarballname = "%s-%s" % (tarballname, ud.branches[name]) 265 if depth:
266 tarballname = "%s-%s" % (tarballname, depth)
251 267
252 tarballname = "%s-%s" % (tarballname, ud.shallow_depth) 268 if not ud.nobranch:
269 tarballname = "%s_%s" % (tarballname, "_".join(sorted(ud.branches.values())).replace('/', '.'))
253 270
254 fetcher = self.__class__.__name__.lower() 271 fetcher = self.__class__.__name__.lower()
255 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname) 272 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname)
@@ -370,7 +387,9 @@ class Git(FetchMethod):
370 to_parse, shallow_branches = [], [] 387 to_parse, shallow_branches = [], []
371 for name in ud.names: 388 for name in ud.names:
372 revision = ud.revisions[name] 389 revision = ud.revisions[name]
373 to_parse.append('%s~%d^{}' % (revision, ud.shallow_depth - 1)) 390 depth = ud.shallow_depths[name]
391 if depth:
392 to_parse.append('%s~%d^{}' % (revision, depth - 1))
374 393
375 # For nobranch, we need a ref, otherwise the commits will be 394 # For nobranch, we need a ref, otherwise the commits will be
376 # removed, and for non-nobranch, we truncate the branch to our 395 # removed, and for non-nobranch, we truncate the branch to our
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 019f22a11d..0b0116b455 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -1122,6 +1122,27 @@ class GitShallowTest(FetcherTest):
1122 self.fetch_shallow(disabled=True) 1122 self.fetch_shallow(disabled=True)
1123 self.assertRevCount(2) 1123 self.assertRevCount(2)
1124 1124
1125 def test_shallow_depth_default_override(self):
1126 self.add_empty_file('a')
1127 self.add_empty_file('b')
1128 self.assertRevCount(2, cwd=self.srcdir)
1129
1130 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
1131 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
1132 self.fetch_shallow()
1133 self.assertRevCount(1)
1134
1135 def test_shallow_depth_default_override_disable(self):
1136 self.add_empty_file('a')
1137 self.add_empty_file('b')
1138 self.add_empty_file('c')
1139 self.assertRevCount(3, cwd=self.srcdir)
1140
1141 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1142 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
1143 self.fetch_shallow()
1144 self.assertRevCount(2)
1145
1125 def test_current_shallow_out_of_date_clone(self): 1146 def test_current_shallow_out_of_date_clone(self):
1126 # Create initial git repo 1147 # Create initial git repo
1127 self.add_empty_file('a') 1148 self.add_empty_file('a')
@@ -1206,13 +1227,15 @@ class GitShallowTest(FetcherTest):
1206 uri = self.d.getVar('SRC_URI', True).split()[0] 1227 uri = self.d.getVar('SRC_URI', True).split()[0]
1207 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri 1228 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1208 1229
1209 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2') 1230 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1231 self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
1232 self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
1210 self.d.setVar('SRCREV_master', '${AUTOREV}') 1233 self.d.setVar('SRCREV_master', '${AUTOREV}')
1211 self.d.setVar('SRCREV_a_branch', '${AUTOREV}') 1234 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1212 1235
1213 self.fetch_shallow(uri) 1236 self.fetch_shallow(uri)
1214 1237
1215 self.assertRevCount(3, ['--all']) 1238 self.assertRevCount(4, ['--all'])
1216 self.assertRefs(['master', 'origin/master', 'origin/a_branch']) 1239 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1217 1240
1218 def test_shallow_clone_preferred_over_shallow(self): 1241 def test_shallow_clone_preferred_over_shallow(self):
@@ -1262,6 +1285,14 @@ class GitShallowTest(FetcherTest):
1262 with self.assertRaises(bb.fetch2.FetchError): 1285 with self.assertRaises(bb.fetch2.FetchError):
1263 self.fetch() 1286 self.fetch()
1264 1287
1288 def test_shallow_invalid_depth_default(self):
1289 self.add_empty_file('a')
1290 self.add_empty_file('b')
1291
1292 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
1293 with self.assertRaises(bb.fetch2.FetchError):
1294 self.fetch()
1295
1265 if os.environ.get("BB_SKIP_NETTESTS") == "yes": 1296 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
1266 print("Unset BB_SKIP_NETTESTS to run network tests") 1297 print("Unset BB_SKIP_NETTESTS to run network tests")
1267 else: 1298 else: