Permalink
Browse files

Merge master. Fix conflict.

  • Loading branch information...
2 parents b64de8f + ee0e507 commit 5e9a49fcb1f998acd573eef42c40cbc312c4af3b @ggreer committed Aug 22, 2012
Showing with 46 additions and 41 deletions.
  1. +44 −41 src/ignore.c
  2. +2 −0 src/ignore.h
View
@@ -72,6 +72,33 @@ void cleanup_ignore_patterns() {
free(ignore_names);
}
+/* For loading git/svn/hg ignore patterns */
+void load_ignore_patterns(const char *ignore_filename) {
+ FILE *fp = NULL;
+ fp = fopen(ignore_filename, "r");
+ if (fp == NULL) {
+ log_debug("Skipping ignore file %s", ignore_filename);
+ return;
+ }
+
+ char *line = NULL;
+ ssize_t line_len = 0;
+ size_t line_cap = 0;
+
+ while ((line_len = getline(&line, &line_cap, fp)) > 0) {
+ if (line_len == 0 || line[0] == '\n') {
+ continue;
+ }
+ if (line[line_len-1] == '\n') {
+ line[line_len-1] = '\0'; /* kill the \n */
+ }
+ add_ignore_pattern(line);
+ }
+
+ free(line);
+ fclose(fp);
+}
+
void load_svn_ignore_patterns(const char *path, const int path_len) {
FILE *fp = NULL;
char *dir_prop_base = malloc(path_len + strlen(SVN_DIR_PROP_BASE) + 1);
@@ -143,39 +170,26 @@ void load_svn_ignore_patterns(const char *path, const int path_len) {
fclose(fp);
}
-/* For loading git/svn/hg ignore patterns */
-void load_ignore_patterns(const char *ignore_filename) {
- FILE *fp = NULL;
- fp = fopen(ignore_filename, "r");
- if (fp == NULL) {
- log_debug("Skipping ignore file %s", ignore_filename);
- return;
- }
-
- char *line = NULL;
- ssize_t line_len = 0;
- size_t line_cap = 0;
+int ackmate_dir_match(const char* dir_name) {
+ int rc = 0;
- while ((line_len = getline(&line, &line_cap, fp)) > 0) {
- if (line_len == 0 || line[0] == '\n') {
- continue;
- }
- if (line[line_len-1] == '\n') {
- line[line_len-1] = '\0'; /* kill the \n */
+ 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, dir_name, strlen(dir_name), 0, 0, NULL, 0);
+ if (rc >= 0) {
+ log_debug("file %s ignored because name matches ackmate dir filter pattern", dir_name);
+ return 1;
}
- add_ignore_pattern(line);
}
- free(line);
- fclose(fp);
+ return 0;
}
/* This function is REALLY HOT. It gets called for every file */
int filename_filter(struct dirent *dir) {
const char *filename = dir->d_name;
int match_pos;
char *pattern = NULL;
- int rc = 0;
int i;
if (!opts.follow_symlinks && dir->d_type == DT_LNK) {
@@ -204,6 +218,10 @@ int filename_filter(struct dirent *dir) {
return 0;
}
+ if (ackmate_dir_match(dir->d_name)) {
+ return 0;
+ }
+
for (i = 0; i < ignore_patterns_len; i++) {
pattern = ignore_patterns[i];
if (fnmatch(pattern, filename, fnmatch_flags) == 0) {
@@ -212,22 +230,12 @@ int filename_filter(struct dirent *dir) {
}
}
- 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, dir->d_name, strlen(dir->d_name), 0, 0, NULL, 0);
- if (rc >= 0) {
- log_debug("file %s ignored because name matches ackmate dir filter pattern", dir->d_name);
- return 0;
- }
- }
-
return 1;
}
int filepath_filter(char *filepath) {
int match_pos;
char *pattern = NULL;
- int rc = 0;
int i;
if (opts.search_all_files) {
@@ -245,6 +253,10 @@ int filepath_filter(char *filepath) {
return 0;
}
+ if (ackmate_dir_match(filepath)) {
+ return 0;
+ }
+
for (i = 0; i < ignore_patterns_len; i++) {
pattern = ignore_patterns[i];
if (fnmatch(pattern, filepath, fnmatch_flags) == 0) {
@@ -253,14 +265,5 @@ int filepath_filter(char *filepath) {
}
}
- 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;
}
View
@@ -18,6 +18,8 @@ void cleanup_ignore_patterns();
void load_ignore_patterns(const char *ignore_filename);
void load_svn_ignore_patterns(const char *path, const int path_len);
+int ackmate_dir_match(const char* dir_name);
+
int filename_filter(struct dirent *dir);
int filepath_filter(char *filepath);

0 comments on commit 5e9a49f

Please sign in to comment.