Skip entirely excluded directories when handling dockerignore.

This is pure optimization to not recurse into directories when
	there are no chances any file will be included.

Signed-off-by: mefyl <quentin.hocquet@docker.com>
This commit is contained in:
mefyl 2018-02-19 12:48:17 +01:00
parent bb3ad64060
commit 3b464f983e
No known key found for this signature in database
GPG Key ID: 0891F9C2A28563BB
1 changed files with 4 additions and 0 deletions

View File

@ -91,6 +91,10 @@ def walk(root, patterns, default=True):
matched = default if hit is None else hit
sub = list(filter(lambda p: p[1], sub))
if os.path.isdir(cur):
# Entirely skip directories if there are no chance any subfile will
# be included.
if all(not p[0] for p in sub) and not matched:
continue
children = False
for r in (os.path.join(f, p) for p in walk(cur, sub, matched)):
yield r