Skip to content

Commit 3f29fbc

Browse files
committed
Python extractor: in overlay mode, traverse only changed files
1 parent 394bc72 commit 3f29fbc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

python/extractor/semmle/traverser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
import os.path
7+
import json
78

89
from semmle.path_filters import filter_from_pattern
910
from semmle.util import Extractable, PY_EXTENSIONS, isdir, islink, listdir
@@ -30,6 +31,12 @@ def __init__(self, options, modulenames, logger):
3031
if not os.path.exists(p) and not options.ignore_missing_modules:
3132
raise FileNotFoundError("'%s' does not exist." % p)
3233
self.paths.add(p)
34+
if 'CODEQL_EXTRACTOR_PYTHON_OVERLAY_CHANGES' in os.environ:
35+
# During overlay extraction, only traverse the files that were changed.
36+
with open(os.environ['CODEQL_EXTRACTOR_PYTHON_OVERLAY_CHANGES'], 'r', encoding='utf-8') as f:
37+
data = json.load(f)
38+
changed_paths = data.get('changes', [])
39+
self.paths = { p for p in changed_paths if p in self.paths }
3340
self.exclude_paths = set([ os.path.abspath(f) for f in options.exclude_file ])
3441
self.exclude = exclude_filter_from_options(options)
3542
self.filter = filter_from_options_and_environment(options)

0 commit comments

Comments
 (0)