Skip to content

Commit

Permalink
You can ignore folders using ./folder/* or ./folder now
Browse files Browse the repository at this point in the history
  • Loading branch information
cabello committed Jul 15, 2012
1 parent 6cb0bed commit 13f1ab6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/ignore.c
Expand Up @@ -240,3 +240,39 @@ int filename_filter(struct dirent *dir) {


return 1; return 1;
} }

int filepath_filter(char *filepath) {
int match_pos;
char *pattern = NULL;
int rc = 0;
int i;

if (opts.search_all_files) {
return 1;
}

match_pos = binary_search(filepath, ignore_names, 0, ignore_names_len);
if (match_pos >= 0) {
log_debug("file %s ignored because name matches static pattern %s", filepath, ignore_names[match_pos]);
return 0;
}

for (i = 0; i < ignore_patterns_len; i++) {
pattern = ignore_patterns[i];
if (fnmatch(pattern, filepath, fnmatch_flags) == 0) {
log_debug("file %s ignored because name matches regex pattern %s", filepath, pattern);
return 0;
}
}

if (opts.ackmate_dir_filter != NULL) {
/* we just care about the match, not where the matches are */
rc = pcre_exec(opts.ackmate_dir_filter, NULL, filepath, strlen(filepath), 0, 0, NULL, 0);
if (rc >= 0) {
log_debug("file %s ignored because name matches ackmate dir filter pattern", filepath);
return 0;
}
}

return 1;
}
1 change: 1 addition & 0 deletions src/ignore.h
Expand Up @@ -20,5 +20,6 @@ void load_svn_ignore_patterns(const char *path, const int path_len);


int ignorefile_filter(struct dirent *dir); int ignorefile_filter(struct dirent *dir);
int filename_filter(struct dirent *dir); int filename_filter(struct dirent *dir);
int filepath_filter(char *filepath);


#endif #endif
3 changes: 3 additions & 0 deletions src/search.c
Expand Up @@ -289,6 +289,9 @@ void search_dir(const pcre *re, const pcre_extra *re_extra, const char* path, co
} }


log_debug("dir %s type %i", dir_full_path, dir->d_type); log_debug("dir %s type %i", dir_full_path, dir->d_type);
if ( ! filepath_filter(dir_full_path)) {
goto cleanup;
}


/* TODO: scan files in current dir before going deeper */ /* TODO: scan files in current dir before going deeper */
if (dir->d_type == DT_DIR) { if (dir->d_type == DT_DIR) {
Expand Down

0 comments on commit 13f1ab6

Please sign in to comment.