text stringlengths 0 828 |
|---|
result = IgnoreListCollection() |
if root_dir is None: |
if git_dir is None: |
raise ValueError(""root_dir or git_dir must be specified"") |
root_dir = os.path.dirname(os.path.abspath(git_dir)) |
def parse(filename, root=None): |
if os.path.isfile(filename): |
if root is None: |
root = os.path.dirname(os.path.abspath(filename)) |
with open(filename) as fp: |
result.parse(fp, root) |
result.append(IgnoreList(root_dir)) |
if ignore_file is not None: |
parse(ignore_file) |
for filename in additional_files: |
parse(filename) |
if git_dir is not None: |
parse(os.path.join(git_dir, 'info', 'exclude'), root_dir) |
if global_: |
# TODO: Read the core.excludeFiles configuration value. |
parse(os.path.expanduser('~/.gitignore'), root_dir) |
if defaults: |
result.append(get_defaults(root_dir)) |
return result" |
1400,"def walk(patterns, dirname): |
"""""" |
Like #os.walk(), but filters the files and directories that are excluded by |
the specified *patterns*. |
# Arguments |
patterns (IgnoreList, IgnoreListCollection): Can also be any object that |
implements the #IgnoreList.match() interface. |
dirname (str): The directory to walk. |
"""""" |
join = os.path.join |
for root, dirs, files in os.walk(dirname, topdown=True): |
dirs[:] = [d for d in dirs if patterns.match(join(root, d), True) != MATCH_IGNORE] |
files[:] = [f for f in files if patterns.match(join(root, f), False) != MATCH_IGNORE] |
yield root, dirs, files" |
1401,"def parse(self, lines): |
"""""" |
Parses the `.gitignore` file represented by the *lines*. |
"""""" |
if isinstance(lines, str): |
lines = lines.split('\n') |
sub = _re.sub |
for line in lines: |
if line.endswith('\n'): |
line = line[:-1] |
line = line.lstrip() |
if not line.startswith('#'): |
invert = False |
if line.startswith('!'): |
line = line[1:] |
invert = True |
while line.endswith(' ') and line[-2:] != '\ ': |
line = line[:-1] |
line = sub(r'\\([!# ])', r'\1', line) |
if '/' in line and not line.startswith('/'): |
# Patterns with a slash can only be matched absolute. |
line = '/' + line |
self.patterns.append(Pattern(line, invert))" |
1402,"def match(self, filename, isdir): |
"""""" |
Match the specified *filename*. If *isdir* is False, directory-only |
patterns will be ignored. |
Returns one of |
- #MATCH_DEFAULT |
- #MATCH_IGNORE |
- #MATCH_INCLUDE |
"""""" |
fnmatch = _fnmatch.fnmatch |
ignored = False |
filename = self.convert_path(filename) |
basename = os.path.basename(filename) |
for pattern in self.patterns: |
if pattern.dir_only and not isdir: |
continue |
if (not ignored or pattern.invert) and pattern.match(filename): |
if pattern.invert: # This file is definitely NOT ignored, no matter what other patterns match |
return MATCH_INCLUDE |
ignored = True |
if ignored: |
return MATCH_IGNORE |
else: |
return MATCH_DEFAULT" |
1403,"def parse(self, lines, root): |
"""""" |
Shortcut for #IgnoreList.parse() and #IgnoreListCollection.append(). |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.