Merge branch 'mg/rebase-i-onto-reflog-in-full'
[gitweb.git] / builtin / ls-files.c
index 468bb13c81b960ac5c9ad5b37cca3ac37b6ef5c0..31b3f2d9006e0f5703ca9fb37bea247012581c0e 100644 (file)
@@ -200,9 +200,19 @@ static void show_ru_info(void)
        }
 }
 
+static int ce_excluded(struct path_exclude_check *check, struct cache_entry *ce)
+{
+       int dtype = ce_to_dtype(ce);
+       return path_excluded(check, ce->name, ce_namelen(ce), &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) {
@@ -215,9 +225,8 @@ static void show_files(struct dir_struct *dir)
        if (show_cached | show_stage) {
                for (i = 0; i < active_nr; i++) {
                        struct cache_entry *ce = active_cache[i];
-                       int dtype = ce_to_dtype(ce);
-                       if (dir->flags & DIR_SHOW_IGNORED &&
-                           !excluded(dir, ce->name, &dtype))
+                       if ((dir->flags & DIR_SHOW_IGNORED) &&
+                           !ce_excluded(&check, ce))
                                continue;
                        if (show_unmerged && !ce_stage(ce))
                                continue;
@@ -232,9 +241,8 @@ static void show_files(struct dir_struct *dir)
                        struct cache_entry *ce = active_cache[i];
                        struct stat st;
                        int err;
-                       int dtype = ce_to_dtype(ce);
-                       if (dir->flags & DIR_SHOW_IGNORED &&
-                           !excluded(dir, ce->name, &dtype))
+                       if ((dir->flags & DIR_SHOW_IGNORED) &&
+                           !ce_excluded(&check, ce))
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
@@ -247,6 +255,9 @@ 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);
 }
 
 /*
@@ -276,41 +287,6 @@ static void prune_cache(const char *prefix)
        active_nr = last;
 }
 
-static const char *pathspec_prefix(const char *prefix)
-{
-       const char **p, *n, *prev;
-       unsigned long max;
-
-       if (!pathspec) {
-               max_prefix_len = prefix ? strlen(prefix) : 0;
-               return prefix;
-       }
-
-       prev = NULL;
-       max = PATH_MAX;
-       for (p = pathspec; (n = *p) != NULL; p++) {
-               int i, len = 0;
-               for (i = 0; i < max; i++) {
-                       char c = n[i];
-                       if (prev && prev[i] != c)
-                               break;
-                       if (!c || c == '*' || c == '?')
-                               break;
-                       if (c == '/')
-                               len = i+1;
-               }
-               prev = n;
-               if (len < max) {
-                       max = len;
-                       if (!max)
-                               break;
-               }
-       }
-
-       max_prefix_len = max;
-       return max ? xmemdupz(prev, max) : NULL;
-}
-
 static void strip_trailing_slash_from_submodules(void)
 {
        const char **p;
@@ -580,7 +556,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                strip_trailing_slash_from_submodules();
 
        /* Find common prefix for all pathspec's */
-       max_prefix = pathspec_prefix(prefix);
+       max_prefix = common_prefix(pathspec);
+       max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
 
        /* Treat unmatching pathspec elements as errors */
        if (pathspec && error_unmatch) {