Skip to content

[speedfix] Ignore all files and folders .gitignore while copying #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2020
Merged
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
28 changes: 27 additions & 1 deletion src/analyze_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@
from language.detect_language import supported_languages
from datetime import datetime
import logging
import fnmatch
import time

module_logger = logging.getLogger("main.analyze_libraries")

def ignore_gitignore(basedir):
"""
Function that can be used as copytree() ignore parameter using a glob style parameter.
Reads the .gitignore (if exists) and adding it to an ignore array.
"""
if os.path.isfile(basedir+'/.gitignore'):
with open(basedir+'/.gitignore') as f:
gitignores = f.readlines()
else:
gitignores = []

gitignores = [x.strip() for x in gitignores]
filtered = []
for pattern in gitignores:
if (pattern != "" and pattern[0] != "#"): # Strip comments and linebreaks
filtered.append(pattern.rstrip('/').lstrip('/')) # Remove first and last char slashes to comply w/ glob
gitignores = filtered

def _ignore_gitignore(path, names):
ignored_names = []
for pattern in gitignores:
ignored_names.extend(fnmatch.filter(names, pattern))
return set(ignored_names)
return _ignore_gitignore


class AnalyzeLibraries:
def __init__(self, commit_list, author_emails, basedir, skip, commit_size_limit, file_size_limit):
Expand All @@ -38,7 +64,7 @@ def get_libraries(self):

_log_info("Copying the repository to a temporary location, this can take a while...")
try:
shutil.copytree(self.basedir, tmp_repo_path, symlinks=True)
shutil.copytree(self.basedir, tmp_repo_path, symlinks=True, ignore=ignore_gitignore(self.basedir))
except shutil.Error as e:
module_logger.debug("Shutil error messages: {}.".format(str(e)))
_log_info("Finished copying the repository to", tmp_repo_path)
Expand Down