@@ -2197,24 +2197,27 @@ def _GetSubmodules(self):
2197
2197
2198
2198
def get_submodules (gitdir , rev ):
2199
2199
# Parse .gitmodules for submodule sub_paths and sub_urls.
2200
- sub_paths , sub_urls = parse_gitmodules (gitdir , rev )
2200
+ sub_paths , sub_urls , sub_shallows = parse_gitmodules (gitdir , rev )
2201
2201
if not sub_paths :
2202
2202
return []
2203
2203
# Run `git ls-tree` to read SHAs of submodule object, which happen
2204
2204
# to be revision of submodule repository.
2205
2205
sub_revs = git_ls_tree (gitdir , rev , sub_paths )
2206
2206
submodules = []
2207
- for sub_path , sub_url in zip (sub_paths , sub_urls ):
2207
+ for sub_path , sub_url , sub_shallow in zip (
2208
+ sub_paths , sub_urls , sub_shallows
2209
+ ):
2208
2210
try :
2209
2211
sub_rev = sub_revs [sub_path ]
2210
2212
except KeyError :
2211
2213
# Ignore non-exist submodules.
2212
2214
continue
2213
- submodules .append ((sub_rev , sub_path , sub_url ))
2215
+ submodules .append ((sub_rev , sub_path , sub_url , sub_shallow ))
2214
2216
return submodules
2215
2217
2216
2218
re_path = re .compile (r"^submodule\.(.+)\.path=(.*)$" )
2217
2219
re_url = re .compile (r"^submodule\.(.+)\.url=(.*)$" )
2220
+ re_shallow = re .compile (r"^submodule\.(.+)\.shallow=(.*)$" )
2218
2221
2219
2222
def parse_gitmodules (gitdir , rev ):
2220
2223
cmd = ["cat-file" , "blob" , "%s:.gitmodules" % rev ]
@@ -2228,9 +2231,9 @@ def parse_gitmodules(gitdir, rev):
2228
2231
gitdir = gitdir ,
2229
2232
)
2230
2233
except GitError :
2231
- return [], []
2234
+ return [], [], []
2232
2235
if p .Wait () != 0 :
2233
- return [], []
2236
+ return [], [], []
2234
2237
2235
2238
gitmodules_lines = []
2236
2239
fd , temp_gitmodules_path = tempfile .mkstemp ()
@@ -2247,16 +2250,17 @@ def parse_gitmodules(gitdir, rev):
2247
2250
gitdir = gitdir ,
2248
2251
)
2249
2252
if p .Wait () != 0 :
2250
- return [], []
2253
+ return [], [], []
2251
2254
gitmodules_lines = p .stdout .split ("\n " )
2252
2255
except GitError :
2253
- return [], []
2256
+ return [], [], []
2254
2257
finally :
2255
2258
platform_utils .remove (temp_gitmodules_path )
2256
2259
2257
2260
names = set ()
2258
2261
paths = {}
2259
2262
urls = {}
2263
+ shallows = {}
2260
2264
for line in gitmodules_lines :
2261
2265
if not line :
2262
2266
continue
@@ -2270,10 +2274,16 @@ def parse_gitmodules(gitdir, rev):
2270
2274
names .add (m .group (1 ))
2271
2275
urls [m .group (1 )] = m .group (2 )
2272
2276
continue
2277
+ m = re_shallow .match (line )
2278
+ if m :
2279
+ names .add (m .group (1 ))
2280
+ shallows [m .group (1 )] = m .group (2 )
2281
+ continue
2273
2282
names = sorted (names )
2274
2283
return (
2275
2284
[paths .get (name , "" ) for name in names ],
2276
2285
[urls .get (name , "" ) for name in names ],
2286
+ [shallows .get (name , "" ) for name in names ],
2277
2287
)
2278
2288
2279
2289
def git_ls_tree (gitdir , rev , paths ):
@@ -2314,7 +2324,7 @@ def GetDerivedSubprojects(self):
2314
2324
# If git repo does not exist yet, querying its submodules will
2315
2325
# mess up its states; so return here.
2316
2326
return result
2317
- for rev , path , url in self ._GetSubmodules ():
2327
+ for rev , path , url , shallow in self ._GetSubmodules ():
2318
2328
name = self .manifest .GetSubprojectName (self , path )
2319
2329
(
2320
2330
relpath ,
@@ -2336,6 +2346,7 @@ def GetDerivedSubprojects(self):
2336
2346
review = self .remote .review ,
2337
2347
revision = self .remote .revision ,
2338
2348
)
2349
+ clone_depth = 1 if shallow .lower () == "true" else None
2339
2350
subproject = Project (
2340
2351
manifest = self .manifest ,
2341
2352
name = name ,
@@ -2352,6 +2363,7 @@ def GetDerivedSubprojects(self):
2352
2363
sync_s = self .sync_s ,
2353
2364
sync_tags = self .sync_tags ,
2354
2365
parent = self ,
2366
+ clone_depth = clone_depth ,
2355
2367
is_derived = True ,
2356
2368
)
2357
2369
result .append (subproject )
0 commit comments