Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions deepcode/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@

IGNORE_FILES_NAMES = {
'.gitignore',
'.hgignore',
'.p4ignore',
'.cvsignore',
'.dcignore'
}

MULTI_SYNTAX_IGNORE_FILES_NAMES = {
'.hgignore'
}

MAX_BUCKET_SIZE = 1024 * 1024 * 4

# ================ CLI =================
Expand Down
28 changes: 21 additions & 7 deletions deepcode/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .utils import logger

from .constants import (IGNORES_DEFAULT, IGNORE_FILES_NAMES, MAX_BUCKET_SIZE)
from .constants import (IGNORES_DEFAULT, IGNORE_FILES_NAMES, MULTI_SYNTAX_IGNORE_FILES_NAMES, MAX_BUCKET_SIZE)

def prepare_file_path(filepath):
"""
Expand All @@ -33,15 +33,28 @@ def get_file_content(file_path):
with open(file_path, encoding='utf-8', mode='r') as f:
return f.read()

def parse_file_ignores(file_path):
def parse_file_ignores(file_path, syntaxed):
dirname = os.path.dirname(file_path)
with open(file_path, encoding='utf-8', mode='r') as f:
if syntaxed:
allowed = False
for l in f.readlines():
rule = l.strip().rstrip('/') # Trim whitespaces and ending slash
if rule and not rule.startswith('#'):
yield os.path.join(dirname, rule)
if not rule.startswith('/'):
yield os.path.join(dirname, '**', rule)
if rule and rule != '!' and not rule.startswith('#'):
if syntaxed and ':' in rule:
if rule == 'syntax:glob':
allowed = True
if rule == 'syntax:regex':
allowed = False
if rule.startswith('path:') or rule.startswith('glob:'):
r = rule.split(':',1)[1]
yield os.path.join(dirname, r)
if not r.startswith('/'):
yield os.path.join(dirname, '**', r)
elif not syntaxed or allowed:
yield os.path.join(dirname, rule)
if not rule.startswith('/'):
yield os.path.join(dirname, '**', rule)


def is_ignored(path, file_ignores):
Expand Down Expand Up @@ -78,7 +91,8 @@ def collect_bundle_files(paths, file_filter, symlinks_enabled=False, file_ignore
continue

if entry.name in IGNORE_FILES_NAMES:
for ignore_rule in parse_file_ignores(entry.path):
syntaxed = True if entry.name in MULTI_SYNTAX_IGNORE_FILES_NAMES else False
for ignore_rule in parse_file_ignores(entry.path, syntaxed):
local_file_ignores.add(ignore_rule)
local_ignore_file = True
logger.debug('recognized ignore rules in file --> {}'.format(entry.path))
Expand Down