dir.c: replace is_path_excluded with now equivalent is_excluded API
authorKarsten Blees <karsten.blees@gmail.com>
Mon, 15 Apr 2013 19:12:57 +0000 (21:12 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2013 19:34:01 +0000 (12:34 -0700)
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
builtin/check-ignore.c
builtin/ls-files.c
dir.c
dir.h
unpack-trees.c
unpack-trees.h
index ab1c9e8fb7a0f7c6f60cc78ff0f345838210459a..06f365d12942f50e75c988ae744ac4fa63406cb8 100644 (file)
@@ -444,9 +444,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        if (pathspec) {
                int i;
-               struct path_exclude_check check;
 
-               path_exclude_check_init(&check, &dir);
                if (!seen)
                        seen = find_pathspecs_matching_against_index(pathspec);
                for (i = 0; pathspec[i]; i++) {
@@ -454,7 +452,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                            && !file_exists(pathspec[i])) {
                                if (ignore_missing) {
                                        int dtype = DT_UNKNOWN;
-                                       if (is_path_excluded(&check, pathspec[i], -1, &dtype))
+                                       if (is_excluded(&dir, pathspec[i], &dtype))
                                                dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
                                } else
                                        die(_("pathspec '%s' did not match any files"),
@@ -462,7 +460,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        }
                }
                free(seen);
-               path_exclude_check_clear(&check);
        }
 
        plug_bulk_checkin();
index 0240f99b57a2f81320b84951bf6dc89ab60d6282..7388346ef2a0beb925d67e4933b3aacb43c3c47e 100644 (file)
@@ -59,7 +59,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
        const char *path, *full_path;
        char *seen;
        int num_ignored = 0, dtype = DT_UNKNOWN, i;
-       struct path_exclude_check check;
        struct exclude *exclude;
 
        /* read_cache() is only necessary so we can watch out for submodules. */
@@ -76,7 +75,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
                return 0;
        }
 
-       path_exclude_check_init(&check, &dir);
        /*
         * look for pathspecs matching entries in the index, since these
         * should not be ignored, in order to be consistent with
@@ -90,8 +88,7 @@ static int check_ignore(const char *prefix, const char **pathspec)
                full_path = check_path_for_gitlink(full_path);
                die_if_path_beyond_symlink(full_path, prefix);
                if (!seen[i]) {
-                       exclude = last_exclude_matching_path(&check, full_path,
-                                                            -1, &dtype);
+                       exclude = last_exclude_matching(&dir, full_path, &dtype);
                        if (exclude) {
                                if (!quiet)
                                        output_exclude(path, exclude);
@@ -101,7 +98,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
        }
        free(seen);
        clear_directory(&dir);
-       path_exclude_check_clear(&check);
 
        return num_ignored;
 }
index 175e6e3e72003387bfa4f78dbd0ed10c02c4e318..22020729cbc35dc5fe11d2a3194fe5994fe67ff9 100644 (file)
@@ -201,19 +201,15 @@ static void show_ru_info(void)
        }
 }
 
-static int ce_excluded(struct path_exclude_check *check, struct cache_entry *ce)
+static int ce_excluded(struct dir_struct *dir, struct cache_entry *ce)
 {
        int dtype = ce_to_dtype(ce);
-       return is_path_excluded(check, ce->name, ce_namelen(ce), &dtype);
+       return is_excluded(dir, ce->name, &dtype);
 }
 
 static void show_files(struct dir_struct *dir)
 {
        int i;
-       struct path_exclude_check check;
-
-       if ((dir->flags & DIR_SHOW_IGNORED))
-               path_exclude_check_init(&check, dir);
 
        /* For cached/deleted files we don't need to even do the readdir */
        if (show_others || show_killed) {
@@ -227,7 +223,7 @@ static void show_files(struct dir_struct *dir)
                for (i = 0; i < active_nr; i++) {
                        struct cache_entry *ce = active_cache[i];
                        if ((dir->flags & DIR_SHOW_IGNORED) &&
-                           !ce_excluded(&check, ce))
+                           !ce_excluded(dir, ce))
                                continue;
                        if (show_unmerged && !ce_stage(ce))
                                continue;
@@ -243,7 +239,7 @@ static void show_files(struct dir_struct *dir)
                        struct stat st;
                        int err;
                        if ((dir->flags & DIR_SHOW_IGNORED) &&
-                           !ce_excluded(&check, ce))
+                           !ce_excluded(dir, ce))
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
@@ -256,9 +252,6 @@ static void show_files(struct dir_struct *dir)
                                show_ce_entry(tag_modified, ce);
                }
        }
-
-       if ((dir->flags & DIR_SHOW_IGNORED))
-               path_exclude_check_clear(&check);
 }
 
 /*
diff --git a/dir.c b/dir.c
index 8ac3d5a973cb3b0d3c322b9d3d9dd319282a47ba..47397600af6dcb1cd26557d5f58a81696a746fc4 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -843,7 +843,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
  * Returns the exclude_list element which matched, or NULL for
  * undecided.
  */
