From 6551171ed1141e1f112533a6f3699ddb10738088 Mon Sep 17 00:00:00 2001 From: Lorenzo Donati Date: Mon, 29 Jun 2020 16:41:36 +0200 Subject: [PATCH] Added support for hg p4 and cvs ignore files. --- deepcode/constants.py | 7 +++++++ deepcode/files.py | 28 +++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/deepcode/constants.py b/deepcode/constants.py index e40b4e3..78789c5 100644 --- a/deepcode/constants.py +++ b/deepcode/constants.py @@ -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 ================= diff --git a/deepcode/files.py b/deepcode/files.py index 7868869..3789fcf 100644 --- a/deepcode/files.py +++ b/deepcode/files.py @@ -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): """ @@ -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): @@ -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))