summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-01-31 20:23:25 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-05 00:46:49 -0800
commit6831a88ac03759a8133f10ffd52ad235a081a8a3 (patch)
tree1f9dcec12142df59bcaff2200349fbef78ee4100 /dir.c
parentd6b8fc303b389b026f2bf9918f6f83041488989b (diff)
downloadgit-6831a88ac03759a8133f10ffd52ad235a081a8a3.tar.gz
gitignore: lazily find dtype
When we process "foo/" entries in gitignore files on a system that does not have d_type member in "struct dirent", the earlier implementation ran lstat(2) separately when matching with entries that came from the command line, in-tree .gitignore files, and $GIT_DIR/info/excludes file. This optimizes it by delaying the lstat(2) call until it becomes absolutely necessary. The initial idea for this change was by Jeff King, but I optimized it further to pass pointers to around. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index a4f8c258cc..292639b156 100644
--- a/dir.c
+++ b/dir.c
@@ -17,6 +17,7 @@ struct path_simplify {
static int read_directory_recursive(struct dir_struct *dir,
const char *path, const char *base, int baselen,
int check_only, const struct path_simplify *simplify);
+static int get_dtype(struct dirent *de, const char *path);
int common_prefix(const char **pathspec)
{
@@ -277,7 +278,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
* Return 1 for exclude, 0 for include and -1 for undecided.
*/
static int excluded_1(const char *pathname,
- int pathlen, const char *basename, int dtype,
+ int pathlen, const char *basename, int *dtype,
struct exclude_list *el)
{
int i;
@@ -288,9 +289,12 @@ static int excluded_1(const char *pathname,
const char *exclude = x->pattern;
int to_exclude = x->to_exclude;
- if ((x->flags & EXC_FLAG_MUSTBEDIR) &&
- (dtype != DT_DIR))
- continue;
+ if (x->flags & EXC_FLAG_MUSTBEDIR) {
+ if (*dtype == DT_UNKNOWN)
+ *dtype = get_dtype(NULL, pathname);
+ if (*dtype != DT_DIR)
+ continue;
+ }
if (x->flags & EXC_FLAG_NODIR) {
/* match basename */
@@ -334,7 +338,7 @@ static int excluded_1(const char *pathname,
return -1; /* undecided */
}
-int excluded(struct dir_struct *dir, const char *pathname, int dtype)
+int excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
{
int pathlen = strlen(pathname);
int st;
@@ -344,7 +348,7 @@ int excluded(struct dir_struct *dir, const char *pathname, int dtype)
prep_exclude(dir, pathname, basename-pathname);
for (st = EXC_CMDL; st <= EXC_FILE; st++) {
switch (excluded_1(pathname, pathlen, basename,
- dtype, &dir->exclude_list[st])) {
+ dtype_p, &dir->exclude_list[st])) {
case 0:
return 0;
case 1:
@@ -529,7 +533,7 @@ static int in_pathspec(const char *path, int len, const struct path_simplify *si
static int get_dtype(struct dirent *de, const char *path)
{
- int dtype = DTYPE(de);
+ int dtype = de ? DTYPE(de) : DT_UNKNOWN;
struct stat st;
if (dtype != DT_UNKNOWN)
@@ -581,8 +585,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
if (simplify_away(fullname, baselen + len, simplify))
continue;
- dtype = get_dtype(de, fullname);
- exclude = excluded(dir, fullname, dtype);
+ dtype = DTYPE(de);
+ exclude = excluded(dir, fullname, &dtype);
if (exclude && dir->collect_ignored
&& in_pathspec(fullname, baselen + len, simplify))
dir_add_ignored(dir, fullname, baselen + len);
@@ -594,6 +598,9 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
if (exclude && !dir->show_ignored)
continue;
+ if (dtype == DT_UNKNOWN)
+ dtype = get_dtype(de, fullname);
+
/*
* Do we want to see just the ignored files?
* We still need to recurse into directories,