Permalink
Browse files

Initial support for .gitignore patterns that start with a slash.

  • Loading branch information...
1 parent 61da3aa commit 4148d6a58c70fb636ff70b785f33c54b0f9242d1 @ggreer committed Jan 10, 2013
Showing with 22 additions and 5 deletions.
  1. +20 −5 src/ignore.c
  2. +1 −0 src/scandir.h
  3. +1 −0 src/search.c
View
@@ -66,11 +66,6 @@ void add_ignore_pattern(ignores *ig, const char* pattern) {
int i;
int pattern_len;
- /* Skip leading / — which, in .gitignore, doesn't mean filesystem root. */
- if ('/' == pattern[0]) {
- pattern += 1;
- }
-
/* Strip off the leading ./ so that matches are more likely. */
if (strncmp(pattern, "./", 2) == 0) {
pattern += 2;
@@ -308,6 +303,26 @@ int filename_filter(const char *path, const struct dirent *dir, void *baton) {
}
}
+ /* TODO: copy-pasted from above */
+ if (scandir_baton->level == 0) {
+ char *temp2; /* horrible variable name, I know */
+ ag_asprintf(&temp, "/%s", filename);
+ if (path_ignore_search(ig, path_start, temp)) {
+ return 0;
+ }
+
+ if (is_directory(path, dir) && temp[strlen(filename) - 1] != '/') {
+ ag_asprintf(&temp2, "%s/", temp);
+ int rv = path_ignore_search(ig, path_start, temp2);
+ free(temp2);
+ if (rv) {
+ return 0;
+ }
+ }
+ free(temp);
+ }
+
+ scandir_baton->level++;
if (ig->parent != NULL) {
scandir_baton->ig = ig->parent;
return filename_filter(path, dir, (void *)scandir_baton);
View
@@ -6,6 +6,7 @@
typedef struct {
const ignores *ig;
const char *base_path;
+ int level;
} scandir_baton_t;
typedef int (*filter_fp)(const char *path, const struct dirent *, void *);
View
@@ -271,6 +271,7 @@ void search_dir(ignores *ig, const char *base_path, const char *path, const int
scandir_baton.ig = ig;
scandir_baton.base_path = base_path;
+ scandir_baton.level = 0;
results = ag_scandir(path, &dir_list, &filename_filter, &scandir_baton);
if (results == 0) {
log_debug("No results found in directory %s", path);

0 comments on commit 4148d6a

Please sign in to comment.