-static struct exclude *last_exclude_matching(struct dir_struct *dir,
+struct exclude *last_exclude_matching(struct dir_struct *dir,
                                             const char *pathname,
                                             int *dtype_p)
 {
@@ -865,7 +865,7 @@ static struct exclude *last_exclude_matching(struct dir_struct *dir,
  * scans all exclude lists to determine whether pathname is excluded.
  * Returns 1 if true, otherwise 0.
  */
-static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
+int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
 {
        struct exclude *exclude =
                last_exclude_matching(dir, pathname, dtype_p);
@@ -874,47 +874,6 @@ static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_
        return 0;
 }
 
-void path_exclude_check_init(struct path_exclude_check *check,
-                            struct dir_struct *dir)
-{
-       check->dir = dir;
-}
-
-void path_exclude_check_clear(struct path_exclude_check *check)
-{
-}
-
-/*
- * For each subdirectory in name, starting with the top-most, checks
- * to see if that subdirectory is excluded, and if so, returns the
- * corresponding exclude structure.  Otherwise, checks whether name
- * itself (which is presumably a file) is excluded.
- *
- * A path to a directory known to be excluded is left in check->path to
- * optimize for repeated checks for files in the same excluded directory.
- */
-struct exclude *last_exclude_matching_path(struct path_exclude_check *check,
-                                          const char *name, int namelen,
-                                          int *dtype)
-{
-       return last_exclude_matching(check->dir, name, dtype);
-}
-
-/*
- * Is this name excluded?  This is for a caller like show_files() that
- * do not honor directory hierarchy and iterate through paths that are
- * possibly in an ignored directory.
- */
-int is_path_excluded(struct path_exclude_check *check,
-                 const char *name, int namelen, int *dtype)
-{
-       struct exclude *exclude =
-               last_exclude_matching_path(check, name, namelen, dtype);
-       if (exclude)
-               return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
-       return 0;
-}
-
 static struct dir_entry *dir_entry_new(const char *pathname, int len)
 {
        struct dir_entry *ent;
@@ -1086,15 +1045,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
 
        /* This is the "show_other_directories" case */
 
-       /* might be a sub directory in an excluded directory */
-       if (!exclude) {
-               struct path_exclude_check check;
-               int dt = DT_DIR;
-               path_exclude_check_init(&check, dir);
-               exclude = is_path_excluded(&check, dirname, len, &dt);
-               path_exclude_check_clear(&check);
-       }
-
        /*
         * We are looking for ignored files and our directory is not ignored,
         * check if it contains untracked files (i.e. is listed as untracked)
@@ -1129,27 +1079,13 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
  *
  * Return 1 for exclude, 0 for include.
  */
-static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude, int *dtype)
+static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude)
 {
-       struct path_exclude_check check;
-       int exclude_file = 0;
-
        /* Always exclude indexed files */
        if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
                return 1;
 
-       if (exclude)
-               exclude_file = !(dir->flags & DIR_SHOW_IGNORED);
-       else if (dir->flags & DIR_SHOW_IGNORED) {
-               path_exclude_check_init(&check, dir);
-
-               if (!is_path_excluded(&check, path->buf, path->len, dtype))
-                       exclude_file = 1;
-
-               path_exclude_check_clear(&check);
-       }
-
-       return exclude_file;
+       return exclude == !(dir->flags & DIR_SHOW_IGNORED);
 }
 
 /*
@@ -1306,12 +1242,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
                break;
        case DT_REG:
        case DT_LNK:
-               switch (treat_file(dir, path, exclude, &dtype)) {
-               case 1:
+               if (treat_file(dir, path, exclude))
                        return path_ignored;
-               default:
-                       break;
-               }
+               break;
        }
        return path_handled;
 }
diff --git a/dir.h b/dir.h
index cd166d0c63ae6ded1035a3dac94bff57e4e05ac1..bfe726e58ec21a97d411c60bf2e7a581fc5e3e3d 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -151,20 +151,10 @@ extern int match_pathname(const char *, int,
                          const char *, int,
                          const char *, int, int, int);
 
-/*
- * The is_excluded() API is meant for callers that check each level of leading
- * directory hierarchies with is_excluded() to avoid recursing into excluded
- * directories.  Callers that do not do so should use this API instead.
- */
-struct path_exclude_check {
-       struct dir_struct *dir;
-};
-extern void path_exclude_check_init(struct path_exclude_check *, struct dir_struct *);
-extern void path_exclude_check_clear(struct path_exclude_check *);
-extern struct exclude *last_exclude_matching_path(struct path_exclude_check *, const char *,
-                                                 int namelen, int *dtype);
-extern int is_path_excluded(struct path_exclude_check *, const char *, int namelen, int *dtype);
+extern struct exclude *last_exclude_matching(struct dir_struct *dir,
+                                            const char *name, int *dtype);
 
+extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
 
 extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
                                             int group_type, const char *src);
index 09e53df3b2a39e7ec8c7d601c5b8b8ae4de39b9a..ede4299b833378ef5a4d44dac181d54889343a27 100644 (file)
@@ -1026,10 +1026,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                        o->el = &el;
        }
 
-       if (o->dir) {
-               o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
-               path_exclude_check_init(o->path_exclude_check, o->dir);
-       }
        memset(&o->result, 0, sizeof(o->result));
        o->result.initialized = 1;
        o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -1155,10 +1151,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 
 done:
        clear_exclude_list(&el);
-       if (o->path_exclude_check) {
-               path_exclude_check_clear(o->path_exclude_check);
-               free(o->path_exclude_check);
-       }
        return ret;
 
 return_failed:
@@ -1375,7 +1367,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
                return 0;
 
        if (o->dir &&
-           is_path_excluded(o->path_exclude_check, name, -1, &dtype))
+           is_excluded(o->dir, name, &dtype))
                /*
                 * ce->name is explicitly excluded, so it is Ok to
                 * overwrite it.
index ec74a9f19a47c39de61def9709da6d4d6f1dcbdb..5e432f576eb2304a63510a61a71182e11f777092 100644 (file)
@@ -52,7 +52,6 @@ struct unpack_trees_options {
        const char *prefix;
        int cache_bottom;
        struct dir_struct *dir;
-       struct path_exclude_check *path_exclude_check;
        struct pathspec *pathspec;
        merge_fn_t fn;
        const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];