X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=dir.c;h=225fdfb52c432b7af1af1cdf9aa9a31f8022e3ec;hb=694a577519a762d12b8a53e76b6f1dd3ccf25e7d;hp=5bcc764c97dca5e584d0a4227bfb299efb5699ce;hpb=fe61935007b6803ce116e233316e4ff51de02be6;p=git.git diff --git a/dir.c b/dir.c index 5bcc764c9..225fdfb52 100644 --- a/dir.c +++ b/dir.c @@ -298,7 +298,8 @@ int excluded(struct dir_struct *dir, const char *pathname) return 0; } -static struct dir_entry *dir_entry_new(const char *pathname, int len) { +static struct dir_entry *dir_entry_new(const char *pathname, int len) +{ struct dir_entry *ent; ent = xmalloc(sizeof(*ent) + len + 1); @@ -653,6 +654,7 @@ static void free_simplify(struct path_simplify *simplify) int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec) { struct path_simplify *simplify = create_simplify(pathspec); + char *pp = NULL; /* * Make sure to do the per-directory exclude for all the @@ -660,7 +662,8 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i */ if (baselen) { if (dir->exclude_per_dir) { - char *p, *pp = xmalloc(baselen+1); + char *p; + pp = xmalloc(baselen+1); memcpy(pp, base, baselen+1); p = pp; while (1) { @@ -676,12 +679,12 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i else p = pp + baselen; } - free(pp); } } read_directory_recursive(dir, path, base, baselen, 0, simplify); free_simplify(simplify); + free(pp); qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name); qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name); return dir->nr; @@ -777,3 +780,15 @@ int remove_dir_recursively(struct strbuf *path, int only_empty) ret = rmdir(path->buf); return ret; } + +void setup_standard_excludes(struct dir_struct *dir) +{ + const char *path; + + dir->exclude_per_dir = ".gitignore"; + path = git_path("info/exclude"); + if (!access(path, R_OK)) + add_excludes_from_file(dir, path); + if (excludes_file && !access(excludes_file, R_OK)) + add_excludes_from_file(dir, excludes_file); +}